Repository: akolar/ogn-lib

Issue:
 Implement parser for Capturs messages (OGCAPT)

Discussion:

Patch:
diff --git a/ogn_lib/parser.py b/ogn_lib/parser.py
index 0546bbb..4ae680a 100644
--- a/ogn_lib/parser.py
+++ b/ogn_lib/parser.py
@@ -153,6 +153,8 @@ class Parser(metaclass=ParserBase):
             using Parser.PATTERN_ALL
         """
 
+        raw_message = cls._preprocess_message(raw_message)
+
         match = cls.PATTERN_ALL.match(raw_message)
 
         if not match:
@@ -187,6 +189,18 @@ class Parser(metaclass=ParserBase):
         data['raw'] = raw_message
         return data
 
+    @staticmethod
+    def _preprocess_message(message):
+        """
+        Performs additional preprocessing on the received APRS message.
+
+        :param str message: the received message
+        :return: processed message
+        :rtype: str
+        """
+
+        return message
+
     @staticmethod
     def _parse_digipeaters(digipeaters):
         """
@@ -756,3 +770,11 @@ class LiveTrack24(Parser):
             'vertical_speed': Parser._convert_fpm_to_ms(fields[1]),
             'source': fields[2]
         }
+
+
+class Capturs(Parser):
+    __destto__ = ['OGLT24', 'OGLT24-1']
+
+    @staticmethod
+    def _preprocess_message(message):
+        return message.strip('/')


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 2b99868..c1c0a9c 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -177,11 +177,13 @@ class TestParser:
         mocker.spy(parser.Parser, '_parse_digipeaters')
         mocker.spy(parser.Parser, '_parse_heading_speed')
         mocker.spy(parser.Parser, '_parse_protocol_specific')
+        mocker.spy(parser.Parser, '_preprocess_message')
 
-        parser.Parser.parse_message(
-            'FLRDD83BC>APRS,qAS,EDLF:/163148h5124.56N/00634.42E\''
-            '276/075/A=001551')
+        msg = ('FLRDD83BC>APRS,qAS,EDLF:/163148h5124.56N/00634.42E\''
+               '276/075/A=001551')
+        parser.Parser.parse_message(msg)
 
+        parser.Parser._preprocess_message.assert_called_once_with(msg)
         parser.Parser._parse_timestamp.assert_called_once_with('163148h')
         assert parser.Parser._parse_location.call_count == 2
         parser.Parser._parse_altitude.assert_called_once_with('001551')
@@ -232,6 +234,10 @@ class TestParser:
 
         assert data['comment']
 
+    def test_preprocess_message(self):
+        msg = 'asdf'
+        assert parser.Parser._preprocess_message(msg) == msg
+
     def test_parse_digipeaters(self):
         data = parser.Parser._parse_digipeaters('qAS,RECEIVER')
         assert data == {
@@ -512,6 +518,19 @@ class TestLT24:
             parser.LiveTrack24._parse_protocol_specific('id11111 GPS')
 
 
+class TestCapturs:
+    def test_process(self):
+        parser.Capturs.parse_message(
+            "FLRDDEEF1>OGCAPT,qAS,CAPTURS:/065144h4837.56N/00233.80E'000/000/")
+
+    def test_preprocess(self):
+        msg_original = ("FLRDDEEF1>OGCAPT,qAS,CAPTURS:/065144h4837.56N/"
+                        "00233.80E'000/000/")
+        msg = parser.Capturs._preprocess_message(msg_original)
+
+        assert msg == msg_original[:-1]
+
+
 class TestServerParser:
 
     def test_parse_message_beacon(self, mocker):