Coverage for ivatar / test_config_defaults.py: 87%
39 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 00:09 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 00:09 +0000
1"""
2Unit tests for configurable default settings
3"""
5import unittest
6from unittest.mock import patch
7import os
8import django
10os.environ["DJANGO_SETTINGS_MODULE"] = "ivatar.settings"
11django.setup()
13from django.test import TestCase
16class ConfigurableDefaultsTestCase(TestCase):
17 """
18 Test cases for configurable default settings for gravatarproxy, gravatarredirect, and forcedefault
19 """
21 def test_config_imports_successfully(self):
22 """
23 Test that the new configuration options can be imported successfully
24 """
25 try:
26 from ivatar.settings import (
27 DEFAULT_GRAVATARPROXY,
28 DEFAULT_GRAVATARREDIRECT,
29 FORCEDEFAULT,
30 )
32 # Test that they have the expected default values
33 self.assertTrue(isinstance(DEFAULT_GRAVATARPROXY, bool))
34 self.assertTrue(isinstance(DEFAULT_GRAVATARREDIRECT, bool))
35 self.assertTrue(isinstance(FORCEDEFAULT, bool))
36 except ImportError as e:
37 self.fail(f"Failed to import configuration settings: {e}")
39 def test_views_imports_config_successfully(self):
40 """
41 Test that views.py can import the new configuration options
42 """
43 try:
44 from ivatar.views import (
45 DEFAULT_GRAVATARPROXY,
46 DEFAULT_GRAVATARREDIRECT,
47 FORCEDEFAULT,
48 )
50 # Test that they have the expected default values
51 self.assertTrue(isinstance(DEFAULT_GRAVATARPROXY, bool))
52 self.assertTrue(isinstance(DEFAULT_GRAVATARREDIRECT, bool))
53 self.assertTrue(isinstance(FORCEDEFAULT, bool))
54 except ImportError as e:
55 self.fail(f"Failed to import configuration settings in views: {e}")
57 @patch("ivatar.settings.DEFAULT_GRAVATARPROXY", False)
58 @patch("ivatar.settings.DEFAULT_GRAVATARREDIRECT", True)
59 @patch("ivatar.settings.FORCEDEFAULT", True)
60 def test_config_values_can_be_overridden(self):
61 """
62 Test that configuration values can be overridden (mocked for testing)
63 """
64 from ivatar import settings
66 # These should reflect the patched values
67 self.assertFalse(settings.DEFAULT_GRAVATARPROXY)
68 self.assertTrue(settings.DEFAULT_GRAVATARREDIRECT)
69 self.assertTrue(settings.FORCEDEFAULT)
71 def test_default_values_are_correct(self):
72 """
73 Test that the default values match the issue requirements
74 """
75 from ivatar.settings import (
76 DEFAULT_GRAVATARPROXY,
77 DEFAULT_GRAVATARREDIRECT,
78 FORCEDEFAULT,
79 )
81 # Based on the issue, these should be the defaults for public instances
82 self.assertTrue(
83 DEFAULT_GRAVATARPROXY
84 ) # Default should be True for public instances
85 self.assertFalse(DEFAULT_GRAVATARREDIRECT) # Default should be False
86 self.assertFalse(FORCEDEFAULT) # Default should be False
89if __name__ == "__main__":
90 unittest.main()