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.

77 lines
3.3 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 datetime import date
  5. from .models import HonoraryCertificate, Project, Account
  6. class TestWithoutLogin(TestCase):
  7. def setUp(self):
  8. #this supress an unwanted warning about missing root dir
  9. settings.WHITENOISE_AUTOREFRESH = True
  10. def test_set_granted(self):
  11. '''test if the model function set_granted() works as intended'''
  12. obj = HonoraryCertificate.objects.create(realname='hurzel',email='hurzel@web.de')
  13. self.assertEqual(obj.granted,None)
  14. HonoraryCertificate.set_granted(obj.pk, True)
  15. obj2 = HonoraryCertificate.objects.get(pk=obj.pk)
  16. self.assertEqual(obj2.granted,True)
  17. def test_source_link(self):
  18. '''test if link to source code is included in main page'''
  19. response = self.client.get('', follow=True)
  20. #print (response.content)
  21. self.assertContains(response,'<a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a>')
  22. def test_access_denied(self):
  23. '''test if /intern redirects to login page if not logged in'''
  24. response = self.client.get('/intern', follow=True)
  25. self.assertContains(response,'password')
  26. class TestWithLogin(TestCase):
  27. def setUp(self):
  28. User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd')
  29. self.client = Client()
  30. self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe')
  31. def test_access(self):
  32. '''test if /intern gives an answer'''
  33. self.assertEqual(self.client.login(username='testuser', password='testpasswd'), True)
  34. response = self.client.get('/intern')
  35. self.assertContains(response,'Übersicht aller Förderangebote')
  36. def test_project_of_year(self):
  37. ''' test if the finance id is resettet ad start of year'''
  38. acc = Account.objects.create(code='1234', description='blabla')
  39. startdate = date(2022,1,1)
  40. obj = Project.objects.create(account= acc, name='testproject', start=startdate)
  41. self.assertEqual(obj.project_of_year,1)
  42. obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  43. self.assertEqual(obj2.project_of_year,2)
  44. olddate = date(2021,12,31)
  45. obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
  46. obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  47. self.assertEqual(obj3.project_of_year,3)
  48. def test_finance_id(self):
  49. ''' test if the finance id is resettet ad start of year'''
  50. acc = Account.objects.create(code='1234', description='blabla')
  51. startdate = date(2022,1,1)
  52. obj = Project.objects.create(account= acc, name='testproject', start=startdate)
  53. self.assertEqual(obj.finance_id,"1234001")
  54. obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  55. self.assertEqual(obj2.finance_id,"1234002")
  56. olddate = date(2021,12,31)
  57. obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
  58. obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  59. self.assertEqual(obj3.finance_id,"1234003")