chol
/
eva
forked from tohe/eva
1
0
Fork 0
eva/evapp/tests.py

126 lines
5.1 KiB
Python
Raw Normal View History

2020-12-23 10:42:57 +00:00
from django.test import TestCase
2021-09-13 13:32:16 +00:00
from django.test import Client
from django.contrib.auth.models import User
from django.conf import settings
2021-09-20 10:15:13 +00:00
from django.http import HttpResponse
2021-09-20 11:40:26 +00:00
from django.core import mail
2022-01-19 12:36:19 +00:00
from django.utils import translation
2021-09-14 09:58:22 +00:00
from .forms import ITForm, WorkingForm, OfficeForm, DummyForm
2021-09-13 13:32:16 +00:00
2021-09-14 05:17:36 +00:00
class LoginTestCase(TestCase):
def setUp(self):
self.client = Client()
self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe')
self.client.login(username='vladimir', password='reiherzehe')
self.response = self.client.get('/')
2021-09-14 05:17:36 +00:00
def testLogin(self):
self.assertContains(self.response, 'Du bist eingeloggt als vladimir@reiherzehe.com', status_code=200)
2022-01-25 10:21:57 +00:00
response_en = self.client.get('/', HTTP_ACCEPT_LANGUAGE='en-us')
self.assertContains(response_en, 'You are logged in as vladimir@reiherzehe.com', status_code=200)
self.assertContains(response_en, 'Firstname', status_code=200)
response_en = self.client.get('/', HTTP_ACCEPT_LANGUAGE='en')
2022-01-25 10:21:57 +00:00
self.assertContains(response_en, 'You are logged in as vladimir@reiherzehe.com', status_code=200)
2022-01-26 14:54:27 +00:00
self.assertContains(response_en, 'Firstname', status_code=200)
def testDebugWarning(self):
with self.settings(DEBUG=True):
2021-09-16 12:26:02 +00:00
self.response = self.client.get('/') # we need to do it again with DEBUG = True
self.assertContains(self.response, "WARNUNG! Test-MODUS aktiviert. Es werden keine Mails verschickt!", status_code=200)
2021-09-20 08:28:53 +00:00
with self.settings(DEBUG=False) and self.settings(MAILTEST=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)
2021-09-20 09:31:00 +00:00
def _postform(self, data, expected_form):
'''helper function to manage the Wizzard'''
2021-09-20 09:31:00 +00:00
response = self.client.post('/', data, follow=True)
2021-09-20 10:15:13 +00:00
# print(type(response))
self.assertEqual(200, self.response.status_code)
if not type(response) == HttpResponse:
if 'form' in response.context:
self.assertFalse(response.context['form'].errors)
else:
raise "NO FORM FOUND"
self.assertEqual(
type(response.context['wizard']['form']),
expected_form
)
2021-09-20 09:31:00 +00:00
return response
def test_department(self):
self.assertContains(self.response, 'Programme', status_code=200)
self.assertContains(self.response, 'Kommunikation und Events', status_code=200)
2021-11-17 15:12:06 +00:00
def test_wizzard_in(self):
''' this test goes through the whole onboarding process of the EvaFormView from start to end '''
2021-09-16 12:26:02 +00:00
self.assertEqual(200, self.response.status_code)
2021-09-20 09:31:00 +00:00
response = self._postform({
2021-09-16 12:26:02 +00:00
'eva_form_view-current_step': '0',
'0-firstname': 'Ara',
'0-lastname': 'Seva',
'0-department': 'CENT',
2021-11-17 15:12:06 +00:00
'0-choice': 'IN'
2021-09-20 09:31:00 +00:00
}, WorkingForm)
2021-09-16 12:26:02 +00:00
2021-09-20 09:31:00 +00:00
response = self._postform({
2021-09-16 12:26:02 +00:00
'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
2021-09-20 09:31:00 +00:00
}, ITForm)
2021-09-16 12:26:02 +00:00
2021-09-20 09:31:00 +00:00
response = self._postform({
2021-09-16 12:26:02 +00:00
'eva_form_view-current_step': '2',
'2-vendor': 'STANDARD',
'2-os': 'UBU',
'2-keyboard': 'DE',
'2-language': 'GER'
2021-09-20 09:31:00 +00:00
}, OfficeForm)
2021-09-16 12:26:02 +00:00
2021-09-20 10:15:13 +00:00
response = self._postform({
'eva_form_view-current_step': '3',
'3-transponder': 'NORM'
}, DummyForm)
2021-09-20 11:40:26 +00:00
response = self._postform({
2021-09-20 10:15:13 +00:00
'eva_form_view-current_step': '5',
}, DummyForm)
2021-11-17 15:12:06 +00:00
2021-09-20 11:40:26 +00:00
def test_mail(self):
2021-11-17 15:12:06 +00:00
self.test_wizzard_in()
2021-11-17 15:29:27 +00:00
# print(mail.outbox[0].body)
2021-09-20 11:40:26 +00:00
self.assertGreater(len(mail.outbox), 2)
2021-11-17 15:29:27 +00:00
self.assertIn("Vorname", mail.outbox[0].body)
for i in (0,1,3):
self.assertIn("Handy", mail.outbox[i].body)
2021-09-20 11:40:26 +00:00
self.assertIn("Ara Seva", mail.outbox[0].subject)
2021-09-16 12:26:02 +00:00
2021-09-14 07:58:41 +00:00
class NoLoginTestCase(TestCase):
2021-09-13 13:32:16 +00:00
def setUp(self):
self.client = Client()
def test_details(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 302)
response2 = self.client.get(response.url)
self.assertContains( response2, 'Bitte via Wolke einloggen:', status_code=200)
2021-09-14 09:58:22 +00:00
class ITFORMTestCase(TestCase):
def test_mac(self):
form = ITForm(data={"vendor": 'MAC', 'os': 'UBU'})
#print (form.errors)
self.assertEqual(form.non_field_errors(), ['Ein MAC sollte Mac OS installiert haben'])
def test_ubu(self):
form = ITForm(data={"vendor": 'STANDARD', 'os': 'UBU'})
#print (form.errors)
self.assertNotEqual(form.non_field_errors(), ['Ein MAC sollte Mac OS installiert haben'])