django-hilbert icon indicating copy to clipboard operation
django-hilbert copied to clipboard

url_name for ViewTestMixin confusion

Open kmtracey opened this issue 13 years ago • 4 comments

This doc: http://django-hilbert.readthedocs.org/en/v0.4.1/test.html#viewtestmixin

leads me to believe I need to specify 'url_name' for my test class. But when I do that I get:

AttributeError: 'HomePageTest' object has no attribute 'url'

If I change my url_name to url, the test case runs. I'm not sure whether the code or doc is off. Using 0.4.1 level.

kmtracey avatar Aug 15 '12 21:08 kmtracey

self.url is constructed in the ViewTestMixin.__init__. There might be a problem related to depending on where the mixin is used in the base classes and whether or not super is called. This could problem could probably be removed by making it a property instead.

mlavin avatar Aug 15 '12 22:08 mlavin

Actually it seems to be done in setUp. And whether setUp is called differs depending on whether my class is declared:

class DashboardTestCase(TestCase, ViewTestMixin):
    url_name = 'sepc_home'

vs:

class DashboardTestCase(ViewTestMixin, TestCase):
    url_name = 'sepc_home'

The latter works, the former does not. Possibly due to: https://code.djangoproject.com/ticket/15828

kmtracey avatar Aug 21 '12 19:08 kmtracey

Yes I just saw I wrote __init__ rather than setUp.

mlavin avatar Aug 21 '12 19:08 mlavin

Started some work on this in the feature/refactor-view-mixin.

mlavin avatar Aug 26 '12 18:08 mlavin