Coverage for ivatar/test_config_defaults.py: 90%

29 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 11:51 +0000

1""" 

2Unit tests for configurable default settings 

3""" 

4 

5import unittest 

6from unittest.mock import patch 

7import os 

8import django 

9 

10os.environ["DJANGO_SETTINGS_MODULE"] = "ivatar.settings" 

11django.setup() 

12 

13from django.test import TestCase 

14from django.conf import settings 

15 

16 

17class ConfigurableDefaultsTestCase(TestCase): 

18 """ 

19 Test cases for configurable default settings for gravatarproxy, gravatarredirect, and forcedefault 

20 """ 

21 

22 def test_config_imports_successfully(self): 

23 """ 

24 Test that the new configuration options can be imported successfully 

25 """ 

26 try: 

27 # Test that they have the expected default values 

28 self.assertTrue(isinstance(getattr(settings, "DEFAULT_GRAVATARPROXY", True), bool)) 

29 self.assertTrue(isinstance(getattr(settings, "DEFAULT_GRAVATARREDIRECT", False), bool)) 

30 self.assertTrue(isinstance(getattr(settings, "FORCEDEFAULT", False), bool)) 

31 except Exception as e: 

32 self.fail(f"Failed to access configuration settings: {e}") 

33 

34 @patch("django.conf.settings.DEFAULT_GRAVATARPROXY", False, create=True) 

35 @patch("django.conf.settings.DEFAULT_GRAVATARREDIRECT", True, create=True) 

36 @patch("django.conf.settings.FORCEDEFAULT", True, create=True) 

37 def test_config_values_can_be_overridden(self): 

38 """ 

39 Test that configuration values can be overridden (mocked for testing) 

40 """ 

41 # These should reflect the patched values 

42 self.assertFalse(settings.DEFAULT_GRAVATARPROXY) 

43 self.assertTrue(settings.DEFAULT_GRAVATARREDIRECT) 

44 self.assertTrue(settings.FORCEDEFAULT) 

45 

46 def test_default_values_are_correct(self): 

47 """ 

48 Test that the default values match the issue requirements 

49 """ 

50 # Based on the issue, these should be the defaults for public instances 

51 self.assertTrue( 

52 getattr(settings, "DEFAULT_GRAVATARPROXY", True) 

53 ) # Default should be True for public instances 

54 self.assertFalse(getattr(settings, "DEFAULT_GRAVATARREDIRECT", False)) # Default should be False 

55 self.assertFalse(getattr(settings, "FORCEDEFAULT", False)) # Default should be False 

56 

57 

58if __name__ == "__main__": 

59 unittest.main()