def test_send_n_create(self): """Check sending DIMSE N-CREATE messages.""" # N-CREATE-RQ primitive = N_CREATE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' def test_callback(msg): """Callback""" self.assertEqual(msg.__class__.__name__, 'N_CREATE_RQ') self.dimse.on_send_dimse_message = test_callback self.dimse.send_msg(primitive, 1) # N-CREATE-RSP primitive = N_CREATE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 def test_callback(msg): """Callback""" self.assertEqual(msg.__class__.__name__, 'N_CREATE_RSP') self.dimse.on_send_dimse_message = test_callback self.dimse.send_msg(primitive, 1)
def test_conversion_rq(self): """ Check conversion to a -RQ PDU produces the correct output """ primitive = N_CREATE() primitive.MessageID = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.AffectedSOPInstanceUID = '1.2.392.200036.9116.2.6.1.48' ds = Dataset() ds.PatientID = 'Test1101' ds.PatientName = "Tube HeNe" primitive.AttributeList = BytesIO(encode(ds, True, True)) dimse_msg = N_CREATE_RQ() dimse_msg.primitive_to_message(primitive) pdvs = [] for fragment in dimse_msg.encode_msg(1, 16382): pdvs.append(fragment) assert len(pdvs) == 2 cs_pdv = pdvs[0].presentation_data_value_list[0][1] ds_pdv = pdvs[1].presentation_data_value_list[0][1] assert cs_pdv == n_create_rq_cmd assert ds_pdv == n_create_rq_ds
def test_is_valid_request(self): """Test N_CREATE.is_valid_request""" primitive = N_CREATE() assert not primitive.is_valid_request primitive.MessageID = 1 assert not primitive.is_valid_request primitive.AffectedSOPClassUID = '1.2' assert primitive.is_valid_request
def test_callback_send_n_create(self): """Check callback for sending DIMSE N-CREATE messages.""" # N-CREATE-RQ primitive = N_CREATE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' self.dimse.send_msg(primitive, 1) # N-CREATE-RSP primitive = N_CREATE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 self.dimse.send_msg(primitive, 1)
def test_assignment(self): """ Check assignment works correctly """ primitive = N_CREATE() # AffectedSOPClassUID primitive.AffectedSOPClassUID = '1.1.1' assert primitive.AffectedSOPClassUID == UID('1.1.1') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPClassUID = UID('1.1.2') assert primitive.AffectedSOPClassUID == UID('1.1.2') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPClassUID = b'1.1.3' assert primitive.AffectedSOPClassUID == UID('1.1.3') assert isinstance(primitive.AffectedSOPClassUID, UID) # AffectedSOPInstanceUID primitive.AffectedSOPInstanceUID = b'1.2.1' assert primitive.AffectedSOPInstanceUID == UID('1.2.1') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPInstanceUID = UID('1.2.2') assert primitive.AffectedSOPInstanceUID == UID('1.2.2') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPInstanceUID = '1.2.3' assert primitive.AffectedSOPInstanceUID == UID('1.2.3') assert isinstance(primitive.AffectedSOPClassUID, UID) # AttributeList ref_ds = Dataset() ref_ds.PatientID = '1234567' primitive.AttributeList = BytesIO(encode(ref_ds, True, True)) ds = decode(primitive.AttributeList, True, True) assert ds.PatientID == '1234567' # MessageID primitive.MessageID = 11 assert 11 == primitive.MessageID # MessageIDBeingRespondedTo primitive.MessageIDBeingRespondedTo = 13 assert 13 == primitive.MessageIDBeingRespondedTo # Status primitive.Status = 0x0000 assert primitive.Status == 0x0000
def test_callback_send_n_create(self): """Check callback for sending DIMSE N-CREATE messages.""" # N-CREATE-RQ primitive = N_CREATE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' self.dimse.send_msg(primitive, 1) # User defined primitive.AffectedSOPInstanceUID = '1.2.3' primitive.AttributeList = BytesIO(b'\x00\x01') self.dimse.send_msg(primitive, 1) # N-CREATE-RSP primitive = N_CREATE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 self.dimse.send_msg(primitive, 1) primitive.AffectedSOPClassUID = '1.2' primitive.AffectedSOPInstanceUID = '1.2.3' primitive.AattributeList = BytesIO(b'\x00\x01') self.dimse.send_msg(primitive, 1)
def test_callback_receive_n_create(self): """Check callback for receiving DIMSE N-CREATE messages.""" # N-CREATE-RQ primitive = N_CREATE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' msg = N_CREATE_RQ() msg.primitive_to_message(primitive) msg.ID = 1 self.dimse.debug_receive_n_create_rq(msg) # User defined primitive.AffectedSOPInstanceUID = '1.1.1.1' primitive.AttributeList = BytesIO(n_create_rq_ds) msg = N_CREATE_RQ() msg.primitive_to_message(primitive) msg.ID = 1 self.dimse.debug_receive_n_create_rq(msg) # N-CREATE-RSP primitive = N_CREATE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 msg = N_CREATE_RSP() msg.primitive_to_message(primitive) msg.ID = 1 self.dimse.debug_receive_n_create_rsp(msg) # User defined primitive.AffectedSOPClassUID = '1.1.1' primitive.AffectedSOPInstanceUID = '1.1.1.1' primitive.AttributeList = BytesIO(n_create_rsp_ds) msg = N_CREATE_RSP() msg.primitive_to_message(primitive) msg.ID = 1 self.dimse.debug_receive_n_create_rsp(msg)
def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = N_CREATE() # MessageID with pytest.raises(TypeError): primitive.MessageID = 'halp' with pytest.raises(TypeError): primitive.MessageID = 1.111 with pytest.raises(ValueError): primitive.MessageID = 65536 with pytest.raises(ValueError): primitive.MessageID = -1 # MessageIDBeingRespondedTo with pytest.raises(TypeError): primitive.MessageIDBeingRespondedTo = 'halp' with pytest.raises(TypeError): primitive.MessageIDBeingRespondedTo = 1.111 with pytest.raises(ValueError): primitive.MessageIDBeingRespondedTo = 65536 with pytest.raises(ValueError): primitive.MessageIDBeingRespondedTo = -1 # AffectedSOPClassUID with pytest.raises(TypeError): primitive.AffectedSOPClassUID = 45.2 with pytest.raises(TypeError): primitive.AffectedSOPClassUID = 100 with pytest.raises(ValueError): primitive.AffectedSOPClassUID = 'abc' # AffectedSOPInstanceUID with pytest.raises(TypeError): primitive.AffectedSOPInstanceUID = 45.2 with pytest.raises(TypeError): primitive.AffectedSOPInstanceUID = 100 with pytest.raises(ValueError): primitive.AffectedSOPInstanceUID = 'abc' # AttributeList msg = r"'AttributeList' parameter must be a BytesIO object" with pytest.raises(TypeError, match=msg): primitive.AttributeList = 'halp' with pytest.raises(TypeError): primitive.AttributeList = 1.111 with pytest.raises(TypeError): primitive.AttributeList = 50 with pytest.raises(TypeError): primitive.AttributeList = [30, 10] # Status with pytest.raises(TypeError): primitive.Status = 19.4