def test_assignment(self): """ Check assignment works correctly """ primitive = C_STORE() primitive.MessageID = 11 self.assertEqual(primitive.MessageID, 11) primitive.MessageIDBeingRespondedTo = 13 self.assertEqual(primitive.MessageIDBeingRespondedTo, 13) # AffectedSOPClassUID primitive.AffectedSOPClassUID = '1.1.1' self.assertEqual(primitive.AffectedSOPClassUID, UID('1.1.1')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) primitive.AffectedSOPClassUID = UID('1.1.2') self.assertEqual(primitive.AffectedSOPClassUID, UID('1.1.2')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) primitive.AffectedSOPClassUID = b'1.1.3' self.assertEqual(primitive.AffectedSOPClassUID, UID('1.1.3')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) # AffectedSOPInstanceUID primitive.AffectedSOPInstanceUID = b'1.2.1' self.assertEqual(primitive.AffectedSOPInstanceUID, UID('1.2.1')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) primitive.AffectedSOPInstanceUID = UID('1.2.2') self.assertEqual(primitive.AffectedSOPInstanceUID, UID('1.2.2')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) primitive.AffectedSOPInstanceUID = '1.2.3' self.assertEqual(primitive.AffectedSOPInstanceUID, UID('1.2.3')) self.assertTrue(isinstance(primitive.AffectedSOPClassUID, UID)) primitive.Priority = 0x02 self.assertEqual(primitive.Priority, 0x02) primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' self.assertEqual(primitive.MoveOriginatorApplicationEntityTitle, b'UNITTEST_SCP ') primitive.MoveOriginatorApplicationEntityTitle = b'UNITTEST_SCP' self.assertEqual(primitive.MoveOriginatorApplicationEntityTitle, b'UNITTEST_SCP ') primitive.MoveOriginatorMessageID = 15 self.assertEqual(primitive.MoveOriginatorMessageID, 15) ref_ds = Dataset() ref_ds.PatientID = 1234567 primitive.DataSet = BytesIO(encode(ref_ds, True, True)) #self.assertEqual(primitive.DataSet, ref_ds) primitive.Status = 0x0000 self.assertEqual(primitive.Status, 0x0000) primitive.Status = 0xC123 self.assertEqual(primitive.Status, 0xC123) primitive.Status = 0xEE01 self.assertEqual(primitive.Status, 0xEE01)
def test_assignment(self): """ Check assignment works correctly """ primitive = C_STORE() primitive.MessageID = 11 assert primitive.MessageID == 11 primitive.MessageIDBeingRespondedTo = 13 assert primitive.MessageIDBeingRespondedTo == 13 # 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) primitive.Priority = 0x02 assert primitive.Priority == 0x02 primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' assert primitive.MoveOriginatorApplicationEntityTitle == b'UNITTEST_SCP ' primitive.MoveOriginatorApplicationEntityTitle = b'UNITTEST_SCP' assert primitive.MoveOriginatorApplicationEntityTitle == b'UNITTEST_SCP ' primitive.MoveOriginatorMessageID = 15 assert primitive.MoveOriginatorMessageID == 15 ref_ds = Dataset() ref_ds.PatientID = 1234567 primitive.DataSet = BytesIO(encode(ref_ds, True, True)) #assert primitive.DataSet, ref_ds) primitive.Status = 0x0000 assert primitive.Status == 0x0000 primitive.Status = 0xC123 assert primitive.Status == 0xC123 primitive.Status = 0xEE01 assert primitive.Status == 0xEE01
def test_send_c_store(self): """Check sending DIMSE C-STORE messages.""" # C-STORE-RQ primitive = C_STORE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' def test_callback(msg): """Callback""" self.assertEqual(msg.__class__.__name__, 'C_STORE_RQ') self.dimse.on_send_dimse_message = test_callback self.dimse.send_msg(primitive, 1) # C-STORE-RSP primitive = C_STORE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 def test_callback(msg): """Callback""" self.assertEqual(msg.__class__.__name__, 'C_STORE_RSP') self.dimse.on_send_dimse_message = test_callback self.dimse.send_msg(primitive, 1)
def test_callback_send_c_store(self): """Check callback for sending DIMSE C-STORE messages.""" # C-STORE-RQ primitive = C_STORE() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' # CT primitive.AffectedSOPInstanceUID = '1.1.2' primitive.Priority = 0x02 primitive.DataSet = BytesIO() # CT + no dataset self.dimse.send_msg(primitive, 1) primitive.AffectedSOPClassUID = '1.1.1' # No UID type, no dataset # MR + dataset primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.4' # MR bytestream = BytesIO() bytestream.write(c_store_ds) primitive.DataSet = bytestream self.dimse.send_msg(primitive, 1) # C-STORE-RSP primitive = C_STORE() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 self.dimse.send_msg(primitive, 1)
def test_is_valid_resposne(self): """Test C_STORE.is_valid_response.""" primitive = C_STORE() assert not primitive.is_valid_response primitive.MessageIDBeingRespondedTo = 1 assert not primitive.is_valid_response primitive.Status = 0x0000 assert primitive.is_valid_response
def test_callback_receive_c_store(self): """Check callback for sending DIMSE C-STORE messages.""" # C-STORE-RQ primitive = C_STORE() 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.' \ '1215709044.1459316254.522441' primitive.Priority = 0x02 primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' primitive.MoveOriginatorMessageID = 3 primitive.DataSet = BytesIO() # No dataset msg = C_STORE_RQ() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_store_rq(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" primitive.DataSet = BytesIO(encode(ref_ds, True, True)) msg = C_STORE_RQ() msg.primitive_to_message(primitive) # Dataset self.dimse.debug_receive_c_store_rq(msg) # C-STORE-RSP primitive = C_STORE() primitive.MessageIDBeingRespondedTo = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.AffectedSOPInstanceUID = '1.2.392.200036.9116.2.6.1.48.' \ '1215709044.1459316254.522441' primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' primitive.MoveOriginatorMessageID = 3 primitive.DataSet = BytesIO() # Check statuses + no dataset for status in [0x0000, 0xb000, 0xb007, 0xb006, 0xa700, 0xa900, 0xc000]: primitive.Status = status msg = C_STORE_RSP() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_store_rsp(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" msg = C_STORE_RSP() msg.primitive_to_message(primitive) # Dataset msg.data_set = BytesIO(encode(ref_ds, True, True)) self.dimse.debug_receive_c_store_rsp(msg)
def test_conversion_rsp(self): """ Check conversion to a -RSP PDU produces the correct output """ primitive = C_STORE() primitive.MessageIDBeingRespondedTo = 5 primitive.AffectedSOPClassUID = '1.2.4.10' primitive.AffectedSOPInstanceUID = '1.2.4.5.7.8' primitive.Status = 0x0000 dimse_msg = C_STORE_RSP() dimse_msg.primitive_to_message(primitive) pdvs = dimse_msg.encode_msg(1, 16382) cs_pdv = pdvs[0].presentation_data_value_list[0][1] self.assertEqual(cs_pdv, c_store_rsp_cmd)
def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = C_STORE() # MessageID with self.assertRaises(TypeError): primitive.MessageID = 'halp' with self.assertRaises(TypeError): primitive.MessageID = 1.111 with self.assertRaises(ValueError): primitive.MessageID = 65536 with self.assertRaises(ValueError): primitive.MessageID = -1 # MessageIDBeingRespondedTo with self.assertRaises(TypeError): primitive.MessageIDBeingRespondedTo = 'halp' with self.assertRaises(TypeError): primitive.MessageIDBeingRespondedTo = 1.111 with self.assertRaises(ValueError): primitive.MessageIDBeingRespondedTo = 65536 with self.assertRaises(ValueError): primitive.MessageIDBeingRespondedTo = -1 # AffectedSOPClassUID with self.assertRaises(TypeError): primitive.AffectedSOPClassUID = 45.2 with self.assertRaises(TypeError): primitive.AffectedSOPClassUID = 100 with self.assertRaises(ValueError): primitive.AffectedSOPClassUID = 'abc' # AffectedSOPInstanceUID with self.assertRaises(TypeError): primitive.AffectedSOPInstanceUID = 45.2 with self.assertRaises(TypeError): primitive.AffectedSOPInstanceUID = 100 with self.assertRaises(ValueError): primitive.AffectedSOPInstanceUID = 'abc' # Priority with self.assertRaises(ValueError): primitive.Priority = 45.2 with self.assertRaises(ValueError): primitive.Priority = 'abc' with self.assertRaises(ValueError): primitive.Priority = -1 with self.assertRaises(ValueError): primitive.Priority = 3 # MoveOriginatorApplicationEntityTitle with self.assertRaises(TypeError): primitive.MoveOriginatorApplicationEntityTitle = 45.2 with self.assertRaises(TypeError): primitive.MoveOriginatorApplicationEntityTitle = 100 with self.assertRaises(ValueError): primitive.MoveOriginatorApplicationEntityTitle = '' with self.assertRaises(ValueError): primitive.MoveOriginatorApplicationEntityTitle = ' ' # MoveOriginatorMessageID with self.assertRaises(TypeError): primitive.MoveOriginatorMessageID = 'halp' with self.assertRaises(TypeError): primitive.MoveOriginatorMessageID = 1.111 with self.assertRaises(ValueError): primitive.MoveOriginatorMessageID = 65536 with self.assertRaises(ValueError): primitive.MoveOriginatorMessageID = -1 # DataSet with self.assertRaises(TypeError): primitive.DataSet = 'halp' with self.assertRaises(TypeError): primitive.DataSet = 1.111 with self.assertRaises(TypeError): primitive.DataSet = 50 with self.assertRaises(TypeError): primitive.DataSet = [30, 10] # Status with self.assertRaises(TypeError): primitive.Status = 19.4