예제 #1
0
    def test_send_n_action(self):
        """Check sending DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        primitive = N_ACTION()
        primitive.MessageID = 1
        primitive.AffectedSOPClassUID = '1.1.1'

        def test_callback(msg):
            """Callback"""
            self.assertEqual(msg.__class__.__name__, 'N_ACTION_RQ')

        self.dimse.on_send_dimse_message = test_callback
        self.dimse.send_msg(primitive, 1)

        # N-ACTION-RSP
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000

        def test_callback(msg):
            """Callback"""
            self.assertEqual(msg.__class__.__name__, 'N_ACTION_RSP')

        self.dimse.on_send_dimse_message = test_callback
        self.dimse.send_msg(primitive, 1)
예제 #2
0
    def test_conversion_rsp(self):
        """ Check conversion to a -RSP PDU produces the correct output """
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 5
        primitive.AffectedSOPClassUID = '1.2.4.10'
        primitive.AffectedSOPInstanceUID = '1.2.4.5.7.8'
        primitive.Status = 0x0000
        primitive.ActionTypeID = 1

        ds = Dataset()
        ds.PatientID = 'Test1101'
        ds.PatientName = "Tube HeNe"

        primitive.ActionReply = BytesIO(encode(ds, True, True))

        dimse_msg = N_ACTION_RSP()
        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_action_rsp_cmd
        assert ds_pdv == n_action_rsp_ds
예제 #3
0
    def test_callback_send_n_action(self):
        """Check callback for sending DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        primitive = N_ACTION()
        primitive.MessageID = 1
        primitive.RequestedSOPClassUID = '1.1.1'
        primitive.RequestedSOPInstanceUID = '1.1.1.2'
        primitive.ActionTypeID = 5
        self.dimse.send_msg(primitive, 1)

        # User defined
        primitive.ActionInformation = BytesIO(b'\x00\x01')
        self.dimse.send_msg(primitive, 1)

        # N-ACTION-RSP
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000
        self.dimse.send_msg(primitive, 1)

        # User defined
        primitive.ActionTypeID = 5
        primitive.AffectedSOPClassUID = '1.2'
        primitive.AffectedSOPInstanceUID = '1.2.3'
        primitive.ActionReply = BytesIO(b'\x00\x01')
        self.dimse.send_msg(primitive, 1)
예제 #4
0
    def test_callback_send_n_action(self):
        """Check callback for sending DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        primitive = N_ACTION()
        primitive.MessageID = 1
        primitive.AffectedSOPClassUID = '1.1.1'
        self.dimse.send_msg(primitive, 1)

        # N-ACTION-RSP
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000
        self.dimse.send_msg(primitive, 1)
예제 #5
0
    def test_callback_receive_n_action(self):
        """Check callback for receiving DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        primitive = N_ACTION()
        primitive.MessageID = 1
        primitive.RequestedSOPClassUID = '1.1.1'
        primitive.RequestedSOPInstanceUID = '1.1.1.1'
        primitive.ActionTypeID = 2
        msg = N_ACTION_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rq(msg)

        # User defined
        primitive.ActionInformation = BytesIO(n_action_rq_ds)
        msg = N_ACTION_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rq(msg)

        # N-ACTION-RSP
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000
        msg = N_ACTION_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rsp(msg)

        # User defined
        primitive.AffectedSOPClassUID = '1.1.1'
        primitive.AffectedSOPInstanceUID = '1.1.1.1'
        primitive.ActionTypeID = 2
        primitive.ActionReply = BytesIO(n_action_rsp_ds)
        msg = N_ACTION_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rsp(msg)
