From 5cda8400cc8f655c2bca49e8d326e54b48f206b0 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 20 Sep 2021 11:31:00 +0200 Subject: [PATCH] refactoring of formtools test code --- TODO | 2 ++ evapp/tests.py | 42 +++++++++++++++++++----------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index 4725632..1c1ef69 100644 --- a/TODO +++ b/TODO @@ -2,4 +2,6 @@ * test for complete run with all forms +* test for mail sending + * firstname lastname in subject diff --git a/evapp/tests.py b/evapp/tests.py index 6c3f411..5b3d049 100644 --- a/evapp/tests.py +++ b/evapp/tests.py @@ -3,7 +3,7 @@ from django.test import Client from django.contrib.auth.models import User from django.conf import settings -from .forms import ITForm, WorkingForm +from .forms import ITForm, WorkingForm, OfficeForm class LoginTestCase(TestCase): def setUp(self): @@ -23,50 +23,46 @@ class LoginTestCase(TestCase): self.response = self.client.get('/') # we need to do it again with DEBUG = False self.assertNotContains(self.response, "WARNUNG! Test-MODUS aktiviert. Es werden keine Mails verschickt!", status_code=200) + def _postform(self, data, expected_form): + response = self.client.post('/', data, follow=True) + if 'form' in response.context: + self.assertFalse(response.context['form'].errors) + else: + raise "NO FORM FOUND" + return response + self.assertEqual( + type(response.context['wizard']['form']), + expected_form + ) + def testWizzard(self): ''' this test goes thru the whole process of the EvaFormView from start to end ''' self.assertEqual(200, self.response.status_code) - response = self.client.post('/', { + response = self._postform({ 'eva_form_view-current_step': '0', '0-firstname': 'Ara', '0-lastname': 'Seva', '0-department': 'CENT', - }) - #print(response.context) + }, WorkingForm) - self.assertFalse(response.context['form'].is_bound) - print(response.context['wizard']['steps']) - self.assertEqual( - type(response.context['wizard']['form']), - WorkingForm - ) - - response = self.client.post('/', { + response = self._postform({ 'eva_form_view-current_step': '1', '1-firstdate_employment': '2021-01-01', '1-firstdate_presence': '2021-01-01', '1-jobdescription_german': 'hau drauf', '1-jobdescription_english': 'und schluss', '1-works_in_gs': False - }, follow=True) - if 'form' in response.context: - self.assertFalse(response.context['form'].errors) - else: - raise "NO FORM FOUND" + }, ITForm) - response = self.client.post('/', { + response = self._postform({ 'eva_form_view-current_step': '2', '2-vendor': 'STANDARD', '2-os': 'UBU', '2-keyboard': 'DE', '2-language': 'GER' - }, follow=True) - if 'form' in response.context: - self.assertFalse(response.context['form'].errors) - else: - raise "NO FORM FOUND" + }, OfficeForm) class NoLoginTestCase(TestCase):