示例#1
0
 def test_encode_passed_Packet(self, packet):
     o = Packet.encode(packet)
     assert o[Packet.name()]
     assert o['_signature'] == packet.get_signature()
     assert o['_header'] == packet.get_header()
     assert o['_parent_header'] == packet.get_parent_header()
     assert o['_metadata'] == packet.get_metadata()
     assert o['_content'] == packet.get_content()
示例#2
0
    def test_gen_signature_content_not_set(self, header, parent_header,
                                           metadata):
        p = (Packet().set_header(header).set_parent_header(
            parent_header).set_metadata(metadata))

        with pytest.raises(AssertionError):
            hmac = HMAC(b'12345')
            p.gen_signature(hmac)
示例#3
0
    def test_gen_signature_success(self, header, parent_header, metadata,
                                   content):
        p = (Packet().set_header(header).set_parent_header(
            parent_header).set_metadata(metadata).set_content(content))

        hmac = HMAC(b'12345')
        p.gen_signature(hmac)

        assert p.get_signature() is not None
示例#4
0
    def test_to_dict(self, header, parent_header, metadata, content):
        p = (Packet().set_header(header).set_parent_header(
            parent_header).set_metadata(metadata).set_content(content))
        p._signature = '12345'

        assert p.to_dict() == {
            'signature': '12345',
            'header': header,
            'parent_header': parent_header,
            'metadata': metadata,
            'content': content,
        }
示例#5
0
    def test_gen_signature_hmac_None(
        self,
        header,
        parent_header,
        metadata,
        content,
    ):
        p = (Packet().set_header(header).set_parent_header(
            parent_header).set_metadata(metadata).set_content(content))

        with pytest.raises(AssertionError):
            hmac = None
            p.gen_signature(hmac)
示例#6
0
    def test_process(self):
        def my_action(p):
            old_value = p.get_content().get_data()
            p.get_content().set_data(1000)
            return old_value

        ar = ActionRegistry()
        ar.register(TEST_TYPE, my_action)

        p = (Packet().set_header(Header().set_type(TEST_TYPE)).set_content(
            Content().set_data(999)))

        assert ar.process(p) == 999
        assert p.get_content().get_data() == 1000
示例#7
0
 def test_decode_passed_encoded_Metadata(self, metadata):
     e = Packet.encode(metadata)
     o = Packet.decode(e)
     assert o.to_dict() == metadata.to_dict()
示例#8
0
 def test_decode_passed_encoded_Header(self, header):
     e = Packet.encode(header)
     o = Packet.decode(e)
     assert o.to_dict() == header.to_dict()
示例#9
0
 def test_decode_passed_encoded_Packet(self, packet):
     e = Packet.encode(packet)
     o = Packet.decode(e)
     assert o.to_dict() == packet.to_dict()
示例#10
0
 def test_encode_passed_normal_value(self):
     d = {'key': 'value'}
     o = Packet.encode(d)
     assert o == d
示例#11
0
 def test_encode_passed_Content(self, content):
     assert Packet.encode(content) == Content.encode(content)
示例#12
0
 def test_set_metadata_success(self, metadata):
     assert Packet().set_metadata(metadata).get_metadata() == metadata
示例#13
0
 def test_set_header_success(self, header):
     assert Packet().set_header(header).get_header() == header
示例#14
0
def packet(header, parent_header, metadata, content):
    return (Packet().set_header(header).set_parent_header(
        parent_header).set_metadata(metadata).set_content(content))
示例#15
0
 def test_set_content_success(self, content):
     assert Packet().set_content(content).get_content() == content
示例#16
0
 def test_decode_passed_encoded_Content(self, content):
     e = Packet.encode(content)
     o = Packet.decode(e)
     assert o.to_dict() == content.to_dict()
示例#17
0
 def test_decode_passed_encoded_normal_value(self):
     d = {'key': 'value'}
     e = Packet.encode(d)
     o = Packet.decode(e)
     assert o == d
示例#18
0
 def test_encode_passed_Header(self, header):
     assert Packet.encode(header) == Header.encode(header)
示例#19
0
 def test_encode_passed_Metadata(self, metadata):
     assert Packet.encode(metadata) == Metadata.encode(metadata)
示例#20
0
 def test_set_parent_header_success(self, parent_header):
     expected = parent_header
     actual = Packet().set_parent_header(parent_header).get_parent_header()
     assert actual == expected