More test coverage.

This commit is contained in:
Nicholas Serra 2016-03-27 12:41:41 -04:00
parent e74abbd2a6
commit 6da3a2edce
3 changed files with 47 additions and 5 deletions

View file

@ -21,6 +21,7 @@ if not settings.configured:
'django.contrib.messages',
'django.contrib.sites',
'tos',
'tos.tests'
],
MIDDLEWARE_CLASSES=[
'django.middleware.common.CommonMiddleware',
@ -30,7 +31,8 @@ if not settings.configured:
'django.contrib.messages.middleware.MessageMiddleware',
],
ROOT_URLCONF='tos.tests.test_urls',
LOGIN_URL='/login/'
LOGIN_URL='/login/',
SITE_ID='1'
)

View file

@ -3,6 +3,7 @@ from django.test import TestCase
from tos.compat import get_runtime_user_model
from tos.models import (
NoActiveTermsOfService,
TermsOfService,
UserAgreement,
has_user_agreed_latest_tos,
@ -48,10 +49,6 @@ class TestModels(TestCase):
# latest is active though
self.assertTrue(latest.active)
def test_terms_of_service_manager(self):
self.assertEquals(TermsOfService.objects.get_current_tos(), self.tos1)
def test_validation_error_all_set_false(self):
"""
If you try and set all to false the model will throw a ValidationError
@ -92,3 +89,18 @@ class TestModels(TestCase):
self.assertTrue(has_user_agreed_latest_tos(self.user1))
self.assertFalse(has_user_agreed_latest_tos(self.user2))
self.assertTrue(has_user_agreed_latest_tos(self.user3))
class TestManager(TestCase):
def test_terms_of_service_manager(self):
tos1 = TermsOfService.objects.create(
content="first edition of the terms of service",
active=True
)
self.assertEquals(TermsOfService.objects.get_current_tos(), tos1)
def test_terms_of_service_manager_raises_error(self):
self.assertRaises(NoActiveTermsOfService, TermsOfService.objects.get_current_tos)

View file

@ -48,6 +48,34 @@ class TestViews(TestCase):
self.assertFalse(has_user_agreed_latest_tos(self.user2))
def test_do_not_need_agreement(self):
""" user2 tries to login and has already agreed"""
self.assertTrue(has_user_agreed_latest_tos(self.user1))
response = self.client.post(self.login_url, dict(username='user1',
password='user1pass'))
self.assertEqual(302, response.status_code)
def test_redirect_security(self):
""" redirect to outside url not allowed, should redirect to login url"""
response = self.client.post(self.login_url, dict(username='user1',
password='user1pass', next='http://example.com'))
self.assertEqual(302, response.status_code)
self.assertIn(settings.LOGIN_REDIRECT_URL, str(response))
def test_need_to_log_in(self):
""" GET to login url shows login tempalte."""
response = self.client.get(self.login_url)
self.assertContains(response, "Dummy login template.")
def test_root_tos_view(self):
response = self.client.get('/tos/')
self.assertIn('first edition of the terms of service', response.content)
def test_reject_agreement(self):
self.assertFalse(has_user_agreed_latest_tos(self.user2))