Skip to content

Instantly share code, notes, and snippets.

@mekhami
Last active February 27, 2016 18:56
Show Gist options
  • Save mekhami/89553d8a3d7c022efe57 to your computer and use it in GitHub Desktop.
Save mekhami/89553d8a3d7c022efe57 to your computer and use it in GitHub Desktop.
class ProjectViewsTest(TestCase):
def setUp(self):
self.project = Project.objects.create(name='google')
self.request = RequestFactory().get('/fake-path/')
def test_project_display_context_data(self):
view = ProjectDisplay()
view = setup_view(view, self.request, slug=self.project.slug)
self.assertIn('form', view.get_context_data())
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