fixed tests

This commit is contained in:
Oliver Zander 2025-10-14 16:48:39 +02:00
parent a7d3df7b39
commit ce4aeb0721
4 changed files with 35 additions and 31 deletions

View File

@ -1,5 +1,6 @@
from datetime import date, timedelta from datetime import date, timedelta
from django.core.management import CommandError
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.template.loader import get_template from django.template.loader import get_template
from django.core.mail import BadHeaderError from django.core.mail import BadHeaderError
@ -50,8 +51,8 @@ class Command(BaseCommand):
# [email], # [email],
# bcc=[SURVEY_EMAIL]) # bcc=[SURVEY_EMAIL])
#survey_mail.send(fail_silently=False) #survey_mail.send(fail_silently=False)
except BadHeaderError: except BadHeaderError as error:
return HttpResponse('Invalid header found.') # FIXME HttpResponse??? raise CommandError(f'Invalid header found: {error}')
print(f'send surveylinkemail to {email}...') print(f'send surveylinkemail to {email}...')

View File

@ -29,8 +29,8 @@
<br>Für alle Fragen wende dich gern an das <a <br>Für alle Fragen wende dich gern an das <a
href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Wikimedia_Deutschland">Team Communitys und href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Wikimedia_Deutschland">Team Communitys und
Engagement</a>. Engagement</a>.
<br>Für interessierte Hacker gibts auch den <a <br>Für interessierte Hacker gibts auch den
href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a> zum Formular und was damit passiert. <a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a> zum Formular und was damit passiert.
<p> <p>
<a href="https://www.wikimedia.de/impressum/">Impressum</a> <a href="https://www.wikimedia.de/impressum/">Impressum</a>
</p> </p>

View File

@ -1,7 +1,9 @@
from django.shortcuts import resolve_url
from django.test import TestCase from django.test import TestCase
from input.models import Library from input.models import Library
from input.utils.testing import create_superuser, login, request from input.utils.testing import create_superuser, login, request
from input.views import TYPES
class AnonymousViewTestCase(TestCase): class AnonymousViewTestCase(TestCase):
@ -14,33 +16,36 @@ class AnonymousViewTestCase(TestCase):
def test_extern(self): def test_extern(self):
request(self, 'extern') request(self, 'extern')
@staticmethod
def get_step_data(step, data):
return {'extern_view-current_step': step, **data}
@classmethod @classmethod
def get_first_step_data(cls, choice): def get_step_data(cls, choice, **data):
return cls.get_step_data(0, { return {
'0-realname': 'Test', 'realname': 'Test',
'0-email': 'test@example.com', 'email': 'test@example.com',
'0-choice': choice, 'choice': choice,
'0-check': True, '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): 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) 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.') self.assertContains(response, 'Deine Anfrage wurde gesendet.')
def test_extern_first_steps(self): def test_extern_steps(self):
types = [ types = [
('BIB', 'Bibliotheksausweis'), ('BIB', 'Bibliotheksausweis'),
('ELIT', 'Online-Ressource'), ('ELIT', 'Online-Ressource'),
@ -53,12 +58,10 @@ class AnonymousViewTestCase(TestCase):
('VIS', 'DIN 5008'), ('VIS', 'DIN 5008'),
] ]
for choice, text in types: for code, text in types:
with self.subTest(type=choice): with self.subTest(type=code):
self.client.session.clear() url = self.helper_url(code)
response = request(self, url)
data = self.get_first_step_data(choice)
response = request(self, 'extern', data=data)
self.assertContains(response, text) self.assertContains(response, text)
@ -93,6 +96,10 @@ class AnonymousViewTestCase(TestCase):
'notes': '', 'notes': '',
}) })
def test_extern_invalid_code(self):
request(self, 'extern', args=['invalid'], status_code=404)
class AuthenticatedViewTestCase(TestCase): class AuthenticatedViewTestCase(TestCase):
@ -159,4 +166,4 @@ class TermsConsentViewTests(AnonymousViewTestCase):
# Expect to remain on step 2 with required field error # Expect to remain on step 2 with required field error
self.assertNotContains(resp, 'Deine Anfrage wurde gesendet.') self.assertNotContains(resp, 'Deine Anfrage wurde gesendet.')
self.assertContains(resp, 'Dieses Feld ist zwingend erforderlich.') self.assertContains(resp, 'Dieses Feld ist zwingend erforderlich.')

View File

@ -73,10 +73,6 @@ class ApplicationType(NamedTuple):
def label(self): def label(self):
return TYPE_CHOICES[self.code] return TYPE_CHOICES[self.code]
@property
def model(self):
return MODELS[self.code]
@property @property
def help_texts(self): def help_texts(self):
return HELP_TEXTS.get(self.code) return HELP_TEXTS.get(self.code)