Skip to content

Commit

Permalink
[WIP] add test for tcms.testplans.views.NewTestPlanView. Fix kiwitcms…
Browse files Browse the repository at this point in the history
  • Loading branch information
awalvie committed Nov 12, 2020
1 parent dbf5b2e commit 3c34b85
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tcms/testplans/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,119 @@
ProductFactory, VersionFactory, PlanTypeFactory)


class NewPlanViewTest(LoggedInTestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()

user_should_have_perm(cls.tester, perm='testplans.add_testplan')
user_should_have_perm(cls.tester, perm='testplans.view_testplan')

cls.product = ProductFactory()
cls.product_version = VersionFactory(product=cls.product)
cls.test_plan_type = PlanTypeFactory()
cls.test_plan_1 = TestPlanFactory()

cls.testplan_new_url = reverse('plans-new')

cls.testplan_new_data = {
'author': cls.tester.pk,
'product': cls.product.pk,
'product_version': cls.product_version.pk,
'type': cls.test_plan_type.pk,
'name': cls.test_plan_1.name,

'email_settings-0-auto_to_plan_author': 'on',
'email_settings-0-auto_to_case_owner': 'on',
'email_settings-0-auto_to_case_default_tester': 'on',
'email_settings-0-notify_on_case_update': 'on',
'email_settings-0-notify_on_plan_update': 'on',

'email_settings-0-id': cls.test_plan_1.emailing.pk,
'email_settings-TOTAL_FORMS': '1',
'email_settings-INITIAL_FORMS': '1',
'email_settings-MIN_NUM_FORMS': '0',
'email_settings-MAX_NUM_FORMS': '1',
'is_active': True,
}

def test_show_testplan_new_page(self):
response = self.client.get(self.testplan_new_url)
self.assertContains(response, _('Create new TestPlan'))
self.assert_notify_form(response)
self.assertContains(
response,
'<input class="bootstrap-switch" name="is_active" type="checkbox" checked',
html=False)

def test_with_invalid_product_shows_error(self):
new_data = self.testplan_new_data.copy()
new_data['product'] = -1
del new_data['email_settings-0-auto_to_plan_author']

response = self.client.post(self.testplan_new_url, data=new_data, follow=True)

self.assertContains(response, _('Create new TestPlan'))
self.assertContains(
response,
_('Select a valid choice. That choice is not one of the available choices.'))
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-auto_to_plan_author" '
'type="checkbox"', html=False)

def test_with_invalid_type_shows_error(self):
new_data = self.testplan_new_data.copy()
new_data['type'] = -1
del new_data['email_settings-0-auto_to_case_owner']

response = self.client.post(self.testplan_new_url, data=new_data, follow=True)

self.assertContains(response, _('Create new TestPlan'))
self.assertContains(
response,
_('Select a valid choice. That choice is not one of the available choices.'))
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-auto_to_case_owner" '
'type="checkbox"', html=False)

def test_with_invalid_version_shows_error(self):
new_data = self.testplan_new_data.copy()
# Note: version not assigned to the current Product, that's why
# it is invalid !
version = VersionFactory()
new_data['product_version'] = version.pk

response = self.client.post(self.testplan_new_url, data=new_data, follow=True)

self.assertContains(
response,
_('Select a valid choice. That choice is not one of the available choices.'))

def assert_notify_form(self, response):
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-auto_to_plan_author" '
'type="checkbox" checked', html=False)
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-auto_to_case_owner" '
'type="checkbox" checked', html=False)
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-auto_to_case_default_tester" '
'type="checkbox" checked', html=False)
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-notify_on_case_update" '
'type="checkbox" checked', html=False)
self.assertContains(
response,
'<input class="bootstrap-switch" name="email_settings-0-notify_on_plan_update" '
'type="checkbox" checked', html=False)


class EditPlanViewTest(LoggedInTestCase):
@classmethod
def setUpTestData(cls):
Expand Down

0 comments on commit 3c34b85

Please sign in to comment.