Beispiel #1
0
    def test_assignment(self):
        """ Check assignment works correctly """
        primitive = C_ECHO()

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

        # Known status
        primitive.Status = 0x0000
        self.assertEqual(primitive.Status, 0x0000)
        # Unknown status
        primitive.Status = 0x9999
        self.assertEqual(primitive.Status, 0x9999)

        primitive.Status = 0xEE01
        self.assertEqual(primitive.Status, 0xEE01)
Beispiel #2
0
    def test_assignment(self):
        """ Check assignment works correctly """
        primitive = C_ECHO()

        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)

        # Known status
        primitive.Status = 0x0000
        assert primitive.Status == 0x0000
        # Unknown status
        primitive.Status = 0x9999
        assert primitive.Status == 0x9999

        primitive.Status = 0xEE01
        assert primitive.Status == 0xEE01
Beispiel #3
0
    def test_send_c_echo(self):
        """Check sending DIMSE C-ECHO messages."""
        # C-ECHO-RQ
        primitive = C_ECHO()
        primitive.MessageID = 1
        primitive.AffectedSOPClassUID = '1.1.1'

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

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

        # C-ECHO-RSP
        primitive = C_ECHO()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000

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

        self.dimse.on_send_dimse_message = test_callback
        self.dimse.send_msg(primitive, 1)
Beispiel #4
0
    def test_exceptions(self):
        """ Check incorrect types/values for properties raise exceptions """
        primitive = C_ECHO()

        # 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

        # AffectedSOPClassUID
        with self.assertRaises(TypeError):
            primitive.AffectedSOPClassUID = 45.2
        with self.assertRaises(TypeError):
            primitive.AffectedSOPClassUID = 100
        with self.assertRaises(ValueError):
            primitive.AffectedSOPClassUID = 'abc'

        # Status
        with self.assertRaises(TypeError):
            primitive.Status = 19.4
Beispiel #5
0
 def test_is_valid_resposne(self):
     """Test C_ECHO.is_valid_response."""
     primitive = C_ECHO()
     assert not primitive.is_valid_response
     primitive.MessageIDBeingRespondedTo = 1
     assert not primitive.is_valid_response
     primitive.Status = 0x0000
     assert primitive.is_valid_response
Beispiel #6
0
    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)
Beispiel #7
0
    def test_conversion_rsp(self):
        """ Check conversion to a -RQ PDU produces the correct output """
        primitive = C_ECHO()
        primitive.MessageIDBeingRespondedTo = 8
        primitive.AffectedSOPClassUID = '1.2.840.10008.1.1'
        primitive.Status = 0x0000

        dimse_msg = C_ECHO_RSP()
        dimse_msg.primitive_to_message(primitive)

        pdvs = dimse_msg.encode_msg(1, 16382)
        cs_pdv = pdvs[0].presentation_data_value_list[0][1]
        self.assertEqual(cs_pdv, c_echo_rsp_cmd)
Beispiel #8
0
    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.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)