From 6da3a2edce4d02dfb64548e09286bfe9fe69a139 Mon Sep 17 00:00:00 2001 From: Nicholas Serra Date: Sun, 27 Mar 2016 12:41:41 -0400 Subject: [PATCH] More test coverage. --- runtests.py | 4 +++- tos/tests/test_models.py | 20 ++++++++++++++++---- tos/tests/test_views.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/runtests.py b/runtests.py index 9f2b8be..f4f8726 100755 --- a/runtests.py +++ b/runtests.py @@ -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' ) diff --git a/tos/tests/test_models.py b/tos/tests/test_models.py index 42d3fc1..f978376 100644 --- a/tos/tests/test_models.py +++ b/tos/tests/test_models.py @@ -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) diff --git a/tos/tests/test_views.py b/tos/tests/test_views.py index 7418867..a341346 100644 --- a/tos/tests/test_views.py +++ b/tos/tests/test_views.py @@ -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))