-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathtest_msg.py
More file actions
39 lines (30 loc) · 1.43 KB
/
test_msg.py
File metadata and controls
39 lines (30 loc) · 1.43 KB
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
"""Tests for messagetypes module"""
import unittest
from six import text_type
from pybitmessage import messagetypes
sample_data = {"": "message", "subject": "subject", "body": "body"}
invalid_data = {"": "message", "subject": b"\x01\x02\x03", "body": b"\x01\x02\x03\x04"}
class TestMessageTypes(unittest.TestCase):
"""A test case for messagetypes"""
def test_msg_encode(self):
"""Test msg encode"""
msgObj = messagetypes.message.Message()
encoded_message = msgObj.encode(sample_data)
self.assertEqual(type(encoded_message), dict)
self.assertEqual(encoded_message["subject"], sample_data["subject"])
self.assertEqual(encoded_message["body"], sample_data["body"])
def test_msg_decode(self):
"""Test msg decode"""
msgObj = messagetypes.constructObject(sample_data)
self.assertEqual(msgObj.subject, sample_data["subject"])
self.assertEqual(msgObj.body, sample_data["body"])
def test_invalid_data_type(self):
"""Test invalid data type"""
msgObj = messagetypes.constructObject(invalid_data)
self.assertTrue(isinstance(msgObj.subject, text_type))
self.assertTrue(isinstance(msgObj.body, text_type))
def test_msg_process(self):
"""Test msg process"""
msgObj = messagetypes.constructObject(sample_data)
self.assertTrue(isinstance(msgObj, messagetypes.message.Message))
self.assertIsNone(msgObj.process())