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.

42 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. from django.test import TestCase
  2. from django.conf import settings
  3. from django.contrib.auth.models import User
  4. from .models import HonoraryCertificate
  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. # fixture = ['testfixture']
  27. def setUp(self):
  28. User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd')
  29. def test_access(self):
  30. '''test if /intern gives an answer'''
  31. self.assertEqual(self.client.login(username='testuser', password='testpasswd'), True)
  32. response = self.client.get('/intern')
  33. self.assertContains(response,'Übersicht aller Förderangebote')