2021-09-29 13:53:53 +00:00
|
|
|
from django.test import TestCase, Client
|
2020-11-23 13:38:47 +00:00
|
|
|
from django.conf import settings
|
2020-11-24 10:12:04 +00:00
|
|
|
from django.contrib.auth.models import User
|
2020-09-21 12:27:16 +00:00
|
|
|
|
2021-09-29 13:53:53 +00:00
|
|
|
from .models import HonoraryCertificate, Project, Account
|
2020-11-23 13:08:01 +00:00
|
|
|
|
2020-11-24 10:12:04 +00:00
|
|
|
class TestWithoutLogin(TestCase):
|
2020-11-23 13:08:01 +00:00
|
|
|
|
2020-11-23 13:38:47 +00:00
|
|
|
def setUp(self):
|
|
|
|
#this supress an unwanted warning about missing root dir
|
|
|
|
settings.WHITENOISE_AUTOREFRESH = True
|
|
|
|
|
2020-11-23 13:08:01 +00:00
|
|
|
def test_set_granted(self):
|
2020-11-23 16:16:03 +00:00
|
|
|
'''test if the model function set_granted() works as intended'''
|
2020-11-23 13:08:01 +00:00
|
|
|
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)
|
2020-11-23 13:38:47 +00:00
|
|
|
|
|
|
|
def test_source_link(self):
|
2020-11-23 16:16:03 +00:00
|
|
|
'''test if link to source code is included in main page'''
|
2020-11-23 16:05:54 +00:00
|
|
|
response = self.client.get('', follow=True)
|
|
|
|
#print (response.content)
|
2020-11-23 13:38:47 +00:00
|
|
|
self.assertContains(response,'<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a>')
|
2020-11-23 16:05:54 +00:00
|
|
|
|
|
|
|
def test_access_denied(self):
|
2020-11-23 16:16:03 +00:00
|
|
|
'''test if /intern redirects to login page if not logged in'''
|
2020-11-23 16:05:54 +00:00
|
|
|
response = self.client.get('/intern', follow=True)
|
|
|
|
self.assertContains(response,'password')
|
2020-11-24 10:12:04 +00:00
|
|
|
|
2021-09-29 13:53:53 +00:00
|
|
|
|
2020-11-24 10:12:04 +00:00
|
|
|
class TestWithLogin(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd')
|
2021-09-29 13:53:53 +00:00
|
|
|
self.client = Client()
|
|
|
|
self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe')
|
2020-11-24 10:12:04 +00:00
|
|
|
|
|
|
|
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')
|
2021-09-29 13:53:53 +00:00
|
|
|
|
|
|
|
def test_project_pid(self):
|
|
|
|
''' test if the project pid is resettet ad start of year'''
|
|
|
|
# self.client.login(username='vladimir', password='reiherzehe')
|
|
|
|
acc = Account.objects.create(code='1234', description='blabla')
|
|
|
|
#acc.save()
|
|
|
|
obj = Project.objects.create(account= acc, name='testproject', start='2022-01-01')
|
|
|
|
#obj.save()
|
2021-09-30 13:29:50 +00:00
|
|
|
print(f'pid: {obj.pid}')
|
|
|
|
self.assertEqual(obj.pid,'1234000')
|