refactoring of formtools test code

This commit is contained in:
Benni Bärmann 2021-09-20 11:31:00 +02:00
parent 032245ae3b
commit 5cda8400cc
2 changed files with 21 additions and 23 deletions

2
TODO
View File

@ -2,4 +2,6 @@
* test for complete run with all forms * test for complete run with all forms
* test for mail sending
* firstname lastname in subject * firstname lastname in subject

View File

@ -3,7 +3,7 @@ from django.test import Client
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from .forms import ITForm, WorkingForm from .forms import ITForm, WorkingForm, OfficeForm
class LoginTestCase(TestCase): class LoginTestCase(TestCase):
def setUp(self): 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.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) 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): def testWizzard(self):
''' this test goes thru the whole process of the EvaFormView from start to end ''' ''' this test goes thru the whole process of the EvaFormView from start to end '''
self.assertEqual(200, self.response.status_code) self.assertEqual(200, self.response.status_code)
response = self.client.post('/', { response = self._postform({
'eva_form_view-current_step': '0', 'eva_form_view-current_step': '0',
'0-firstname': 'Ara', '0-firstname': 'Ara',
'0-lastname': 'Seva', '0-lastname': 'Seva',
'0-department': 'CENT', '0-department': 'CENT',
}) }, WorkingForm)
#print(response.context)
self.assertFalse(response.context['form'].is_bound) response = self._postform({
print(response.context['wizard']['steps'])
self.assertEqual(
type(response.context['wizard']['form']),
WorkingForm
)
response = self.client.post('/', {
'eva_form_view-current_step': '1', 'eva_form_view-current_step': '1',
'1-firstdate_employment': '2021-01-01', '1-firstdate_employment': '2021-01-01',
'1-firstdate_presence': '2021-01-01', '1-firstdate_presence': '2021-01-01',
'1-jobdescription_german': 'hau drauf', '1-jobdescription_german': 'hau drauf',
'1-jobdescription_english': 'und schluss', '1-jobdescription_english': 'und schluss',
'1-works_in_gs': False '1-works_in_gs': False
}, follow=True) }, ITForm)
if 'form' in response.context:
self.assertFalse(response.context['form'].errors)
else:
raise "NO FORM FOUND"
response = self.client.post('/', { response = self._postform({
'eva_form_view-current_step': '2', 'eva_form_view-current_step': '2',
'2-vendor': 'STANDARD', '2-vendor': 'STANDARD',
'2-os': 'UBU', '2-os': 'UBU',
'2-keyboard': 'DE', '2-keyboard': 'DE',
'2-language': 'GER' '2-language': 'GER'
}, follow=True) }, OfficeForm)
if 'form' in response.context:
self.assertFalse(response.context['form'].errors)
else:
raise "NO FORM FOUND"
class NoLoginTestCase(TestCase): class NoLoginTestCase(TestCase):