Skip to content

Commit

Permalink
test: Add tests for tcms.bugs.views.Search -- Closes #1601
Browse files Browse the repository at this point in the history
  • Loading branch information
mfonism committed Sep 14, 2020
1 parent 15ac2f6 commit ec95b0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tcms/bugs/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ def verify_post_with_permission(self):
self.assertEqual(comments.last().comment, 'A comment text')


class TestSearch(tests.PermissionsTestCase):
permission_label = 'bugs.view_bug'
url = reverse('bugs-search')
http_method_names = ['get']
post_data = 1 # attribute is still checked even when POST isn't in http_method_names

def verify_get_with_permission(self):
response = self.client.get(self.url)

self.assertTemplateUsed(response, 'bugs/search.html')


class TestM2MPermissionsExist(TestCase):
def test_permissions_exist(self):
ctype = ContentType.objects.get_for_model(Bug.tags.through)
Expand Down
20 changes: 20 additions & 0 deletions tcms/bugs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,23 @@ def test_add_reopen_bug_comment(self):

self.assertEqual(comments.count(), old_comment_count + 1)
self.assertEqual(comments.last().comment, _('*bug reopened*'))


class TestSearch(LoggedInTestCase):

@classmethod
def setUpTestData(cls):
super().setUpTestData()
user_should_have_perm(cls.tester, 'bugs.view_bug')

def test_initial_form_field_states(self):
ProductFactory()
VersionFactory()
BuildFactory()

response = self.client.get(reverse('bugs-search'))
fields = response.context['form'].fields

self.assertEqual(fields['version'].queryset.count(), 0)
self.assertEqual(fields['build'].queryset.count(), 0)
self.assertNotEqual(fields['product'].queryset.count(), 0)

0 comments on commit ec95b0c

Please sign in to comment.