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 1
1
[metadata]
2
2
name = django-sys-indicator
3
- version = 0.3 .0
3
+ version = 0.4 .0
4
4
url = https://github.com/marksweb/django-sys-indicator
5
5
description = A system/environment indicator for django
6
6
long_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
30
30
return getattr (dj_settings , "SYSTEM_INDICATOR_LABEL" , 'localhost' )
31
31
32
32
@property
33
- def SYSTEM_INDICATOR_COLORS (self ) -> str : # noqa: N802
33
+ def SYSTEM_INDICATOR_COLORS (self ) -> dict : # noqa: N802
34
34
return getattr (dj_settings , "SYSTEM_INDICATOR_COLORS" , DEFAULT_COLOURS )
35
35
36
36
@property
Original file line number Diff line number Diff line change 6
6
7
7
8
8
def django_sys_indicator_tag () -> str :
9
- if not settings .SYSTEM_INDICATOR_ENABLED :
10
- return ""
11
-
12
9
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' ]
16
18
return render_to_string (
17
19
template_name ,
18
20
{
Original file line number Diff line number Diff line change @@ -56,3 +56,27 @@ def test_enabled_orange(self):
56
56
assert settings .SYSTEM_INDICATOR_LABEL in content
57
57
assert border_color in content
58
58
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