Skip to content

Commit e252d9e

Browse files
committed
DBC22-1831: improved backend unit test coverage to 95%
DBC22-1831: improved backend unit test coverage to 95%
1 parent eb9268a commit e252d9e

24 files changed

+3651
-53
lines changed

src/backend/apps/cms/tests/test_advisory_serializer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from apps.cms.serializers import AdvisorySerializer, AdvisoryTestSerializer
33
from apps.shared.tests import BaseTest
44
from django.contrib.gis.geos import Polygon
5-
5+
from django.utils.html import format_html
6+
from django.templatetags.static import static
67

78
class TestAdvisorySerializer(BaseTest):
89
def setUp(self):
@@ -21,6 +22,7 @@ def setUp(self):
2122
path="000100010001",
2223
depth=3,
2324
)
25+
self.advisory.rendered_body()
2426
self.advisory.save()
2527
self.serializer = AdvisorySerializer(self.advisory)
2628

@@ -32,6 +34,8 @@ def test_serializer_valid_data(self):
3234
'Advisory body 1'
3335
assert self.serializer.data["geometry"] is not None
3436

37+
38+
3539
def test_serializer_invalid_data(self):
3640
# Create a serializer with invalid data
3741
invalid_data = {

src/backend/apps/cms/tests/test_bulletin_serialization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def setUp(self):
3131
image=img_obj,
3232
image_alt_text='Some Image Alt text',
3333
)
34+
35+
self.bulletin.rendered_body()
3436
self.bulletin.save()
3537
self.serializer = BulletinTestSerializer(self.bulletin)
3638

src/backend/apps/cms/tests/test_ferry_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def setUp(self):
3434
),
3535
live=True,
3636
)
37+
38+
ferry_2.rendered_description()
39+
ferry_2.rendered_seasonal_description()
40+
ferry_2.rendered_service_hours()
3741
ferry_2.save()
3842

3943
def test_ferry_list_caching(self):
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.test import TestCase
2+
from django.templatetags.static import static
3+
from django.utils.html import format_html
4+
from wagtail import hooks
5+
6+
class WagtailHookTest(TestCase):
7+
8+
def test_insert_global_admin_css(self):
9+
# Call the hook function to get the HTML content
10+
hook_name = 'insert_global_admin_css'
11+
callbacks = hooks.get_hooks(hook_name)
12+
13+
# Verify that there is at least one callback registered
14+
self.assertGreater(len(callbacks), 0)
15+
16+
# Call each callback and verify the HTML content
17+
for callback in callbacks:
18+
result = callback()
19+
20+
expected_css_link = format_html(
21+
'<link rel="stylesheet" type="text/css" href="{}">',
22+
static("wagtail_admin.css"),
23+
)
24+
self.assertIn(result, expected_css_link)
25+

src/backend/apps/event/serializers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ class Meta:
3131
)
3232

3333
def to_representation(self, instance):
34-
representation = super().to_representation(instance)
34+
representation = super().to_representation(instance)
3535
schedule = instance.schedule.get('intervals', [])
36-
if schedule and isinstance(schedule, list):
37-
start, end = schedule[0].split('/')
38-
representation['start'] = start
39-
representation['end'] = end
36+
start, end = schedule[0].split('/')
37+
representation['start'] = start
38+
representation['end'] = end
4039
return representation
4140

