From 956c04945fc127287823176df9de46f17f93c2d6 Mon Sep 17 00:00:00 2001 From: Mark Kekez <92973272+aliex-13@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:24:50 +1030 Subject: [PATCH] Add iCal parsing to GTT (for EXA related maintenance) (#273) * Add new EXA parser to separate from GTT * Add iCal parser to GTT and remove EXA * Fix linter issue * Update ical include_filter GTT * Fix linter issues --- circuit_maintenance_parser/provider.py | 5 ++++- tests/unit/data/gtt/gtt8 | 21 +++++++++++++++++++++ tests/unit/data/gtt/gtt8_result.json | 21 +++++++++++++++++++++ tests/unit/data/gtt/gtt9 | 21 +++++++++++++++++++++ tests/unit/data/gtt/gtt9_result.json | 21 +++++++++++++++++++++ tests/unit/test_e2e.py | 18 ++++++++++++++++++ tests/unit/test_parsers.py | 10 ++++++++++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/unit/data/gtt/gtt8 create mode 100644 tests/unit/data/gtt/gtt8_result.json create mode 100644 tests/unit/data/gtt/gtt9 create mode 100644 tests/unit/data/gtt/gtt9_result.json diff --git a/circuit_maintenance_parser/provider.py b/circuit_maintenance_parser/provider.py index df6ef7f2..fc6a59ee 100644 --- a/circuit_maintenance_parser/provider.py +++ b/circuit_maintenance_parser/provider.py @@ -307,10 +307,13 @@ class GTT(GenericProvider): """EXA (formerly GTT) provider custom class.""" # "Planned Work Notification", "Emergency Work Notification" - _include_filter = PrivateAttr({EMAIL_HEADER_SUBJECT: ["Work Notification"]}) + _include_filter = PrivateAttr( + {"Icalendar": ["BEGIN"], "ical": ["BEGIN"], EMAIL_HEADER_SUBJECT: ["Work Notification"]} + ) _processors: List[GenericProcessor] = PrivateAttr( [ + SimpleProcessor(data_parsers=[ICal]), CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserGTT1]), ] ) diff --git a/tests/unit/data/gtt/gtt8 b/tests/unit/data/gtt/gtt8 new file mode 100644 index 00000000..7f35c1f1 --- /dev/null +++ b/tests/unit/data/gtt/gtt8 @@ -0,0 +1,21 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:EXA +BEGIN:VEVENT +UID:00123456 +DTSTART;VALUE=DATE-TIME:20240306T190000Z +SEQUENCE:1 +TRANSP:OPAQUE +DTEND;VALUE=DATE-TIME:20240307T060000Z +SUMMARY:EXA TT#(00123456)\ Planned Work +CLASS:PUBLIC +ORGANIZER;CN="EXAInfra":mailto:akanksha.ambastha@exainfra.net +DTSTAMP;VALUE=DATE-TIME:20240208T000000Z +X-MAINTNOTE-PROVIDER:EXA Infrastructure +X-MAINTNOTE-ACCOUNT:Test Account +X-MAINTNOTE-MAINTENANCE-ID:00123456 +X-MAINTNOTE-OBJECT-ID:TEST/WAVE/123456 +X-MAINTNOTE-IMPACT:OUTAGE +X-MAINTNOTE-STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR \ No newline at end of file diff --git a/tests/unit/data/gtt/gtt8_result.json b/tests/unit/data/gtt/gtt8_result.json new file mode 100644 index 00000000..2f6a0c28 --- /dev/null +++ b/tests/unit/data/gtt/gtt8_result.json @@ -0,0 +1,21 @@ +[ + { + "account": "Test Account", + "circuits": [ + { + "circuit_id": "TEST/WAVE/123456", + "impact": "OUTAGE" + } + ], + "end": 1709791200, + "maintenance_id": "00123456", + "organizer": "mailto:akanksha.ambastha@exainfra.net", + "provider": "EXA Infrastructure ", + "sequence": 1, + "stamp": 1707350400, + "start": 1709751600, + "status": "CONFIRMED", + "summary": "EXA TT#(00123456)\\ Planned Work", + "uid": "00123456" + } +] \ No newline at end of file diff --git a/tests/unit/data/gtt/gtt9 b/tests/unit/data/gtt/gtt9 new file mode 100644 index 00000000..876c3b63 --- /dev/null +++ b/tests/unit/data/gtt/gtt9 @@ -0,0 +1,21 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:EXA +BEGIN:VEVENT +UID:00223456 +DTSTART;VALUE=DATE-TIME:20240306T190000Z +SEQUENCE:1 +TRANSP:OPAQUE +DTEND;VALUE=DATE-TIME:20240307T060000Z +SUMMARY:EXA TT#(00223456)\ Planned Work +CLASS:PUBLIC +ORGANIZER;CN="EXAInfra":mailto:akanksha.ambastha@exainfra.net +DTSTAMP;VALUE=DATE-TIME:20240208T000000Z +X-MAINTNOTE-PROVIDER:EXA Infrastructure +X-MAINTNOTE-ACCOUNT:Test Account +X-MAINTNOTE-MAINTENANCE-ID:00223456 +X-MAINTNOTE-OBJECT-ID:TEST/WAVE/123456 +X-MAINTNOTE-IMPACT:OUTAGE +X-MAINTNOTE-STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR \ No newline at end of file diff --git a/tests/unit/data/gtt/gtt9_result.json b/tests/unit/data/gtt/gtt9_result.json new file mode 100644 index 00000000..dff6cce5 --- /dev/null +++ b/tests/unit/data/gtt/gtt9_result.json @@ -0,0 +1,21 @@ +[ + { + "account": "Test Account", + "circuits": [ + { + "circuit_id": "TEST/WAVE/123456", + "impact": "OUTAGE" + } + ], + "end": 1709791200, + "maintenance_id": "00223456", + "organizer": "mailto:akanksha.ambastha@exainfra.net", + "provider": "EXA Infrastructure ", + "sequence": 1, + "stamp": 1707350400, + "start": 1709751600, + "status": "CONFIRMED", + "summary": "EXA TT#(00223456)\\ Planned Work", + "uid": "00223456" + } +] \ No newline at end of file diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index 06239cc8..0f3e6e66 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -411,6 +411,24 @@ Path(dir_path, "data", "gtt", "gtt7_result.json"), ], ), + ( + GTT, + [ + ("ical", Path(dir_path, "data", "gtt", "gtt8")), + ], + [ + Path(dir_path, "data", "gtt", "gtt8_result.json"), + ], + ), + ( + GTT, + [ + ("ical", Path(dir_path, "data", "gtt", "gtt9")), + ], + [ + Path(dir_path, "data", "gtt", "gtt9_result.json"), + ], + ), # HGC ( HGC, diff --git a/tests/unit/test_parsers.py b/tests/unit/test_parsers.py index 9a0411ec..59288993 100644 --- a/tests/unit/test_parsers.py +++ b/tests/unit/test_parsers.py @@ -366,6 +366,16 @@ def default(self, o): Path(dir_path, "data", "gtt", "gtt7.eml"), Path(dir_path, "data", "gtt", "gtt7_html_parser_result.json"), ), + ( + ICal, + Path(dir_path, "data", "gtt", "gtt8"), + Path(dir_path, "data", "gtt", "gtt8_result.json"), + ), + ( + ICal, + Path(dir_path, "data", "gtt", "gtt9"), + Path(dir_path, "data", "gtt", "gtt9_result.json"), + ), # HGC ( HtmlParserHGC1,