def test_conversion_rq(self): """ Check conversion to a -RQ PDU produces the correct output """ primitive = C_ECHO() primitive.MessageID = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.1.1' dimse_msg = C_ECHO_RQ() 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] assert cs_pdv == c_echo_rq_cmd
def test_callback_send_c_echo(self): """Check callback for sending DIMSE C-ECHO messages.""" # C-ECHO-RQ primitive = C_ECHO() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' self.dimse.send_msg(primitive, 1) # C-ECHO-RSP primitive = C_ECHO() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 self.dimse.send_msg(primitive, 1)
def test_callback_receive_c_echo(self): """Check callback for receiving DIMSE C-ECHO messages.""" # C-ECHO-RQ primitive = C_ECHO() primitive.MessageID = 7 primitive.Priority = 0x02 msg = C_ECHO_RQ() msg.primitive_to_message(primitive) msg.context_id = 1 self.dimse.debug_receive_c_echo_rq(msg) # C-ECHO-RSP primitive = C_ECHO() primitive.MessageIDBeingRespondedTo = 4 primitive.Status = 0x0000 msg = C_ECHO_RSP() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_echo_rsp(msg)
def message_to_primitive(self): """Convert the DIMSEMessage class to a DIMSE primitive. Returns ------- DIMSE message primitive One of the DIMSE message primitives from pynetdicom.dimse_primitives generated from the current DIMSEMessage. """ # pylint: disable=too-many-branches cls_type_name = self.__class__.__name__ if 'C_ECHO' in cls_type_name: primitive = C_ECHO() elif 'C_STORE' in cls_type_name: primitive = C_STORE() elif 'C_FIND' in cls_type_name: primitive = C_FIND() elif 'C_GET' in cls_type_name: primitive = C_GET() elif 'C_MOVE' in cls_type_name: primitive = C_MOVE() elif 'C_CANCEL' in cls_type_name: primitive = C_CANCEL() elif 'N_EVENT' in cls_type_name: primitive = N_EVENT_REPORT() elif 'N_GET' in cls_type_name: primitive = N_GET() elif 'N_SET' in cls_type_name: primitive = N_SET() elif 'N_ACTION' in cls_type_name: primitive = N_ACTION() elif 'N_CREATE' in cls_type_name: primitive = N_CREATE() elif 'N_DELETE' in cls_type_name: primitive = N_DELETE() # Command Set # For each parameter in the primitive, set the appropriate value # from the Message's Command Set elements for elem in self.command_set: if hasattr(primitive, elem.keyword): setattr(primitive, elem.keyword, self.command_set.__getattr__(elem.keyword)) # Datasets # Set the primitive's DataSet/Identifier/etc attribute try: dataset_keyword = _DATASET_KEYWORDS[cls_type_name] setattr(primitive, dataset_keyword, self.data_set) except KeyError: pass # Set the presentation context ID the message was set under primitive._context_id = self.context_id return primitive
def send_pdu(pdv): """Dummy Send method to test DIMSEServiceProvider.Send""" pass @staticmethod def receive_pdu(): """Dummy Receive method to test DIMSEServiceProvider.Receive""" pass @staticmethod def peek_next_pdu(): return 0x01 REFERENCE_MSG = [ (C_ECHO(), ('C_ECHO_RQ', 'C_ECHO_RSP')), (C_STORE(), ('C_STORE_RQ', 'C_STORE_RSP')), (C_FIND(), ('C_FIND_RQ', 'C_FIND_RSP')), (C_GET(), ('C_GET_RQ', 'C_GET_RSP')), (C_MOVE(), ('C_MOVE_RQ', 'C_MOVE_RSP')), (C_CANCEL(), (None, 'C_CANCEL_RQ')), (N_EVENT_REPORT(), ('N_EVENT_REPORT_RQ', 'N_EVENT_REPORT_RSP')), (N_GET(), ('N_GET_RQ', 'N_GET_RSP')), (N_SET(), ('N_SET_RQ', 'N_SET_RSP')), (N_ACTION(), ('N_ACTION_RQ', 'N_ACTION_RSP')), (N_CREATE(), ('N_CREATE_RQ', 'N_CREATE_RSP')), (N_DELETE(), ('N_DELETE_RQ', 'N_DELETE_RSP')), ] class TestDIMSEProvider(object):
def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = C_ECHO() # 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 # Status with pytest.raises(TypeError): primitive.Status = 19.4
def send_pdu(pdv): """Dummy Send method to test DIMSEServiceProvider.Send""" pass @staticmethod def receive_pdu(): """Dummy Receive method to test DIMSEServiceProvider.Receive""" pass @staticmethod def peek_next_pdu(): return 0x01 REFERENCE_MSG = [ (C_ECHO(), ("C_ECHO_RQ", "C_ECHO_RSP")), (C_STORE(), ("C_STORE_RQ", "C_STORE_RSP")), (C_FIND(), ("C_FIND_RQ", "C_FIND_RSP")), (C_GET(), ("C_GET_RQ", "C_GET_RSP")), (C_MOVE(), ("C_MOVE_RQ", "C_MOVE_RSP")), (C_CANCEL(), (None, "C_CANCEL_RQ")), (N_EVENT_REPORT(), ("N_EVENT_REPORT_RQ", "N_EVENT_REPORT_RSP")), (N_GET(), ("N_GET_RQ", "N_GET_RSP")), (N_SET(), ("N_SET_RQ", "N_SET_RSP")), (N_ACTION(), ("N_ACTION_RQ", "N_ACTION_RSP")), (N_CREATE(), ("N_CREATE_RQ", "N_CREATE_RSP")), (N_DELETE(), ("N_DELETE_RQ", "N_DELETE_RSP")), ] class TestDIMSEProvider: