Skip to content

Commit

Permalink
Fix test_get_request_params_from_request_values
Browse files Browse the repository at this point in the history
  • Loading branch information
ziv17 committed Jan 15, 2024
1 parent 749937e commit cf971f6
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions tests/test_request_params.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import unittest
from unittest.mock import patch
from datetime import date
from pandas._libs.tslibs.timestamps import Timestamp
from anyway.request_params import (
extract_non_urban_intersection_location,
get_request_params_from_request_values,
get_location_from_news_flash,
fill_missing_non_urban_intersection_values
fill_missing_non_urban_intersection_values,
extract_news_flash_obj,
get_location_from_news_flash_or_request_values,
get_latest_accident_date
)
from anyway.request_params import RequestParams
from anyway.backend_constants import BE_CONST as BE
Expand All @@ -22,22 +27,37 @@ class TestRequestParams(unittest.TestCase):
"non_urban_intersection_hebrew": "צומת השיטה",
"roads": set([669, 71]),
}
expected_1 = {'data': {'non_urban_intersection': 1277,
loc_1 = {'data': {'non_urban_intersection': 1277,
'non_urban_intersection_hebrew': 'צומת השיטה',
'resolution': BE_CONST.ResolutionCategories.SUBURBAN_JUNCTION,
'road1': 669,
'road2': 71},
'gps': {'lat': 32.82561, 'lon': 35.165395},
'name': 'location',
'text': 'צומת השיטה'}
nf = NewsFlash()
nf.description = "description"
nf.title = "title"
rp_1 = RequestParams(
resolution=BE_CONST.ResolutionCategories.SUBURBAN_JUNCTION,
years_ago=5,
location_text="צומת השיטה",
location_info={'non_urban_intersection': 1277, 'non_urban_intersection_hebrew': 'צומת השיטה', 'road1': 669, 'road2': 71},
start_time=date(2014, 1, 1),
end_time=date(2018, 1, 2),
lang='he',
news_flash_description=nf.description,
news_flash_title=nf.title,
gps={"lat": 32.825610, "lon": 35.165395}
)

@patch("anyway.request_params.fill_missing_non_urban_intersection_values")
def test_extract_non_urban_intersection_location(self, fill_missing):
fill_missing.return_value = self.junction_1277
input_params = {"non_urban_intersection": 1277}
res = extract_non_urban_intersection_location(input_params)
# todo: until implementing accidents stats with roads
self.assertEqual(self.expected_1, res, "1") # add assertion here
self.assertEqual(self.loc_1, res, "1") # add assertion here

@patch("anyway.models.SuburbanJunction.get_all_from_key_value")
@patch("anyway.models.SuburbanJunction.get_intersection_from_roads")
Expand All @@ -57,10 +77,20 @@ def test_fill_missing_non_urban_intersection_values(self, from_roads, from_key):
actual = fill_missing_non_urban_intersection_values(input_params)
self.assertEqual(self.junction_1277, actual, "2") # add assertion here

def test_get_request_params_from_request_values(self):
@patch("anyway.request_params.get_latest_accident_date")
@patch("anyway.request_params.extract_news_flash_obj")
@patch("anyway.request_params.get_location_from_news_flash_or_request_values")
def test_get_request_params_from_request_values(self, get_location, extract_nf, get_date):
get_location.return_value = self.loc_1
get_date.return_value = Timestamp("2018-01-02 01:15:16")
extract_nf.return_value = self.nf
input_params = {"road1": 669, "road2": 71}
res = get_request_params_from_request_values(input_params)
self.assertTrue(isinstance(res, RequestParams))
actual = get_request_params_from_request_values(input_params)
self.assertEqual(self.rp_1, actual, "1")

get_location.return_value = {x: None for x in self.loc_1.keys()}
actual = get_request_params_from_request_values(input_params)
self.assertEqual(None, actual, "2")

def test_get_location_from_news_flash(self):
nf = NewsFlash()
Expand Down

0 comments on commit cf971f6

Please sign in to comment.