KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to use RequestFactory to test a DetailView with the following test case: def test_device_homepage(self): request = self.factory.get('/devices/1/', {'pk': 1}) response = DeviceView.as_view()(request) self.assertEqual(response.status_code, 404) When I run the above test, however, I get the following error message: AttributeError: Generic detail view DeviceView must be called with either an object pk or a slug. If I print the request after creation, I can see the following: <WSGIRequest path:/devices/1/, GET:<QueryDict: {u'pk': [u'1']}>, As far as I can tell, that should be all that the DetailView requires to be able to progress past the point in code that's generating the above error message. For completeness the full traceback is below: Traceback (most recent call last): File "/vagrant/devices/tests/test_views.py", line 17, in test_device_homepage response = DeviceView.as_view()(request) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 86, in dispatch return handler(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py", line 108, in get self.object = self.get_object() File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py", line 48, in get_object % self.__class__.__name__)
Tags (comma-separated)
Save Edits
Cancel