-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_proto.py
45 lines (35 loc) · 1.28 KB
/
test_proto.py
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
"""
These tests ensure that different messages sent over the wire come back
correctly after being serialized and unserialized.
"""
import unittest
from jqueue import protocol
class TestProtocol(unittest.TestCase):
def roundtrip(self, message):
msg_bytes = protocol.serialize(message)
out_message, buffer = protocol.message_from_bytes(msg_bytes)
self.assertEqual(buffer, b'')
self.assertEqual(out_message, message)
def test_request_job(self):
TTL = 30
self.roundtrip(protocol.RequestJob(TTL))
def test_job_reply(self):
ID = b'42'
CONTENT = b'this is a sample job'
self.roundtrip(protocol.Job(ID, CONTENT))
def test_ping(self):
ID = b'42'
self.roundtrip(protocol.Ping(ID))
def test_submit_resut(self):
ID = b'42'
CONTENT = b'this is a sample result'
self.roundtrip(protocol.SubmitResult(ID, CONTENT))
def test_ok(self):
self.roundtrip(protocol.Ok())
def test_error(self):
ERRORS = {protocol.Errors.NO_JOB_AVAIL, protocol.Errors.TTL_TOO_HIGH,
protocol.Errors.NOT_RESERVED, protocol.Errors.DO_NOT_UNDERSTAND}
for err in ERRORS:
self.roundtrip(protocol.Error(err))
if __name__ == '__main__':
unittest.main()