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 = [] for fragment in dimse_msg.encode_msg(1, 16382): pdvs.append(fragment) cs_pdv = pdvs[0].presentation_data_value_list[0][1] ds_pdv = pdvs[1].presentation_data_value_list[0][1] assert cs_pdv == c_get_rsp_cmd assert ds_pdv == c_get_rsp_ds
def test_callback_receive_c_move(self): """Check callback for receiving DIMSE C-MOVE messages.""" # C-MOVE-RQ msg = C_MOVE_RQ() self.dimse.debug_receive_c_move_rq(msg) # C-MOVE-RSP primitive = C_MOVE() 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_MOVE_RSP() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_move_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_move_rsp(msg) # C-CANCEL-MOVE-RQ self.dimse.debug_receive_c_cancel_rq(msg)
def test_message_to_primitive_c_get(self): """Test converting C_GET_RQ to C_GET primitive.""" msg = C_GET_RQ() for data in [c_get_rq_cmd, c_get_rq_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_GET) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Priority == 2 assert primitive.MessageID == 7 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.PatientID == "*" msg = C_GET_RSP() for data in [c_get_rsp_cmd, c_get_rsp_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_GET) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Status == 65280 assert primitive.MessageIDBeingRespondedTo == 5 assert primitive.NumberOfRemainingSuboperations == 3 assert primitive.NumberOfCompletedSuboperations == 1 assert primitive.NumberOfFailedSuboperations == 2 assert primitive.NumberOfWarningSuboperations == 4 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.PatientID == "*"
def test_message_to_primitive_c_find(self): """Test converting C_FIND_RQ to C_FIND primitive.""" msg = C_FIND_RQ() for data in [c_find_rq_cmd, c_find_rq_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_FIND) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Priority == 2 assert primitive.MessageID == 7 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.PatientID == "*" msg = C_GET_RSP() for data in [c_find_rsp_cmd, c_find_rsp_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_FIND) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Status == 65280 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.RetrieveAETitle == "FINDSCP" assert ds.PatientName == "ANON^A^B^C^D"