예제 #1
0
    def test_conversion_rsp(self):
        """ Check conversion to a -RSP PDU produces the correct output """
        primitive = C_MOVE()
        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_MOVE_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_move_rsp_cmd
        assert ds_pdv == c_move_rsp_ds
예제 #2
0
    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)
예제 #3
0
    def test_send_c_move_rsp_no_affected_sop(self):
        """Test the handler for C-MOVE rsp with no Affected SOP Class UID."""
        self.ae = ae = AE()
        ae.add_supported_context('1.2.840.10008.1.1')
        ae.add_requested_context('1.2.840.10008.1.1')
        scp = ae.start_server(('', 11112), block=False)

        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established

        msg = C_MOVE()
        msg.MessageIDBeingRespondedTo = 1
        msg.Status = 0x0000
        msg.NumberOfRemainingSuboperations = 0
        msg.NumberOfCompletedSuboperations = 0
        msg.NumberOfFailedSuboperations = 0
        msg.NumberOfWarningSuboperations = 0

        assoc.dimse.send_msg(msg, 1)

        assoc.release()
        scp.shutdown()
예제 #4
0
    def test_exceptions(self):
        """ Check incorrect types/values for properties raise exceptions """
        primitive = C_MOVE()

        # 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

        # NumberOfRemainingSuboperations
        with pytest.raises(TypeError):
            primitive.NumberOfRemainingSuboperations = 'halp'
        with pytest.raises(TypeError):
            primitive.NumberOfRemainingSuboperations = 1.111
        with pytest.raises(ValueError):
            primitive.NumberOfRemainingSuboperations = -1

        # NumberOfCompletedSuboperations
        with pytest.raises(TypeError):
            primitive.NumberOfCompletedSuboperations = 'halp'
        with pytest.raises(TypeError):
            primitive.NumberOfCompletedSuboperations = 1.111
        with pytest.raises(ValueError):
            primitive.NumberOfCompletedSuboperations = -1

        # NumberOfFailedSuboperations
        with pytest.raises(TypeError):
            primitive.NumberOfFailedSuboperations = 'halp'
        with pytest.raises(TypeError):
            primitive.NumberOfFailedSuboperations = 1.111
        with pytest.raises(ValueError):
            primitive.NumberOfFailedSuboperations = -1

        # NumberOfWarningSuboperations
        with pytest.raises(TypeError):
            primitive.NumberOfWarningSuboperations = 'halp'
        with pytest.raises(TypeError):
            primitive.NumberOfWarningSuboperations = 1.111
        with pytest.raises(ValueError):
            primitive.NumberOfWarningSuboperations = -1

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

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

        # Priority
        with pytest.raises(ValueError):
            primitive.Priority = 45.2

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

        with pytest.raises(ValueError):
            primitive.Priority = -1

        with pytest.raises(ValueError):
            primitive.Priority = 3

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

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

        with pytest.raises(ValueError):
            primitive.MoveDestination = ''

        with pytest.raises(ValueError):
            primitive.MoveDestination = '    '

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

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

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

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

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