Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for tcms.bugs.views.Search -- Closes #1601 #1914

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tcms/bugs/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ 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']

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
23 changes: 23 additions & 0 deletions tcms/bugs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tcms.core.templatetags.extra_filters import markdown2html # noqa: E402
from tcms.bugs.models import Bug # noqa: E402
from tcms.bugs.tests.factory import BugFactory # noqa: E402
from tcms.management.models import Product # noqa: E402
from tcms.tests import ( # noqa: E402
BaseCaseRun,
LoggedInTestCase,
Expand Down Expand Up @@ -247,3 +248,25 @@ 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')

ProductFactory()
VersionFactory()
BuildFactory()

def test_initial_form_field_states(self):
product_count = Product.objects.count()

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

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