Skip to content

Instantly share code, notes, and snippets.

@sesh
Forked from mekhami/tests.py
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save sesh/2d02474fe40b2633126b to your computer and use it in GitHub Desktop.

Select an option

Save sesh/2d02474fe40b2633126b to your computer and use it in GitHub Desktop.
class ProjectViewsTest(TestCase):
def setUp(self):
self.project = Project.objects.create(name='google')
self.client = Client()
def test_project_display_context_data(self):
response = self.client.get('/project/{}/'.format(self.project.slug))
self.assertIn('form', response.context)
Creating test database for alias 'default'...
.E............
======================================================================
ERROR: test_project_display_context_data (buffet.tests.ProjectViewsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ldvp/work/buffet/buffet/tests.py", line 118, in test_project_display_context_data
self.assertIn('form', view.get_context_data())
File "/home/ldvp/work/buffet/buffet/views.py", line 29, in get_context_data
context = super(ProjectDisplay, self).get_context_data(**kwargs)
File "/home/ldvp/virt/buffet/local/lib/python2.7/site-packages/django/views/generic/detail.py", line 101, in get_context_data
if self.object:
AttributeError: 'ProjectDisplay' object has no attribute 'object'
----------------------------------------------------------------------
Ran 14 tests in 0.544s
FAILED (errors=1)
class ProjectDisplay(LoginRequiredMixin, DetailView):
model = Project
context_object_name = 'project'
def get_context_data(self, **kwargs):
context = super(ProjectDisplay, self).get_context_data(**kwargs)
context['form'] = ServiceTypeForm()
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment