File: test_parse_message_rejack.py

package info (click to toggle)
python-aprslib 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: python: 2,973; makefile: 216
file content (124 lines) | stat: -rw-r--r-- 3,971 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import unittest
from aprslib.parsing.message import parse_message

# ack/rej assertion tests
class AckRejTests(unittest.TestCase):

    # errorneus rej
    def test_errorneus_rej(self):
        unparsed, result = parse_message("WXBOT    :red12345")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': 'red12345',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # reject with "old" msgno
    def test_reject_old_msgno(self):
        unparsed, result = parse_message("WXBOT    :rej123")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'msgNo': '123',
            'response': 'rej'
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # ack with new msgNo but no ackMsgNo
    def test_ack_new_msgno_but_no_ack_msgno(self):
        unparsed, result = parse_message("WXBOT    :ackAB}")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'response': 'ack',
            'msgNo': 'AB',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # ack with new msgNo and ackMsgNo
    def test_ack_new_msgno_and_ackmsgno(self):
        unparsed, result = parse_message("WXBOT    :ackAB}CD")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'response': 'ack',
            'msgNo': 'AB',
            'ackMsgNo': 'CD',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

# message text body tests
class MessageTestBodyTests(unittest.TestCase):

    # message body without msg no
    def test_message_without_msgno(self):
        unparsed, result = parse_message("WXBOT    :HelloWorld  ")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': 'HelloWorld',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # message body with msg no - old format
    def test_message_body_with_no_msgno_oldformat(self):
        unparsed, result = parse_message("WXBOT    :HelloWorld  {ABCDE")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': 'HelloWorld',
            'msgNo': 'ABCDE',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # message body with msgNo (new format) and ackMsgNo missing
    def test_message_body_with_msgno_and_ackmsgno_missing_newformat(self):
        unparsed, result = parse_message("WXBOT    :HelloWorld  {AB}")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': 'HelloWorld',
            'msgNo': 'AB',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # message body with msgNo and ackMsgNo (new format)
    def test_message_body_with_msgno_and_ackmsgno_newformat(self):
        unparsed, result = parse_message("WXBOT    :HelloWorld  {AB}CD")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': 'HelloWorld',
            'msgNo': 'AB',
            'ackMsgNo': 'CD',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)

    # message body with really long message
    def test_message_body_with_long_message(self):
        unparsed, result = parse_message("WXBOT    :00000000001111111111222222222233333333334444444444555555555566666666667777777777")
        expected = {
            'format': 'message',
            'addresse': 'WXBOT',
            'message_text': '00000000001111111111222222222233333333334444444444555555555566666666667777777777',
        }

        self.assertEqual(unparsed, '')
        self.assertEqual(expected, result)