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()
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)
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
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, }
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)
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
def test_decode_passed_encoded_Metadata(self, metadata): e = Packet.encode(metadata) o = Packet.decode(e) assert o.to_dict() == metadata.to_dict()
def test_decode_passed_encoded_Header(self, header): e = Packet.encode(header) o = Packet.decode(e) assert o.to_dict() == header.to_dict()
def test_decode_passed_encoded_Packet(self, packet): e = Packet.encode(packet) o = Packet.decode(e) assert o.to_dict() == packet.to_dict()
def test_encode_passed_normal_value(self): d = {'key': 'value'} o = Packet.encode(d) assert o == d
def test_encode_passed_Content(self, content): assert Packet.encode(content) == Content.encode(content)
def test_set_metadata_success(self, metadata): assert Packet().set_metadata(metadata).get_metadata() == metadata
def test_set_header_success(self, header): assert Packet().set_header(header).get_header() == header
def packet(header, parent_header, metadata, content): return (Packet().set_header(header).set_parent_header( parent_header).set_metadata(metadata).set_content(content))
def test_set_content_success(self, content): assert Packet().set_content(content).get_content() == content
def test_decode_passed_encoded_Content(self, content): e = Packet.encode(content) o = Packet.decode(e) assert o.to_dict() == content.to_dict()
def test_decode_passed_encoded_normal_value(self): d = {'key': 'value'} e = Packet.encode(d) o = Packet.decode(e) assert o == d
def test_encode_passed_Header(self, header): assert Packet.encode(header) == Header.encode(header)
def test_encode_passed_Metadata(self, metadata): assert Packet.encode(metadata) == Metadata.encode(metadata)
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