diff --git a/tests/unit/test_unit_metobs.py b/tests/unit/test_unit_metobs.py index 101e49fa..0012dda1 100644 --- a/tests/unit/test_unit_metobs.py +++ b/tests/unit/test_unit_metobs.py @@ -353,19 +353,27 @@ def test_unit_baselevel_get_and_parse_request( assert content == mock_json_loads.return_value @pytest.mark.parametrize( - "data, key, parameters, data_type, expected_result", + "data, key, parameters, data_type, expected_url, expected_summary", [ ( - [{"key": "p1", "link": [{"href": "URL", "type": "application/json"}]}], + [ + { + "key": "p1", + "summary": "sum", + "link": [{"href": "URL", "type": "application/json"}], + } + ], "key", "p1", "application/json", "URL", + "sum", ), ( [ { "title": "p2", + "summary": "sum", "link": [{"href": "URL", "type": "application/json"}], } ], @@ -373,15 +381,44 @@ def test_unit_baselevel_get_and_parse_request( "p2", "application/json", "URL", + "sum", + ), + ( + [{"key": "p1", "link": []}], + "key", + "p1", + None, + IndexError, + None, + ), + ( + [{"link": []}], + "key", + "p1", + None, + KeyError, + None, + ), + ( + [{"link": []}], + "key", + None, + None, + KeyError, + None, + ), + ( + [{"link": []}], + None, + None, + None, + KeyError, + None, ), - ([{"key": "p1", "link": []}], "key", "p1", None, IndexError), - ([{"link": []}], "key", "p1", None, KeyError), - ([{"link": []}], "key", None, None, KeyError), - ([{"link": []}], None, None, None, KeyError), ], ) def test_unit_baselevel_get_url( - self, data, key, parameters, data_type, expected_result + self, data, key, parameters, data_type, expected_url, expected_summary ): """Unit test for BaseLevel _get_url method. @@ -390,19 +427,21 @@ def test_unit_baselevel_get_url( key: key parameters: parameters data_type: format of api data - expected_result: expected result + expected_url: expected result + expected_summary: expected summary """ level = BaseLevel() - if type(expected_result) != str: # noqa: E721 - with pytest.raises(expected_result): + if type(expected_url) != str: # noqa: E721 + with pytest.raises(expected_url): level._get_url(data, key, parameters, data_type) return None - url = level._get_url(data, key, parameters, data_type) + url, summary = level._get_url(data, key, parameters, data_type) assert level.data_type == data_type - assert url == expected_result + assert url == expected_url + assert summary == expected_summary class TestUnitVersions: @@ -456,7 +495,7 @@ class TestUnitParameter: @patch("smhi.metobs.tuple") @patch("smhi.metobs.sorted") @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Versions") def test_unit_parameters_init( self, @@ -522,7 +561,7 @@ class TestUnitStation: @patch("smhi.metobs.tuple") @patch("smhi.metobs.sorted") @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) def test_unit_stations_init( self, mock_get_url, @@ -602,7 +641,7 @@ class TestUnitPeriod: ) @patch("smhi.metobs.sorted") @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) def test_unit_periods_init( self, mock_get_url, @@ -688,7 +727,7 @@ class TestUnitData: ], ) @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Data._get_data") def test_unit_data_init( self, @@ -764,7 +803,7 @@ def test_unit_data_init( ) @patch("smhi.metobs.requests.get") @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Data._parse_header") @patch("smhi.metobs.Data._parse_data") def test_unit_data_get_data( @@ -812,7 +851,7 @@ def test_unit_data_get_data( ], ) @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Data._get_data") def test_unit_data_separate_header_data( self, @@ -844,7 +883,7 @@ def test_unit_data_separate_header_data( [(METOBS_DATA, METOBS_UNIT_1)], ) @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Data._get_data") def test_unit_data_parse_header( self, @@ -878,7 +917,7 @@ def test_unit_data_parse_header( ], ) @patch("smhi.metobs.BaseLevel._get_and_parse_request") - @patch("smhi.metobs.BaseLevel._get_url") + @patch("smhi.metobs.BaseLevel._get_url", return_value=(1, 2)) @patch("smhi.metobs.Data._get_data") def test_unit_data_parse_data( self, @@ -898,6 +937,7 @@ def test_unit_data_parse_data( result: expected result """ data_object = Data(MagicMock(), "corrected-archive", "json") + data_object.parameter_summary = "momentanvÀrde, 1 gÄng/tim" if result is None: with pytest.raises(TypeError):