Skip to content

Commit effe45e

Browse files
committed
Tests update
Update messages test (from/to dict) Update response test (from/to dict)
1 parent 208415b commit effe45e

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

tests/types/message_test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44

55

66
class MessageTestCase(unittest.TestCase):
7+
test_data = [
8+
(Message(id_=1, async_=True, type_='log', data='Hello'),
9+
{"async": True, "type": "log", "id": 1, "data": "Hello"}),
10+
(Message(id_=1, async_=False, type_='log', data='Hello'),
11+
{"async": False, "type": "log", "id": 1, "data": "Hello"})
12+
]
713

8-
def test_message_from_json(self):
9-
msg = Message(id=1, async_=True, type_='log', data='Hello')
10-
self.assertEqual(Message.from_json('{"async": true, "type": "log", "id": 1, "data": "Hello"}'), msg)
14+
def test_message_from_dict(self):
15+
for i in range(len(self.test_data)):
16+
with self.subTest(i=i):
17+
message = self.test_data[i][0]
18+
dict_ = self.test_data[i][1]
19+
self.assertEqual(Message.from_dict(dict_), message)
1120

12-
def test_message_to_json(self):
13-
msg = Message(id=1, async_=True, type_='log', data='Hello')
14-
self.assertEqual(msg.to_json(), '{"async": true, "type": "log", "id": 1, "data": "Hello"}')
21+
def test_message_to_dict(self):
22+
for i in range(len(self.test_data)):
23+
with self.subTest(i=i):
24+
message = self.test_data[i][0]
25+
dict_ = self.test_data[i][1]
26+
self.assertEqual(message.to_dict(), dict_)
1527

1628

1729
if __name__ == '__main__':

tests/types/response_test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44

55

66
class ResponseTestCase(unittest.TestCase):
7+
test_data = [
8+
(Response(message='Hello', success=True, result=None),
9+
{"Success": True, "Message": "Hello", "Result": None}),
10+
(Response(message='Hello', success=False, result=None),
11+
{"Success": False, "Message": "Hello", "Result": None})
12+
]
713

8-
def test_response_from_json(self):
9-
resp = Response(message='Hello', success=True, result=None)
10-
self.assertEqual(Response.from_json('{"Success": true, "Message": "Hello", "Result": null}'), resp)
14+
def test_response_from_dict(self):
15+
for i in range(len(self.test_data)):
16+
with self.subTest(i=i):
17+
response = self.test_data[i][0]
18+
dict_ = self.test_data[i][1]
19+
self.assertEqual(Response.from_dict(dict_), response)
1120

12-
def test_response_to_json(self):
13-
resp = Response(message='Hello', success=True, result=None)
14-
self.assertEqual(resp.to_json(), '{"Success": true, "Message": "Hello", "Result": null}')
21+
def test_response_to_dict(self):
22+
for i in range(len(self.test_data)):
23+
with self.subTest(i=i):
24+
response = self.test_data[i][0]
25+
dict_ = self.test_data[i][1]
26+
self.assertEqual(response.to_dict(), dict_)
1527

1628

1729
if __name__ == '__main__':

0 commit comments

Comments
 (0)