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 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}...')

View File

@ -29,8 +29,8 @@
<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
Engagement</a>.
<br>Für interessierte Hacker gibts auch den <a
href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a> zum Formular und was damit passiert.
<br>Für interessierte Hacker gibts auch den
<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a> zum Formular und was damit passiert.
<p>
<a href="https://www.wikimedia.de/impressum/">Impressum</a>
</p>

View File

@ -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):

View File

@ -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)