4241
def get_direction_display(self, obj):
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"events": [
3+
{
4+
"id": "drivebc.ca/DBC-3175",
5+
"display_category": "minorEvents",
6+
"direction_display": "Not Applicable",
7+
"route_display": "Pritchard Rd",
8+
"schedule": {
9+
"intervals": [
10+
"2023-09-20T18:13/"
11+
]
12+
},
13+
"severity": "MINOR",
14+
"description": "Highway 3. Collision between Pritchard Rd and Abbey Pit Rd (17 km east of Cranbrook). Last updated Wed Sep 20 at 11:13 AM MDT. (DBC-3175)",
15+
"event_type": "INCIDENT",
16+
"event_sub_type": "HAZARD",
17+
"status": "ACTIVE",
18+
"closed": false,
19+
"direction": "NONE",
20+
"location": {
21+
"type": "Point",
22+
"coordinates": [
23+
-115.583567,
24+
49.50658
25+
]
26+
},
27+
"route_at": "Highway 3",
28+
"route_from": "Pritchard Rd",
29+
"route_to": "",
30+
"first_created": "2018-11-14T09:06:41-08:00",
31+
"last_updated": "2023-09-20T11:13:56-07:00",
32+
"start": "2023-09-20T18:13",
33+
"end": "2023-10-20T18:13",
34+
"priority": 7
35+
}
36+
],
37+
"pagination": {
38+
"offset": "0"
39+
},
40+
"meta": {
41+
"url": "/events",
42+
"up_url": "",
43+
"version": "v1"
44+
}
45+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"events": [
3+
{
4+
"id": "drivebc.ca/DBC-20066",
5+
"display_category": "roadConditions",
6+
"direction_display": "Not Applicable",
7+
"route_display": "Exit 109: Yale Rd to Exit 120: Young Rd",
8+
"schedule": {
9+
"intervals": [
10+
"2024-01-30T01:00/2025-01-30T01:00"
11+
]
12+
},
13+
"severity": "MAJOR",
14+
"description": "Highway 1 (TransCanada Highway). Watch for slippery sections between Exit 109: Yale Rd and Exit 120: Young Rd for 7.7 km (Chilliwack). Until Wed Jan 29, 2025 at 5:00 PM PST. Next update time Wed Jan 29, 2025 at 4:45 PM PST. Last updated Tue Jan 30 at 8:31 AM PST. (DBC-20066)",
15+
"event_type": "ROAD_CONDITION",
16+
"event_sub_type": "PARTLY_ICY",
17+
"status": "ACTIVE",
18+
"closed": false,
19+
"direction": "NONE",
20+
"location": {
21+
"type": "LineString",
22+
"coordinates": [
23+
[
24+
-122.063019,
25+
49.137886
26+
],
27+
[
28+
-122.060004,
29+
49.138325
30+
],
31+
[
32+
-122.05868,
33+
49.138518
34+
],
35+
[
36+
-122.039974,
37+
49.140932
38+
],
39+
[
40+
-122.02876,
41+
49.142377
42+
],
43+
[
44+
-122.027027,
45+
49.142632
46+
],
47+
[
48+
-122.025373,
49+
49.142998
50+
],
51+
[
52+
-122.022035,
53+
49.143963
54+
],
55+
[
56+
-122.020949,
57+
49.144189
58+
],
59+
[
60+
-122.020039,
61+
49.144322
62+
],
63+
[
64+
-122.0189,
65+
49.144415
66+
],
67+
[
68+
-122.01753,
69+
49.144438
70+
],
71+
[
72+
-122.0117,
73+
49.144303
74+
],
75+
[
76+
-122.006977,
77+
49.144219
78+
],
79+
[
80+
-122.006907,
81+
49.144219
82+
],
83+
[
84+
-122.003081,
85+
49.144157
86+
],
87+
[
88+
-121.999997,
89+
49.144107
90+
],
91+
[
92+
-121.999873,
93+
49.144105
94+
],
95+
[
96+
-121.99975,
97+
49.144103
98+
],
99+
[
100+
-121.999572,
101+
49.1441
102+
],
103+
[
104+
-121.999088,
105+
49.144092
106+
],
107+
[
108+
-121.983239,
109+
49.143787
110+
],
111+
[
112+
-121.977708,
113+
49.143681
114+
],
115+
[
116+
-121.977602,
117+
49.14368
118+
],
119+
[
120+
-121.969274,
121+
49.14352
122+
],
123+
[
124+
-121.967859,
125+
49.143585
126+
],
127+
[
128+
-121.967236,
129+
49.143653
130+
],
131+
[
132+
-121.965676,
133+
49.143902
134+
],
135+
[
136+
-121.964755,
137+
49.144076
138+
],
139+
[
140+
-121.964486,
141+
49.144142
142+
],
143+
[
144+
-121.962445,
145+
49.144643
146+
],
147+
[
148+
-121.962149,
149+
49.144716
150+
],
151+
[
152+
-121.961942,
153+
49.144767
154+
],
155+
[
156+
-121.961366,
157+
49.144906
158+
],
159+
[
160+
-121.961083,
161+
49.144974
162+
]
163+
]
164+
},
165+
"route_at": "Highway 1",
166+
"route_from": "Exit 109: Yale Rd",
167+
"route_to": "Exit 120: Young Rd",
168+
"first_created": "2024-01-29T16:55:13-08:00",
169+
"last_updated": "2024-01-30T08:31:32-08:00",
170+
"start": "2024-01-30T01:00",
171+
"end": "2025-01-30T01:00"
172+
}
173+
],
174+
"pagination": {
175+
"offset": "0"
176+
},
177+
"meta": {
178+
"url": "/events",
179+
"up_url": "",
180+
"version": "v1"
181+
}
182+
}

0 commit comments

Comments
 (0)