You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. from django.test import TestCase, Client
  2. from django.conf import settings
  3. from django.contrib.auth.models import User
  4. from .models import HonoraryCertificate, Project, Account
  5. class TestWithoutLogin(TestCase):
  6. def setUp(self):
  7. #this supress an unwanted warning about missing root dir
  8. settings.WHITENOISE_AUTOREFRESH = True
  9. def test_set_granted(self):
  10. '''test if the model function set_granted() works as intended'''
  11. obj = HonoraryCertificate.objects.create(realname='hurzel',email='hurzel@web.de')
  12. self.assertEqual(obj.granted,None)
  13. HonoraryCertificate.set_granted(obj.pk, True)
  14. obj2 = HonoraryCertificate.objects.get(pk=obj.pk)
  15. self.assertEqual(obj2.granted,True)
  16. def test_source_link(self):
  17. '''test if link to source code is included in main page'''
  18. response = self.client.get('', follow=True)
  19. #print (response.content)
  20. self.assertContains(response,'<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a>')
  21. def test_access_denied(self):
  22. '''test if /intern redirects to login page if not logged in'''
  23. response = self.client.get('/intern', follow=True)
  24. self.assertContains(response,'password')
  25. class TestWithLogin(TestCase):
  26. def setUp(self):
  27. User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd')
  28. self.client = Client()
  29. self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe')
  30. def test_access(self):
  31. '''test if /intern gives an answer'''
  32. self.assertEqual(self.client.login(username='testuser', password='testpasswd'), True)
  33. response = self.client.get('/intern')
  34. self.assertContains(response,'Übersicht aller Förderangebote')
  35. def test_project_pid(self):
  36. ''' test if the project pid is resettet ad start of year'''
  37. # self.client.login(username='vladimir', password='reiherzehe')
  38. acc = Account.objects.create(code='1234', description='blabla')
  39. #acc.save()
  40. obj = Project.objects.create(account= acc, name='testproject', start='2022-01-01')
  41. #obj.save()
  42. print(f'pid: {obj.pid}')
  43. self.assertEqual(obj.pid,'1234000')