samedi 31 janvier 2015

How to unit test view_func in urls?

I am using mock package to help out with writing unit tests. (even though I am not mocking in this particular example, but I could if it helps achieving my goal)


I have the following routing rule defined and would like to test it.



app.add_url_rule('/api/v1.0/worker/bbc-stage-0', 'stage0', view_func=BBCStage0TaskView.as_view('bbc_stage0_taskview'))


The following test allows to see if the path is correct:



def test_url_to_view_stage0_exists(self):
self.assertEqual(api.app.url_map._rules_by_endpoint['stage0'][0].rule, '/api/v1.0/worker/bbc-stage-0')


But I haven't found a way to test if view_func is pointing to the right class. Is there a way to achieve this?


Aucun commentaire:

Enregistrer un commentaire