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.

85 lines
3.6 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. # self.client.login(username='vladimir', password='reiherzehe')
  39. acc = Account.objects.create(code='1234', description='blabla')
  40. #acc.save()
  41. startdate = date(2022,1,1)
  42. obj = Project.objects.create(account= acc, name='testproject', start=startdate)
  43. #obj.save()
  44. print(f'p_of_year: {obj.project_of_year}')
  45. self.assertEqual(obj.project_of_year,1)
  46. obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  47. self.assertEqual(obj2.project_of_year,2)
  48. olddate = date(2021,12,31)
  49. obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
  50. obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  51. self.assertEqual(obj3.project_of_year,3)
  52. def test_finance_id(self):
  53. ''' test if the finance id is resettet ad start of year'''
  54. # self.client.login(username='vladimir', password='reiherzehe')
  55. acc = Account.objects.create(code='1234', description='blabla')
  56. #acc.save()
  57. startdate = date(2022,1,1)
  58. obj = Project.objects.create(account= acc, name='testproject', start=startdate)
  59. #obj.save()
  60. # print(f'p_of_year: {obj.project_of_year}')
  61. self.assertEqual(obj.finance_id,"1234001")
  62. obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  63. self.assertEqual(obj2.finance_id,"1234002")
  64. olddate = date(2021,12,31)
  65. obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
  66. obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
  67. self.assertEqual(obj3.finance_id,"1234003")