class TestDIMSEProvider(object): """Test DIMSE service provider operations.""" def setup(self): """Set up""" self.dimse = DIMSEServiceProvider(DummyAssociation()) def test_receive_not_pdata(self): """Test we get back None if not a P_DATA""" assert self.dimse.get_msg(True) == (None, None) def test_peek_empty(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(DummyAssociation()) assert dimse.peek_msg() == (None, None) def test_peek_item(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(DummyAssociation()) primitive = C_STORE() dimse.msg_queue.put((14, primitive)) assert dimse.peek_msg() == (14, primitive) def test_invalid_message(self): """Test that an invalid message kills the association.""" class DummyDUL(object): def __init__(self): self.event_queue = queue.Queue() dimse = DIMSEServiceProvider(DummyAssociation()) p_data_tf = ( # | | length b"\x04\x00\x00\x00\x00\x4E" # P-DATA-TF 78 b"\x00\x00\x00\x4a\x01" # PDV Item 70 b"\x03" # PDV: 2 -> 69 # C-ECHO-RQ # CommandGroupLen | len 4 | value 64 b"\x00\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00" # 12 # AffSOPClass | len 18 | value b"\x00\x00\x02\x00\x12\x00\x00\x00" b"\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e" b"\x31\x00" # 26 # CommandField | len 2 | 0x0030 -> C-ECHO-RQ b"\x00\x00\x00\x01\x02\x00\x00\x00\x30\x00" # 10 # Message ID | len 6 | -> should be invalid b"\x00\x00\x10\x01\x06\x00\x00\x00\xff\xff\xff\xff\xff\xff" # 14 # CommandDSType | len 2 | no DS b"\x00\x00\x00\x08\x02\x00\x00\x00\x01\x01" # 10 ) pdata = P_DATA_TF() pdata.decode(p_data_tf) pdata = pdata.to_primitive() # Should send Evt19 due to invalid message dimse.receive_primitive(pdata) assert dimse.assoc.dul.event_queue.get() == 'Evt19'
class TestDIMSEProvider(object): """Test DIMSE service provider operations.""" def setup(self): """Set up""" self.dimse = DIMSEServiceProvider(DummyAssociation()) def test_receive_not_pdata(self): """Test we get back None if not a P_DATA""" assert self.dimse.get_msg(True) == (None, None) def test_peek_empty(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(DummyAssociation()) assert dimse.peek_msg() == (None, None) def test_peek_item(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(DummyAssociation()) primitive = C_STORE() dimse.msg_queue.put((14, primitive)) assert dimse.peek_msg() == (14, primitive) def test_invalid_message(self): class DummyDUL(object): def __init__(self): self.event_queue = queue.Queue() dimse = DIMSEServiceProvider(DummyAssociation()) p_data_tf = ( b"\x04\x00\x00\x00\x00\x48" # P-DATA-TF 74 b"\x00\x00\x00\x44\x01" # PDV Item 70 b"\x03" # PDV: 2 -> 69 b"\x00\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00" # 12 Command Group Length b"\x00\x00\x02\x00\x12\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31\x00" # 26 b"\x00\x00\x00\x01\x02\x00\x00\x00\x30\x00" # 10 Command Field b"\x00\x00\x10\x01\x00\x00\x00\x00" # 10 Message ID b"\x00\x00\x00\x08\x02\x00\x00\x00\x01\x01" # 10 Command Data Set Type ) pdata = P_DATA_TF() pdata.decode(p_data_tf) pdata = pdata.to_primitive() dimse.receive_primitive(pdata) assert dimse.assoc.dul.event_queue.get() == 'Evt19'
class TestDIMSEProvider(object): """Test DIMSE service provider operations.""" def setup(self): """Set up""" self.dimse = DIMSEServiceProvider(DummyDUL(), 1) def test_receive_not_pdata(self): """Test we get back None if not a P_DATA""" assert self.dimse.get_msg(True) == (None, None) @pytest.mark.parametrize("primitive, cls_name", REFERENCE_MSG) def test_send_msg(self, primitive, cls_name): """Check sending DIMSE messages.""" # -RQ primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' def test_callback(msg): """Callback""" assert msg.__class__.__name__ == cls_name[0] self.dimse.on_send_dimse_message = test_callback if cls_name[0]: self.dimse.send_msg(primitive, 1) # -RSP primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 def test_callback(msg): """Callback""" assert msg.__class__.__name__ == cls_name[1] self.dimse.on_send_dimse_message = test_callback self.dimse.send_msg(primitive, 1) def test_peek_empty(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(None, 0.5) assert dimse.peek_msg() == (None, None) def test_peek_item(self): """Test peek_msg with nothing on the queue.""" dimse = DIMSEServiceProvider(None, 0.5) primitive = C_STORE() dimse.msg_queue.put((14, primitive)) assert dimse.peek_msg() == (14, primitive) def test_invalid_message(self): class DummyDUL(object): def __init__(self): self.event_queue = queue.Queue() dul = DummyDUL() dimse = DIMSEServiceProvider(dul, 0.5) p_data_tf = ( b"\x04\x00\x00\x00\x00\x48" # P-DATA-TF 74 b"\x00\x00\x00\x44\x01" # PDV Item 70 b"\x03" # PDV: 2 -> 69 b"\x00\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00" # 12 Command Group Length b"\x00\x00\x02\x00\x12\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31\x00" # 26 b"\x00\x00\x00\x01\x02\x00\x00\x00\x30\x00" # 10 Command Field b"\x00\x00\x10\x01\x00\x00\x00\x00" # 10 Message ID b"\x00\x00\x00\x08\x02\x00\x00\x00\x01\x01" # 10 Command Data Set Type ) pdata = P_DATA_TF() pdata.decode(p_data_tf) pdata = pdata.to_primitive() dimse.receive_primitive(pdata) assert dul.event_queue.get() == 'Evt19'