diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py
index 14a732a..15cac47 100755
--- a/input/management/commands/sendmails.py
+++ b/input/management/commands/sendmails.py
@@ -1,5 +1,6 @@
from datetime import date, timedelta
+from django.core.management import CommandError
from django.core.management.base import BaseCommand
from django.template.loader import get_template
from django.core.mail import BadHeaderError
@@ -50,8 +51,8 @@ class Command(BaseCommand):
# [email],
# bcc=[SURVEY_EMAIL])
#survey_mail.send(fail_silently=False)
- except BadHeaderError:
- return HttpResponse('Invalid header found.') # FIXME HttpResponse???
+ except BadHeaderError as error:
+ raise CommandError(f'Invalid header found: {error}')
print(f'send surveylinkemail to {email}...')
diff --git a/input/templates/input/index.html b/input/templates/input/index.html
index 308d04c..234da25 100755
--- a/input/templates/input/index.html
+++ b/input/templates/input/index.html
@@ -29,8 +29,8 @@
Für alle Fragen wende dich gern an das Team Communitys und
Engagement.
-
Für interessierte Hacker gibts auch den Sourcecode zum Formular und was damit passiert.
+
Für interessierte Hacker gibts auch den
+ Sourcecode zum Formular und was damit passiert.
Impressum
diff --git a/input/tests/views.py b/input/tests/views.py
index 4cbd3a5..f32eeea 100644
--- a/input/tests/views.py
+++ b/input/tests/views.py
@@ -1,7 +1,9 @@
+from django.shortcuts import resolve_url
from django.test import TestCase
from input.models import Library
from input.utils.testing import create_superuser, login, request
+from input.views import TYPES
class AnonymousViewTestCase(TestCase):
@@ -14,33 +16,36 @@ class AnonymousViewTestCase(TestCase):
def test_extern(self):
request(self, 'extern')
- @staticmethod
- def get_step_data(step, data):
- return {'extern_view-current_step': step, **data}
-
@classmethod
- def get_first_step_data(cls, choice):
- return cls.get_step_data(0, {
- '0-realname': 'Test',
- '0-email': 'test@example.com',
- '0-choice': choice,
- '0-check': True,
- })
+ def get_step_data(cls, choice, **data):
+ return {
+ 'realname': 'Test',
+ 'email': 'test@example.com',
+ 'choice': choice,
+ 'check': True,
+ **data,
+ }
+
+ @staticmethod
+ def helper_url(code):
+ info = next(info for info in TYPES if info.code == code)
+
+ return resolve_url('extern', type=info.path)
def helper_extern(self, choice, text, data):
- first_step_data = self.get_first_step_data(choice)
+ url = self.helper_url(choice)
- response = request(self, 'extern', data=first_step_data)
+ response = request(self, url)
self.assertContains(response, text)
- second_step_data = self.get_step_data(1, data)
+ data = self.get_step_data(choice, **data)
- response = request(self, 'extern', data=second_step_data)
+ response = request(self, url, data=data)
self.assertContains(response, 'Deine Anfrage wurde gesendet.')
- def test_extern_first_steps(self):
+ def test_extern_steps(self):
types = [
('BIB', 'Bibliotheksausweis'),
('ELIT', 'Online-Ressource'),
@@ -53,12 +58,10 @@ class AnonymousViewTestCase(TestCase):
('VIS', 'DIN 5008'),
]
- for choice, text in types:
- with self.subTest(type=choice):
- self.client.session.clear()
-
- data = self.get_first_step_data(choice)
- response = request(self, 'extern', data=data)
+ for code, text in types:
+ with self.subTest(type=code):
+ url = self.helper_url(code)
+ response = request(self, url)
self.assertContains(response, text)
@@ -93,6 +96,10 @@ class AnonymousViewTestCase(TestCase):
'notes': '',
})
+ def test_extern_invalid_code(self):
+ request(self, 'extern', args=['invalid'], status_code=404)
+
+
class AuthenticatedViewTestCase(TestCase):
@@ -159,4 +166,4 @@ class TermsConsentViewTests(AnonymousViewTestCase):
# Expect to remain on step 2 with required field error
self.assertNotContains(resp, 'Deine Anfrage wurde gesendet.')
- self.assertContains(resp, 'Dieses Feld ist zwingend erforderlich.')
\ No newline at end of file
+ self.assertContains(resp, 'Dieses Feld ist zwingend erforderlich.')
diff --git a/input/views.py b/input/views.py
index f76cdb6..0a8750b 100755
--- a/input/views.py
+++ b/input/views.py
@@ -73,10 +73,6 @@ class ApplicationType(NamedTuple):
def label(self):
return TYPE_CHOICES[self.code]
- @property
- def model(self):
- return MODELS[self.code]
-
@property
def help_texts(self):
return HELP_TEXTS.get(self.code)