diff --git a/tests/test_request_params.py b/tests/test_request_params.py index 7a0cafd1..174d647b 100644 --- a/tests/test_request_params.py +++ b/tests/test_request_params.py @@ -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 @@ -22,7 +27,7 @@ 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, @@ -30,6 +35,21 @@ class TestRequestParams(unittest.TestCase): '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): @@ -37,7 +57,7 @@ def test_extract_non_urban_intersection_location(self, fill_missing): 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") @@ -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()