File tree Expand file tree Collapse file tree 4 files changed +34
-8
lines changed
Expand file tree Collapse file tree 4 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 11[metadata]
22name = django-sys-indicator
3- version = 0.3 .0
3+ version = 0.4 .0
44url = https://github.com/marksweb/django-sys-indicator
55description = A system/environment indicator for django
66long_description = file: README.md
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def SYSTEM_INDICATOR_LABEL(self) -> str: # noqa: N802
3030 return getattr (dj_settings , "SYSTEM_INDICATOR_LABEL" , 'localhost' )
3131
3232 @property
33- def SYSTEM_INDICATOR_COLORS (self ) -> str : # noqa: N802
33+ def SYSTEM_INDICATOR_COLORS (self ) -> dict : # noqa: N802
3434 return getattr (dj_settings , "SYSTEM_INDICATOR_COLORS" , DEFAULT_COLOURS )
3535
3636 @property
Original file line number Diff line number Diff line change 66
77
88def django_sys_indicator_tag () -> str :
9- if not settings .SYSTEM_INDICATOR_ENABLED :
10- return ""
11-
129 template_name = 'django_sys_indicator/system_indicator.html'
13- color , border_color = settings .SYSTEM_INDICATOR_COLORS [
14- settings .SYSTEM_INDICATOR_COLOR
15- ]
10+
11+ try :
12+ color , border_color = settings .SYSTEM_INDICATOR_COLORS [
13+ settings .SYSTEM_INDICATOR_COLOR
14+ ]
15+ except KeyError :
16+ # Invalid colour chosen
17+ color , border_color = settings .SYSTEM_INDICATOR_COLORS ['red' ]
1618 return render_to_string (
1719 template_name ,
1820 {
Original file line number Diff line number Diff line change @@ -56,3 +56,27 @@ def test_enabled_orange(self):
5656 assert settings .SYSTEM_INDICATOR_LABEL in content
5757 assert border_color in content
5858 assert color in content
59+
60+ @override_settings (SYSTEM_INDICATOR_ENABLED = True , SYSTEM_INDICATOR_COLOR = 'black' )
61+ def test_invalid_colour (self ):
62+ response = self .middleware (self .request )
63+ content = response .content .decode (response .charset )
64+ # Invalid colour results in red as a default
65+ color , border_color = settings .SYSTEM_INDICATOR_COLORS ['red' ]
66+
67+ assert settings .SYSTEM_INDICATOR_LABEL in content
68+ assert border_color in content
69+ assert color in content
70+
71+ @override_settings (SYSTEM_INDICATOR_ENABLED = True , SYSTEM_INDICATOR_LABEL = 123 )
72+ def test_int_label (self ):
73+ response = self .middleware (self .request )
74+ content = response .content .decode (response .charset )
75+ color , border_color = settings .SYSTEM_INDICATOR_COLORS [
76+ settings .SYSTEM_INDICATOR_COLOR
77+ ]
78+
79+ # cast to string here because of the assert against the string content
80+ assert str (settings .SYSTEM_INDICATOR_LABEL ) in content
81+ assert border_color in content
82+ assert color in content
You can’t perform that action at this time.
0 commit comments