Skip to content

Commit

Permalink
DBC22-1831: improved backend unit test coverage to 95%
Browse files Browse the repository at this point in the history
DBC22-1831: improved backend unit test coverage to 95%
  • Loading branch information
bcgov-brwang authored and ray-oxd committed Mar 8, 2024
1 parent 9825585 commit 454e40e
Show file tree
Hide file tree
Showing 24 changed files with 3,651 additions and 53 deletions.
6 changes: 5 additions & 1 deletion src/backend/apps/cms/tests/test_advisory_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from apps.cms.serializers import AdvisorySerializer, AdvisoryTestSerializer
from apps.shared.tests import BaseTest
from django.contrib.gis.geos import Polygon

from django.utils.html import format_html
from django.templatetags.static import static

class TestAdvisorySerializer(BaseTest):
def setUp(self):
Expand All @@ -21,6 +22,7 @@ def setUp(self):
path="000100010001",
depth=3,
)
self.advisory.rendered_body()
self.advisory.save()
self.serializer = AdvisorySerializer(self.advisory)

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



def test_serializer_invalid_data(self):
# Create a serializer with invalid data
invalid_data = {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/apps/cms/tests/test_bulletin_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setUp(self):
image=img_obj,
image_alt_text='Some Image Alt text',
)

self.bulletin.rendered_body()
self.bulletin.save()
self.serializer = BulletinTestSerializer(self.bulletin)

Expand Down
4 changes: 4 additions & 0 deletions src/backend/apps/cms/tests/test_ferry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def setUp(self):
),
live=True,
)

ferry_2.rendered_description()
ferry_2.rendered_seasonal_description()
ferry_2.rendered_service_hours()
ferry_2.save()

def test_ferry_list_caching(self):
Expand Down
25 changes: 25 additions & 0 deletions src/backend/apps/cms/tests/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.test import TestCase
from django.templatetags.static import static
from django.utils.html import format_html
from wagtail import hooks

class WagtailHookTest(TestCase):

def test_insert_global_admin_css(self):
# Call the hook function to get the HTML content
hook_name = 'insert_global_admin_css'
callbacks = hooks.get_hooks(hook_name)

# Verify that there is at least one callback registered
self.assertGreater(len(callbacks), 0)

# Call each callback and verify the HTML content
for callback in callbacks:
result = callback()

expected_css_link = format_html(
'<link rel="stylesheet" type="text/css" href="{}">',
static("wagtail_admin.css"),
)
self.assertIn(result, expected_css_link)

9 changes: 4 additions & 5 deletions src/backend/apps/event/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ class Meta:
)

def to_representation(self, instance):
representation = super().to_representation(instance)
representation = super().to_representation(instance)
schedule = instance.schedule.get('intervals', [])
if schedule and isinstance(schedule, list):
start, end = schedule[0].split('/')
representation['start'] = start
representation['end'] = end
start, end = schedule[0].split('/')
representation['start'] = start
representation['end'] = end
return representation

def get_direction_display(self, obj):
Expand Down
45 changes: 45 additions & 0 deletions src/backend/apps/event/tests/test_data/event_feed_list_of_one.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"events": [
{
"id": "drivebc.ca/DBC-3175",
"display_category": "minorEvents",
"direction_display": "Not Applicable",
"route_display": "Pritchard Rd",
"schedule": {
"intervals": [
"2023-09-20T18:13/"
]
},
"severity": "MINOR",
"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)",
"event_type": "INCIDENT",
"event_sub_type": "HAZARD",
"status": "ACTIVE",
"closed": false,
"direction": "NONE",
"location": {
"type": "Point",
"coordinates": [
-115.583567,
49.50658
]
},
"route_at": "Highway 3",
"route_from": "Pritchard Rd",
"route_to": "",
"first_created": "2018-11-14T09:06:41-08:00",
"last_updated": "2023-09-20T11:13:56-07:00",
"start": "2023-09-20T18:13",
"end": "2023-10-20T18:13",
"priority": 7
}
],
"pagination": {
"offset": "0"
},
"meta": {
"url": "/events",
"up_url": "",
"version": "v1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"events": [
{
"id": "drivebc.ca/DBC-20066",
"display_category": "roadConditions",
"direction_display": "Not Applicable",
"route_display": "Exit 109: Yale Rd to Exit 120: Young Rd",
"schedule": {
"intervals": [
"2024-01-30T01:00/2025-01-30T01:00"
]
},
"severity": "MAJOR",
"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)",
"event_type": "ROAD_CONDITION",
"event_sub_type": "PARTLY_ICY",
"status": "ACTIVE",
"closed": false,
"direction": "NONE",
"location": {
"type": "LineString",
"coordinates": [
[
-122.063019,
49.137886
],
[
-122.060004,
49.138325
],
[
-122.05868,
49.138518
],
[
-122.039974,
49.140932
],
[
-122.02876,
49.142377
],
[
-122.027027,
49.142632
],
[
-122.025373,
49.142998
],
[
-122.022035,
49.143963
],
[
-122.020949,
49.144189
],
[
-122.020039,
49.144322
],
[
-122.0189,
49.144415
],
[
-122.01753,
49.144438
],
[
-122.0117,
49.144303
],
[
-122.006977,
49.144219
],
[
-122.006907,
49.144219
],
[
-122.003081,
49.144157
],
[
-121.999997,
49.144107
],
[
-121.999873,
49.144105
],
[
-121.99975,
49.144103
],
[
-121.999572,
49.1441
],
[
-121.999088,
49.144092
],
[
-121.983239,
49.143787
],
[
-121.977708,
49.143681
],
[
-121.977602,
49.14368
],
[
-121.969274,
49.14352
],
[
-121.967859,
49.143585
],
[
-121.967236,
49.143653
],
[
-121.965676,
49.143902
],
[
-121.964755,
49.144076
],
[
-121.964486,
49.144142
],
[
-121.962445,
49.144643
],
[
-121.962149,
49.144716
],
[
-121.961942,
49.144767
],
[
-121.961366,
49.144906
],
[
-121.961083,
49.144974
]
]
},
"route_at": "Highway 1",
"route_from": "Exit 109: Yale Rd",
"route_to": "Exit 120: Young Rd",
"first_created": "2024-01-29T16:55:13-08:00",
"last_updated": "2024-01-30T08:31:32-08:00",
"start": "2024-01-30T01:00",
"end": "2025-01-30T01:00"
}
],
"pagination": {
"offset": "0"
},
"meta": {
"url": "/events",
"up_url": "",
"version": "v1"
}
}
Loading

0 comments on commit 454e40e

Please sign in to comment.