From 8c8fe373dfd01593af87bdc08ea4e39278605e93 Mon Sep 17 00:00:00 2001 From: Christian Adell Date: Mon, 20 Mar 2023 14:31:15 +0100 Subject: [PATCH 1/4] Fix e2e test while combining data from multiple maintenaces wia single parsed data --- tests/unit/data/date/email_date_1_result.json | 6 ++---- tests/unit/test_e2e.py | 17 ++++++++++++----- tests/unit/test_parsers.py | 5 ++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/unit/data/date/email_date_1_result.json b/tests/unit/data/date/email_date_1_result.json index 6cc5fab1..3538ae20 100644 --- a/tests/unit/data/date/email_date_1_result.json +++ b/tests/unit/data/date/email_date_1_result.json @@ -1,5 +1,3 @@ -[ - { +{ "stamp": 1612172014 - } -] +} diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index bb1e5993..3a5e5067 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -463,12 +463,11 @@ Lumen, [ ("html", Path(dir_path, "data", "lumen", "lumen8.html")), - # (EMAIL_HEADER_DATE, Path(dir_path, "data", "date", "email_date_1")), + (EMAIL_HEADER_DATE, Path(dir_path, "data", "date", "email_date_1")), (EMAIL_HEADER_SUBJECT, Path(dir_path, "data", "lumen", "subject_work_planned")), ], [ Path(dir_path, "data", "lumen", "lumen8_result.json"), - # Path(dir_path, "data", "date", "email_date_1_result.json"), ], ), # Megaport @@ -823,7 +822,7 @@ ) def test_provider_get_maintenances( provider_class, test_data_files, result_parse_files -): # pylint: disable=too-many-locals +): # pylint: disable=too-many-locals,too-many-branches """End to End tests for various Providers.""" extended_data = provider_class.get_extended_data() default_maintenance_data = {"uid": "0", "sequence": 1, "summary": ""} @@ -849,10 +848,18 @@ def test_provider_get_maintenances( for result_parse_file in result_parse_files: with open(result_parse_file, encoding="utf-8") as res_file: partial_result_data = json.load(res_file) - if not expected_result: + + # TODO: Tests assume that maintenances (multiple) will be discovered on the first parser + if not expected_result and isinstance(partial_result_data, list): expected_result = partial_result_data + + if expected_result and isinstance(partial_result_data, dict): + for _ in range(len(expected_result)): + expected_result[0].update(partial_result_data) else: - expected_result[0].update(partial_result_data[0]) + assert len(expected_result) == len(expected_result) + for i, _ in enumerate(partial_result_data): + expected_result[i].update(partial_result_data[i]) for result in expected_result: temp_res = result.copy() diff --git a/tests/unit/test_parsers.py b/tests/unit/test_parsers.py index f0963aaf..b2a2a900 100644 --- a/tests/unit/test_parsers.py +++ b/tests/unit/test_parsers.py @@ -549,7 +549,10 @@ def test_parsers(parser_class, raw_file, results_file): with open(results_file, encoding="utf-8") as res_file: expected_result = json.load(res_file) - assert parsed_notifications == expected_result + if parser_class == EmailDateParser: + assert parsed_notifications == [expected_result] + else: + assert parsed_notifications == expected_result @pytest.mark.parametrize("parser_class", [ICal, EmailDateParser, HtmlParserZayo1, SubjectParserZayo1]) From 5ce626c71850894413d5ba114b6676435488a7a8 Mon Sep 17 00:00:00 2001 From: Christian Adell Date: Mon, 20 Mar 2023 14:39:43 +0100 Subject: [PATCH 2/4] Add Verizon Parser 4 tests in e2e --- tests/unit/test_e2e.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index 3a5e5067..eea067ef 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -725,6 +725,17 @@ Path(dir_path, "data", "date", "email_date_1_result.json"), ], ), + ( + Verizon, + [ + ("html", Path(dir_path, "data", "verizon", "verizon4.html")), + (EMAIL_HEADER_DATE, Path(dir_path, "data", "date", "email_date_1")), + ], + [ + Path(dir_path, "data", "verizon", "verizon4_result.json"), + Path(dir_path, "data", "date", "email_date_1_result.json"), + ], + ), ( Verizon, [ From fbc4474da2a1703040b95b903068792ae484b9c3 Mon Sep 17 00:00:00 2001 From: Christian Adell Date: Mon, 20 Mar 2023 14:44:31 +0100 Subject: [PATCH 3/4] skip pylint too-many-lines --- tests/unit/test_e2e.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index eea067ef..b3ed99ee 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -9,7 +9,7 @@ from circuit_maintenance_parser.errors import ProviderError from circuit_maintenance_parser.constants import EMAIL_HEADER_DATE, EMAIL_HEADER_SUBJECT -# pylint: disable=duplicate-code +# pylint: disable=duplicate-code,too-many-lines from circuit_maintenance_parser.provider import ( Equinix, GenericProvider, From fda6541af232cb8d9dc7ba3179ef5d74d7c3a8ec Mon Sep 17 00:00:00 2001 From: Christian Adell Date: Mon, 20 Mar 2023 18:52:34 +0100 Subject: [PATCH 4/4] Fix assert --- tests/unit/test_e2e.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index b3ed99ee..ab8eb39e 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -868,7 +868,7 @@ def test_provider_get_maintenances( for _ in range(len(expected_result)): expected_result[0].update(partial_result_data) else: - assert len(expected_result) == len(expected_result) + assert len(expected_result) == len(partial_result_data) for i, _ in enumerate(partial_result_data): expected_result[i].update(partial_result_data[i])