File: test_delay_parsing.py

package info (click to toggle)
python-nbxmpp 2.0.2-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,120 kB
  • sloc: python: 14,949; makefile: 8
file content (33 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (3)
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
import unittest

from nbxmpp.protocol import Node
from nbxmpp.modules.delay import parse_delay

class TestHelpers(unittest.TestCase):

    def test_parse_delay(self):

        node = """
        <message>
            <delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25Z' />
            <delay xmlns='urn:xmpp:delay' from='romeo.com' stamp='2010-09-10T23:08:25Z' />
            <delay xmlns='urn:xmpp:delay' stamp='2015-09-10T23:08:25Z' />
        </message>
        """
        message = Node(node=node)

        timestamp = parse_delay(message)
        self.assertEqual(timestamp, 1031699305.0)

        timestamp = parse_delay(message, from_=['capulet.com'])
        self.assertEqual(timestamp, 1031699305.0)

        timestamp = parse_delay(message, from_=['romeo.com'])
        self.assertEqual(timestamp, 1284160105.0)

        timestamp = parse_delay(message, not_from=['romeo.com'])
        self.assertEqual(timestamp, 1031699305.0)


if __name__ == '__main__':
    unittest.main()