Skip to content

Commit

Permalink
DBC22-1884: unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-oxd committed Apr 3, 2024
1 parent d29a297 commit f5111e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
33 changes: 13 additions & 20 deletions src/backend/apps/rest/tests/test_rest_stop_populate.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import json
from pathlib import Path
from unittest import skip
from unittest.mock import patch
from apps.shared.tests import BaseTest, MockResponse

from apps.feed.client import FeedClient
from apps.rest.models import RestStop
from apps.rest.tasks import (
populate_all_rest_stop_data,
populate_rest_stop_from_data,
)
from apps.rest.tasks import populate_rest_stop_from_data
from apps.rest.tests.test_data.rest_stop_parsed_feed import json_feed
from unittest import mock
from django.contrib.gis.db import models
from apps.shared.tests import BaseTest, MockResponse

from apps.feed.client import FeedClient

class TestRestStopModel(BaseTest):
def setUp(self):
Expand All @@ -35,21 +30,20 @@ def setUp(self):
def test_populate_rest_stop_function(self):
populate_rest_stop_from_data(self.json_feed)
rest_stop_one = RestStop.objects.get(rest_stop_id="DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d9")
assert rest_stop_one.location.x == -126.99686259
assert rest_stop_one.location.y == 54.66828166


assert rest_stop_one.location.y == -126.99686259
assert rest_stop_one.location.x == 54.66828166

def test_populate_rest_stop_function_with_existing_data(self):
RestStop.objects.create(
rest_stop_id="DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e42d1d997_1823",
geometry = {
geometry={
"type": "Point",
"coordinates": [
52.98061363,
-119.31978552
]
},
properties = {
properties={
"WI_FI": "Yes",
"OBJECTID": 10,
"OPEN_DATE": None,
Expand Down Expand Up @@ -85,18 +79,18 @@ def test_populate_rest_stop_function_with_existing_data(self):
"NUMBER_OF_STANDARD_BARRELS": 0,
"NUMBER_OF_BEAR_PROOF_BARRELS": 6
},
bbox = [
bbox=[
-119.31978552,
52.98061363,
-119.31978552,
52.98061363
]

)
populate_rest_stop_from_data(self.json_feed)
rest_stop_one = RestStop.objects.get(rest_stop_id="DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e42d1d997_1823")
assert rest_stop_one.location.x == -119.31978552
assert rest_stop_one.location.y == 52.98061363
assert rest_stop_one.location.y == -119.31978552
assert rest_stop_one.location.x == 52.98061363

@patch('apps.feed.client.FeedClient.get_rest_stop_list')
def test_populate_and_update_rest_stop(self, mock_requests_get):
Expand All @@ -112,4 +106,3 @@ def test_populate_and_update_rest_stop(self, mock_requests_get):
populate_rest_stop_from_data(rest_stop_data)
rest_stop_list_length = len(response)
assert rest_stop_list_length == 2

28 changes: 14 additions & 14 deletions src/backend/apps/rest/tests/test_rest_stop_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from apps.shared.tests import BaseTest
from apps.rest.models import RestStop
from apps.rest.serializers import RestStopSerializer
from apps.shared.tests import BaseTest


class TestRestStopSerializer(BaseTest):
Expand All @@ -9,14 +9,14 @@ def setUp(self):

self.rest_stop = RestStop(
rest_stop_id="DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d9",
geometry = {
geometry={
"type": "Point",
"coordinates": [
54.66828166,
-126.99686259
]
]
},
properties = {
properties={
"WI_FI": "No",
"OBJECTID": 4381,
"OPEN_DATE": None,
Expand Down Expand Up @@ -52,7 +52,7 @@ def setUp(self):
"NUMBER_OF_STANDARD_BARRELS": 0,
"NUMBER_OF_BEAR_PROOF_BARRELS": 6
},
bbox = [
bbox=[
-126.99686259,
54.66828166,
-126.99686259,
Expand All @@ -62,14 +62,14 @@ def setUp(self):

self.rest_stop_2 = RestStop(
rest_stop_id="DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d8",
geometry = {
geometry={
"type": "Point",
"coordinates": [
54.84919263,
-127.22078727
]
},
properties = {
properties={
"WI_FI": "Yes",
"OBJECTID": 30,
"OPEN_DATE": None,
Expand Down Expand Up @@ -105,15 +105,15 @@ def setUp(self):
"NUMBER_OF_STANDARD_BARRELS": 0,
"NUMBER_OF_BEAR_PROOF_BARRELS": 4
},
bbox = [
bbox=[
-127.22078727,
54.84919263,
-127.22078727,
54.84919263

]


)

self.rest_stop.rest_stop_id = "DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d7"
Expand All @@ -129,10 +129,10 @@ def test_serializer_data(self):
assert len(self.serializer.data) == 7
assert self.serializer.data['rest_stop_id'] == \
"DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d7"
assert self.serializer.data['location']['coordinates'][0] == -126.99686259
assert self.serializer.data['location']['coordinates'][1] == 54.66828166
assert self.serializer.data['location']['coordinates'][1] == -126.99686259
assert self.serializer.data['location']['coordinates'][0] == 54.66828166

assert self.serializer_two.data['rest_stop_id'] == \
"DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d6"
assert self.serializer_two.data['location']['coordinates'][0] == -127.22078727
assert self.serializer_two.data['location']['coordinates'][1] == 54.84919263
assert self.serializer_two.data['location']['coordinates'][1] == -127.22078727
assert self.serializer_two.data['location']['coordinates'][0] == 54.84919263

0 comments on commit f5111e1

Please sign in to comment.