예제 #6
0
    def test_exceptions(self):
        """ Check incorrect types/values for properties raise exceptions """
        primitive = N_ACTION()

        # 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'

        # RequestedSOPClassUID
        with pytest.raises(TypeError):
            primitive.RequestedSOPClassUID = 45.2

        with pytest.raises(TypeError):
            primitive.RequestedSOPClassUID = 100

        with pytest.raises(ValueError):
            primitive.RequestedSOPClassUID = 'abc'

        # RequestedSOPInstanceUID
        with pytest.raises(TypeError):
            primitive.RequestedSOPInstanceUID = 45.2

        with pytest.raises(TypeError):
            primitive.RequestedSOPInstanceUID = 100

        with pytest.raises(ValueError):
            primitive.RequestedSOPInstanceUID = 'abc'

        # ActionInformation
        msg = r"'ActionInformation' parameter must be a BytesIO object"
        with pytest.raises(TypeError, match=msg):
            primitive.ActionInformation = 'halp'

        with pytest.raises(TypeError):
            primitive.ActionInformation = 1.111

        with pytest.raises(TypeError):
            primitive.ActionInformation = 50

        with pytest.raises(TypeError):
            primitive.ActionInformation = [30, 10]

        # ActionReply
        msg = r"'ActionReply' parameter must be a BytesIO object"
        with pytest.raises(TypeError, match=msg):
            primitive.ActionReply = 'halp'

        with pytest.raises(TypeError):
            primitive.ActionReply = 1.111

        with pytest.raises(TypeError):
            primitive.ActionReply = 50

        with pytest.raises(TypeError):
            primitive.ActionReply = [30, 10]

        # ActionTypeID
        with pytest.raises(TypeError):
            primitive.ActionTypeID = 19.4

        # Status
        with pytest.raises(TypeError):
            primitive.Status = 19.4
예제 #7
0
    def test_assignment(self):
        """ Check assignment works correctly """
        primitive = N_ACTION()

        # Action Type ID
        primitive.ActionTypeID = 0x0000
        assert primitive.ActionTypeID == 0x0000

        # 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)

        # ActionInformation
        ds = Dataset()
        ds.PatientID = '1234567'
        primitive.ActionInformation = BytesIO(encode(ds, True, True))
        ds = decode(primitive.ActionInformation, True, True)
        assert ds.PatientID == '1234567'

        # ActionReply
        ds = Dataset()
        ds.PatientID = '123456'
        primitive.ActionReply = BytesIO(encode(ds, True, True))
        ds = decode(primitive.ActionReply, True, True)
        assert ds.PatientID == '123456'

        # MessageID
        primitive.MessageID = 11
        assert 11 == primitive.MessageID

        # MessageIDBeingRespondedTo
        primitive.MessageIDBeingRespondedTo = 13
        assert 13 == primitive.MessageIDBeingRespondedTo

        # RequestedSOPClassUID
        primitive.RequestedSOPClassUID = '1.1.1'
        assert primitive.RequestedSOPClassUID == UID('1.1.1')
        assert isinstance(primitive.RequestedSOPClassUID, UID)
        primitive.RequestedSOPClassUID = UID('1.1.2')
        assert primitive.RequestedSOPClassUID == UID('1.1.2')
        assert isinstance(primitive.RequestedSOPClassUID, UID)
        primitive.RequestedSOPClassUID = b'1.1.3'
        assert primitive.RequestedSOPClassUID == UID('1.1.3')
        assert isinstance(primitive.RequestedSOPClassUID, UID)

        # RequestedSOPInstanceUID
        primitive.RequestedSOPInstanceUID = b'1.2.1'
        assert primitive.RequestedSOPInstanceUID == UID('1.2.1')
        assert isinstance(primitive.RequestedSOPInstanceUID, UID)
        primitive.RequestedSOPInstanceUID = UID('1.2.2')
        assert primitive.RequestedSOPInstanceUID == UID('1.2.2')
        assert isinstance(primitive.RequestedSOPInstanceUID, UID)
        primitive.RequestedSOPInstanceUID = '1.2.3'
        assert primitive.RequestedSOPInstanceUID == UID('1.2.3')
        assert isinstance(primitive.RequestedSOPInstanceUID, UID)

        # Status
        primitive.Status = 0x0000
        assert primitive.Status == 0x0000