forked from beba/foerderbarometer
86 lines
3.6 KiB
Python
86 lines
3.6 KiB
Python
from django.test import TestCase, Client
|
|
from django.conf import settings
|
|
from django.contrib.auth.models import User
|
|
from datetime import date
|
|
|
|
from .models import HonoraryCertificate, Project, Account
|
|
|
|
class TestWithoutLogin(TestCase):
|
|
|
|
def setUp(self):
|
|
#this supress an unwanted warning about missing root dir
|
|
settings.WHITENOISE_AUTOREFRESH = True
|
|
|
|
def test_set_granted(self):
|
|
'''test if the model function set_granted() works as intended'''
|
|
obj = HonoraryCertificate.objects.create(realname='hurzel',email='hurzel@web.de')
|
|
self.assertEqual(obj.granted,None)
|
|
HonoraryCertificate.set_granted(obj.pk, True)
|
|
obj2 = HonoraryCertificate.objects.get(pk=obj.pk)
|
|
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 test_access_denied(self):
|
|
'''test if /intern redirects to login page if not logged in'''
|
|
response = self.client.get('/intern', follow=True)
|
|
self.assertContains(response,'password')
|
|
|
|
|
|
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_access(self):
|
|
'''test if /intern gives an answer'''
|
|
self.assertEqual(self.client.login(username='testuser', password='testpasswd'), True)
|
|
response = self.client.get('/intern')
|
|
self.assertContains(response,'Übersicht aller Förderangebote')
|
|
|
|
def test_project_of_year(self):
|
|
''' test if the finance id is resettet ad start of year'''
|
|
# self.client.login(username='vladimir', password='reiherzehe')
|
|
acc = Account.objects.create(code='1234', description='blabla')
|
|
#acc.save()
|
|
startdate = date(2022,1,1)
|
|
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
|
|
#obj.save()
|
|
print(f'p_of_year: {obj.project_of_year}')
|
|
self.assertEqual(obj.project_of_year,1)
|
|
|
|
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
|
self.assertEqual(obj2.project_of_year,2)
|
|
|
|
olddate = date(2021,12,31)
|
|
obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
|
|
|
|
obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
|
self.assertEqual(obj3.project_of_year,3)
|
|
|
|
def test_finance_id(self):
|
|
''' test if the finance id is resettet ad start of year'''
|
|
# self.client.login(username='vladimir', password='reiherzehe')
|
|
acc = Account.objects.create(code='1234', description='blabla')
|
|
#acc.save()
|
|
startdate = date(2022,1,1)
|
|
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
|
|
#obj.save()
|
|
# print(f'p_of_year: {obj.project_of_year}')
|
|
self.assertEqual(obj.finance_id,"1234001")
|
|
|
|
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
|
self.assertEqual(obj2.finance_id,"1234002")
|
|
|
|
olddate = date(2021,12,31)
|
|
obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
|
|
|
|
obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
|
self.assertEqual(obj3.finance_id,"1234003")
|