clean up tests

This commit is contained in:
Oliver Zander 2025-08-21 10:08:24 +02:00 committed by Tobias Herre
parent 6306567ebd
commit 17f763ba66
2 changed files with 5 additions and 77 deletions

View File

@ -1,22 +1,13 @@
from datetime import date from datetime import date
from django.test import TestCase, Client from django.test import TestCase
from django.conf import settings
from django.contrib.auth.models import User
from django.http import HttpResponse
from input.forms import LibraryForm
from input.models import HonoraryCertificate, Project, Account, Literature from input.models import HonoraryCertificate, Project, Account, Literature
from .views import ViewTestCase from .views import ViewTestCase
class TestWithoutLogin(TestCase): class ModelTestCase(TestCase):
def setUp(self):
#this setting supress an unwanted warning about missing root dir
settings.WHITENOISE_AUTOREFRESH = True
self.client = Client()
def test_set_granted(self): def test_set_granted(self):
'''test if the model function set_granted() works as intended''' '''test if the model function set_granted() works as intended'''
@ -26,71 +17,6 @@ class TestWithoutLogin(TestCase):
obj2 = HonoraryCertificate.objects.get(pk=obj.pk) obj2 = HonoraryCertificate.objects.get(pk=obj.pk)
self.assertEqual(obj2.granted,True) self.assertEqual(obj2.granted,True)
def test_source_link(self):
'''test if link to source code is included in main page'''
response = self.client.get('', follow=True)
#print (response.content)
self.assertContains(response,'<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a>')
def _postform(self, data, expected_form):
'''helper function to manage the Wizzard'''
response = self.client.post('/', data, follow=False)
self.assertEqual(200, self.response.status_code)
if not type(response) == HttpResponse:
if 'form' in response.context:
print('CONTENT')
print(response.content)
print('ITEMS')
print(response.items())
print('DATA')
print(data)
self.assertFalse(response.context['form'].errors)
else:
if expected_form:
print(response.context)
raise BaseException("NO FORM FOUND")
else:
self.assertContains(response,"Deine Anfrage wurde gesendet.")
self.assertEqual(
type(response.context['wizard']['form']),
expected_form
)
return response
def _notest_bib(self): # renamed because not working
'''full run through the forms to check Bibliotheksstipendium'''
self.response = self.client.get('/')
self.assertEqual(200, self.response.status_code)
print("\n\nEINS EINS\n\n")
response = self._postform({
'extern_view-current_step': '0',
'0-realname': 'vladimir reiherzehe',
'0-email': 'vlre@wikimedia.de',
'0-username': 'stoffel',
'0-choice': 'BIB',
'0-check': True
}, LibraryForm)
print("\n\nZWEI ZWEI\n\n")
response = self._postform({
'extern_view-current_step': '1',
'1-cost': 'teuroooo!',
'1-duration': 'looooong',
'1-library': 'of congress',
}, None)
class TestWithLogin(TestCase):
def setUp(self):
User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd')
self.client = Client()
self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe')
def test_project_of_year(self): def test_project_of_year(self):
''' test if the finance id is resettet ad start of year''' ''' test if the finance id is resettet ad start of year'''
acc = Account.objects.create() acc = Account.objects.create()

View File

@ -6,7 +6,9 @@ from input.utils.testing import request
class ViewTestCase(TestCase): class ViewTestCase(TestCase):
def test_index(self): def test_index(self):
request(self, 'index') response = request(self, 'index')
self.assertContains(response,'<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a>')
def test_extern(self): def test_extern(self):
request(self, 'extern') request(self, 'extern')