Skip to content

Commit

Permalink
Add tests for middleware NoActiveTermsOfService warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
blag committed Jun 19, 2024
1 parent 1714046 commit 2d57b69
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tos/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.test import TestCase, override_settings

from tos.models import (
NoActiveTermsOfService,
Expand Down Expand Up @@ -104,3 +104,39 @@ def test_terms_of_service_manager(self):
def test_terms_of_service_manager_raises_error(self):

self.assertRaises(NoActiveTermsOfService, TermsOfService.objects.get_current_tos)


class TestNoActiveTOS(TestCase):
@classmethod
def setUpClass(cls):
# Use bulk_create to avoid calling the model's save() method
TermsOfService.objects.bulk_create([
TermsOfService(
content="The only TOS",
active=False,
)
])

@classmethod
def tearDownClass(cls):
TermsOfService.objects.all().delete()

@override_settings(DEBUG=True)
def test_model_save_raises_warning(self):
with self.assertWarns(Warning):
TermsOfService.objects.first().save()

@override_settings(DEBUG=True)
def test_get_current_tos_raises_warning(self):
with self.assertWarns(Warning):
TermsOfService.objects.get_current_tos()

@override_settings(DEBUG=False)
def test_model_save_raises_exception(self):
with self.assertRaises(NoActiveTermsOfService):
TermsOfService.objects.first().save()

@override_settings(DEBUG=False)
def test_get_current_tos_raises_exception(self):
with self.assertRaises(NoActiveTermsOfService):
TermsOfService.objects.get_current_tos()

0 comments on commit 2d57b69

Please sign in to comment.