def test_conversion_rsp(self): """ Check conversion to a -RSP PDU produces the correct output """ primitive = C_GET() primitive.MessageIDBeingRespondedTo = 5 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.Status = 0xFF00 primitive.NumberOfRemainingSuboperations = 3 primitive.NumberOfCompletedSuboperations = 1 primitive.NumberOfFailedSuboperations = 2 primitive.NumberOfWarningSuboperations = 4 ref_identifier = Dataset() ref_identifier.QueryRetrieveLevel = "PATIENT" ref_identifier.PatientID = "*" primitive.Identifier = BytesIO(encode(ref_identifier, True, True)) dimse_msg = C_GET_RSP() dimse_msg.primitive_to_message(primitive) pdvs = dimse_msg.encode_msg(1, 16382) cs_pdv = pdvs[0].presentation_data_value_list[0][1] ds_pdv = pdvs[1].presentation_data_value_list[0][1] self.assertEqual(cs_pdv, c_get_rsp_cmd) self.assertEqual(ds_pdv, c_get_rsp_ds)
def test_assignment(self): """ Check assignment works correctly """ primitive = C_GET() 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)) primitive.Priority = 0x02 self.assertEqual(primitive.Priority, 0x02) ref_ds = Dataset() ref_ds.PatientID = 1234567 primitive.Identifier = 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) primitive.NumberOfRemainingSuboperations = 1 self.assertEqual(primitive.NumberOfRemainingSuboperations, 1) primitive.NumberOfCompletedSuboperations = 2 self.assertEqual(primitive.NumberOfCompletedSuboperations, 2) primitive.NumberOfFailedSuboperations = 3 self.assertEqual(primitive.NumberOfFailedSuboperations, 3) primitive.NumberOfWarningSuboperations = 4 self.assertEqual(primitive.NumberOfWarningSuboperations, 4)
def test_assignment(self): """ Check assignment works correctly """ primitive = C_GET() 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) primitive.Priority = 0x02 assert primitive.Priority == 0x02 ref_ds = Dataset() ref_ds.PatientID = 1234567 primitive.Identifier = 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 primitive.NumberOfRemainingSuboperations = 1 assert primitive.NumberOfRemainingSuboperations == 1 primitive.NumberOfCompletedSuboperations = 2 assert primitive.NumberOfCompletedSuboperations == 2 primitive.NumberOfFailedSuboperations = 3 assert primitive.NumberOfFailedSuboperations == 3 primitive.NumberOfWarningSuboperations = 4 assert primitive.NumberOfWarningSuboperations == 4
def test_callback_receive_c_get(self): """Check callback for receiving DIMSE C-GET messages.""" # C-GET-RQ primitive = C_GET() 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.Identifier = BytesIO() # No dataset msg = C_GET_RQ() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_get_rq(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" primitive.Identifier = BytesIO(encode(ref_ds, True, True)) msg = C_GET_RQ() msg.primitive_to_message(primitive) # Dataset self.dimse.debug_receive_c_get_rq(msg) # C-GET-RSP primitive = C_GET() 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.Identifier = BytesIO() primitive.NumberOfCompletedSuboperations = 1 primitive.NumberOfWarningSuboperations = 3 primitive.NumberOfFailedSuboperations = 4 # No dataset, remaining subops primitive.Status = 0x0000 # Must be for pending msg = C_GET_RSP() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_get_rsp(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" primitive.Identifier = BytesIO(encode(ref_ds, True, True)) primitive.NumberOfRemainingSuboperations = 2 msg = C_GET_RSP() msg.primitive_to_message(primitive) # Dataset self.dimse.debug_receive_c_get_rsp(msg) # C-CANCEL-GET-RQ self.dimse.debug_receive_c_cancel_rq(msg)
def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = C_GET() # 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 # NumberOfRemainingSuboperations with self.assertRaises(TypeError): primitive.NumberOfRemainingSuboperations = 'halp' with self.assertRaises(TypeError): primitive.NumberOfRemainingSuboperations = 1.111 with self.assertRaises(ValueError): primitive.NumberOfRemainingSuboperations = -1 # NumberOfCompletedSuboperations with self.assertRaises(TypeError): primitive.NumberOfCompletedSuboperations = 'halp' with self.assertRaises(TypeError): primitive.NumberOfCompletedSuboperations = 1.111 with self.assertRaises(ValueError): primitive.NumberOfCompletedSuboperations = -1 # NumberOfFailedSuboperations with self.assertRaises(TypeError): primitive.NumberOfFailedSuboperations = 'halp' with self.assertRaises(TypeError): primitive.NumberOfFailedSuboperations = 1.111 with self.assertRaises(ValueError): primitive.NumberOfFailedSuboperations = -1 # NumberOfWarningSuboperations with self.assertRaises(TypeError): primitive.NumberOfWarningSuboperations = 'halp' with self.assertRaises(TypeError): primitive.NumberOfWarningSuboperations = 1.111 with self.assertRaises(ValueError): primitive.NumberOfWarningSuboperations = -1 # AffectedSOPClassUID with self.assertRaises(TypeError): primitive.AffectedSOPClassUID = 45.2 with self.assertRaises(TypeError): primitive.AffectedSOPClassUID = 100 with self.assertRaises(ValueError): primitive.AffectedSOPClassUID = '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 # Identifier with self.assertRaises(TypeError): primitive.Identifier = 'halp' with self.assertRaises(TypeError): primitive.Identifier = 1.111 with self.assertRaises(TypeError): primitive.Identifier = 50 with self.assertRaises(TypeError): primitive.Identifier = [30, 10] # Status with self.assertRaises(TypeError): primitive.Status = 19.4