Exemple #1
0
    def test_decode_properties(self):
        """ Check decoding the stream produces the correct properties """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        context = pdu.presentation_context[0]

        # Check ID property
        context_id = context.ID
        self.assertTrue(isinstance(context_id, int))
        self.assertEqual(context_id, 1)

        # Check Abstract Syntax property
        context = pdu.presentation_context[0]
        self.assertTrue(isinstance(context.abstract_syntax, UID))
        self.assertEqual(context.abstract_syntax, UID('1.2.840.10008.1.1'))

        # Check TransferSyntax property is a list
        self.assertTrue(isinstance(context.transfer_syntax, list))

        # Check TransferSyntax list contains transfer syntax type UIDs
        for syntax in pdu.presentation_context[0].transfer_syntax:
            self.assertTrue(isinstance(syntax, UID))
            self.assertTrue(syntax.is_transfer_syntax)

        # Check first transfer syntax is little endian implicit
        syntax = pdu.presentation_context[0].transfer_syntax[0]
        self.assertEqual(syntax, UID('1.2.840.10008.1.2'))
    def test_encode(self):
        """Check encoding produces the correct output."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)
        out = pdu.encode()

        assert out == a_associate_rq
Exemple #3
0
    def test_stream_encode(self):
        """ Check encoding an assoc_rq produces the correct output """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)
        s = pdu.Encode()

        self.assertEqual(s, a_associate_rq)
Exemple #4
0
    def test_new_encode(self):
        """ Check encoding using new generic method """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)
        s = pdu.encode()

        self.assertEqual(s, a_associate_rq)
Exemple #5
0
    def test_decode_properties(self):
        """ Check decoding the assoc_rq stream produces the correct properties """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        # Check AE titles
        self.assertEqual(pdu.calling_ae_title.decode('utf-8'),
                         'ECHOSCU         ')
        self.assertEqual(pdu.called_ae_title.decode('utf-8'),
                         'ANY-SCP         ')
        self.assertTrue(isinstance(pdu.calling_ae_title, bytes))
        self.assertTrue(isinstance(pdu.called_ae_title, bytes))

        # Check application_context_name property
        app_name = pdu.application_context_name
        self.assertTrue(isinstance(app_name, UID))
        self.assertEqual(app_name, '1.2.840.10008.3.1.1.1')

        # Check presentation_context property
        contexts = pdu.presentation_context
        self.assertTrue(isinstance(contexts, list))
        for context in contexts:
            self.assertTrue(isinstance(context, PresentationContextItemRQ))

        # Check user_information property
        user_info = pdu.user_information
        self.assertTrue(isinstance(user_info, UserInformationItem))
Exemple #6
0
    def test_generic_encode(self):
        """ Check using the new pdu.encode produces the correct output """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)
        s = pdu.Encode()
        t = pdu.encode()

        self.assertEqual(s, t)
    def test_to_primitive(self):
        """Check converting PDU to primitive"""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        pr = pdu.to_primitive()

        assert pr.application_context_name == UID('1.2.840.10008.3.1.1.1')
        assert pr.calling_ae_title == b'ECHOSCU         '
        assert pr.called_ae_title == b'ANY-SCP         '

        # Test User Information
        for item in pr.user_information:
            # Maximum PDU Length (required)
            if isinstance(item, MaximumLengthNegotiation):
                assert item.maximum_length_received == 16382
                assert isinstance(item.maximum_length_received, int)

            # Implementation Class UID (required)
            elif isinstance(item, ImplementationClassUIDNotification):
                assert item.implementation_class_uid == UID(
                    '1.2.826.0.1.3680043.9.3811.0.9.0')
                assert isinstance(item.implementation_class_uid, UID)

            # Implementation Version Name (optional)
            elif isinstance(item, ImplementationVersionNameNotification):
                assert item.implementation_version_name == b'PYNETDICOM_090'
                assert isinstance(item.implementation_version_name, bytes)

        # Test Presentation Contexts
        for context in pr.presentation_context_definition_list:
            assert context.context_id == 1
            assert context.abstract_syntax == UID('1.2.840.10008.1.1')
            for syntax in context.transfer_syntax:
                assert syntax == UID('1.2.840.10008.1.2')

        assert isinstance(pr.application_context_name, UID)
        assert isinstance(pr.calling_ae_title, bytes)
        assert isinstance(pr.called_ae_title, bytes)
        assert isinstance(pr.user_information, list)
        assert isinstance(pr.presentation_context_definition_list, list)

        # Not used by A-ASSOCIATE-RQ or fixed value
        assert pr.mode == "normal"
        assert pr.responding_ae_title == pr.called_ae_title
        assert pr.result is None
        assert pr.result_source is None
        assert pr.diagnostic is None
        assert pr.calling_presentation_address is None
        assert pr.called_presentation_address is None
        assert pr.responding_presentation_address == (
            pr.called_presentation_address)
        assert pr.presentation_context_definition_results_list == []
        assert pr.presentation_requirements == "Presentation Kernel"
        assert pr.session_requirements == ""
    def test_inequality(self):
        """Test the inequality operator"""
        aa = A_ASSOCIATE_RQ()
        bb = A_ASSOCIATE_RQ()
        assert not aa != bb
        assert aa != 'TEST'

        aa.decode(a_associate_rq)
        assert aa != bb

        assert not aa != aa
    def test_from_primitive(self):
        """Check converting primitive to PDU."""
        orig_pdu = A_ASSOCIATE_RQ()
        orig_pdu.decode(a_associate_rq)
        primitive = orig_pdu.to_primitive()

        new_pdu = A_ASSOCIATE_RQ()
        new_pdu.from_primitive(primitive)

        assert new_pdu == orig_pdu
        assert new_pdu.encode() == a_associate_rq
    def test_decode(self):
        """Check decoding assoc_rq produces the correct application context."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        app_context = pdu.variable_items[0]

        assert app_context.item_type == 0x10
        assert app_context.item_length == 21
        assert len(app_context) == 25
        assert app_context.application_context_name == '1.2.840.10008.3.1.1.1'
        assert isinstance(app_context.application_context_name, UID)
    def test_property_setters(self):
        """Check the property setters are working correctly."""
        pdu = A_ASSOCIATE_RQ()

        # pdu.called_ae_title
        assert pdu.called_ae_title == b'Default         '
        pdu.called_ae_title = 'TEST_SCP'
        assert pdu.called_ae_title == b'TEST_SCP        '

        # pdu.calling_ae_title
        assert pdu.calling_ae_title == b'Default         '
        pdu.calling_ae_title = 'TEST_SCP2'
        assert pdu.calling_ae_title == b'TEST_SCP2       '
    def test_decode(self):
        """Check decoding assoc_rq produces the correct presentation context."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        # Check PresentationContextItemRQ attributes
        context = pdu.variable_items[1]
        assert context.item_type == 0x20
        assert context.item_length == 46
        assert len(context) == 50
        assert context.presentation_context_id == 0x001

        assert len(context.abstract_transfer_syntax_sub_items) == 2
    def test_decode(self):
        """Check decoding assoc_rq produces the correct abstract syntax."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        context = pdu.presentation_context[0]

        abstract_syntax = context.abstract_transfer_syntax_sub_items[0]

        assert abstract_syntax.item_type == 0x30
        assert abstract_syntax.item_length == 17
        assert len(abstract_syntax) == 21
        assert abstract_syntax.abstract_syntax_name == UID('1.2.840.10008.1.1')
        assert isinstance(abstract_syntax.abstract_syntax_name, UID)
Exemple #14
0
    def test_stream_decode_values_types(self):
        """ Check decoding an assoc_rq produces the correct presentation context """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        # Check PresentationContextItemRQ attributes
        presentation_context = pdu.variable_items[1]
        self.assertEqual(presentation_context.item_type, 0x20)
        self.assertEqual(presentation_context.presentation_context_id, 0x001)
        self.assertEqual(presentation_context.item_length, 46)
        self.assertTrue(isinstance(presentation_context.item_type, int))
        self.assertTrue(
            isinstance(presentation_context.presentation_context_id, int))
        self.assertTrue(isinstance(presentation_context.item_length, int))
    def test_decode_properties(self):
        """Check decoding produces the correct property values."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        user_info = pdu.variable_items[2]
        assert user_info.async_ops_window is None
        assert user_info.common_ext_neg == []
        assert user_info.ext_neg == []
        assert user_info.implementation_class_uid == (
            '1.2.826.0.1.3680043.9.3811.0.9.0')
        assert user_info.implementation_version_name == b'PYNETDICOM_090'
        assert user_info.maximum_length == 16382
        assert user_info.role_selection == {}
        assert user_info.user_identity is None
    def test_decode_properties(self):
        """Check decoding produces the correct property values."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_ac)

        user_info = pdu.variable_items[2]
        assert user_info.async_ops_window is None
        assert user_info.common_ext_neg == []
        assert user_info.ext_neg == []
        assert user_info.implementation_class_uid == (
            '1.2.276.0.7230010.3.0.3.6.0')
        assert user_info.implementation_version_name == b'OFFIS_DCMTK_360'
        assert user_info.maximum_length == 16384
        assert user_info.role_selection == {}
        assert user_info.user_identity is None
Exemple #17
0
    def test_decode_value_type(self):
        """ Check decoding an assoc_rq produces the correct abstract syntax """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        context = pdu.presentation_context[0]

        abstract_syntax = context.abstract_transfer_syntax_sub_items[0]

        self.assertEqual(abstract_syntax.item_type, 0x30)
        self.assertEqual(abstract_syntax.item_length, 17)
        self.assertEqual(abstract_syntax.abstract_syntax_name,
                         UID('1.2.840.10008.1.1'))
        self.assertTrue(isinstance(abstract_syntax.item_type, int))
        self.assertTrue(isinstance(abstract_syntax.item_length, int))
        self.assertTrue(isinstance(abstract_syntax.abstract_syntax_name, UID))
Exemple #18
0
def AE_2(dul):
    """Association establishment action AE-2.

    On receiving connection confirmation, send A-ASSOCIATE-RQ to the peer AE
    This send a byte stream with the format given by Table 9-11

    State-event triggers: Sta4 + Evt2

    Callbacks: ApplicationEntity.on_send_associate_rq(PDU)

    .. [1] DICOM Standard 2015b, PS3.8, Table 9-7, "Associate Establishment
        Related Actions"

    Parameters
    ----------
    dul : pynetdicom3.dul.DULServiceProvider
        The DICOM Upper Layer Service instance for the local AE

    Returns
    -------
    str
        'Sta5', the next state of the state machine.
    """
    # Send A-ASSOCIATE-RQ PDU
    dul.pdu = A_ASSOCIATE_RQ()
    dul.pdu.FromParams(dul.primitive)

    # Callback
    dul.assoc.acse.debug_send_associate_rq(dul.pdu)

    bytestream = dul.pdu.Encode()
    dul.scu_socket.send(bytestream)

    return 'Sta5'
 def test_string_output(self):
     """Check the string output works"""
     pdu = A_ASSOCIATE_RQ()
     pdu.decode(a_associate_rq)
     assert "Verification SOP Class" in pdu.__str__()
     assert "Implicit VR Little Endian" in pdu.__str__()
     assert "3680043.9.3811.0.9.0" in pdu.__str__()
    def test_decode(self):
        """ Check decoding an assoc_rq produces the correct transfer syntax """
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        context = pdu.presentation_context[0]
        transfer_syntaxes = context.transfer_syntax

        # Check TransferSyntax property is a list
        assert isinstance(transfer_syntaxes, list)

        # Check TransferSyntax list contains transfer syntax type UIDs
        for syntax in transfer_syntaxes:
            assert isinstance(syntax, UID)

        # Check first transfer syntax is little endian implicit
        syntax = transfer_syntaxes[0]
        assert syntax, UID('1.2.840.10008.1.2')
Exemple #21
0
    def test_stream_decode_values_types(self):
        """ Check decoding an assoc_rq produces the correct application context """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        app_context = pdu.variable_items[0]

        self.assertEqual(app_context.item_type, 0x10)
        self.assertEqual(app_context.item_length, 21)
        self.assertEqual(app_context.application_context_name,
                         '1.2.840.10008.3.1.1.1')
        self.assertTrue(isinstance(app_context.item_type, int))
        self.assertTrue(isinstance(app_context.item_length, int))
        self.assertTrue(isinstance(app_context.application_context_name, UID))

        self.assertEqual(app_context.application_context_name,
                         '1.2.840.10008.3.1.1.1')
        self.assertTrue(isinstance(app_context.application_context_name, UID))
Exemple #22
0
    def test_update_data(self):
        """ Check that updating the PDU data works correctly """
        orig_pdu = A_ASSOCIATE_RQ()
        orig_pdu.Decode(a_associate_rq)
        orig_pdu.user_information.user_data = [
            orig_pdu.user_information.user_data[1]
        ]
        orig_pdu.get_length()

        primitive = orig_pdu.ToParams()

        new_pdu = A_ASSOCIATE_RQ()
        new_pdu.FromParams(primitive)

        self.assertEqual(new_pdu, orig_pdu)
    def test_decode_properties(self):
        """Check decoding produces the correct property values."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        # Check application_context_name property
        app_name = pdu.application_context_name
        assert isinstance(app_name, UID)
        assert app_name == '1.2.840.10008.3.1.1.1'

        # Check presentation_context property
        contexts = pdu.presentation_context
        assert isinstance(contexts, list)
        for context in contexts:
            assert isinstance(context, PresentationContextItemRQ)

        # Check user_information property
        user_info = pdu.user_information
        assert isinstance(user_info, UserInformationItem)
Exemple #24
0
    def test_stream_decode_values_types(self):
        """ Check decoding the assoc_rq stream produces the correct objects """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        self.assertEqual(pdu.pdu_type, 0x01)
        self.assertEqual(pdu.pdu_length, 209)
        self.assertEqual(pdu.protocol_version, 0x0001)
        self.assertTrue(isinstance(pdu.pdu_type, int))
        self.assertTrue(isinstance(pdu.pdu_length, int))
        self.assertTrue(isinstance(pdu.protocol_version, int))

        # Check VariableItems
        #   The actual items will be tested separately
        self.assertTrue(
            isinstance(pdu.variable_items[0], ApplicationContextItem))
        self.assertTrue(
            isinstance(pdu.variable_items[1], PresentationContextItemRQ))
        self.assertTrue(isinstance(pdu.variable_items[2], UserInformationItem))
Exemple #25
0
    def test_decode_value_type(self):
        """ Check decoding an assoc_rq produces the correct user information """
        pdu = A_ASSOCIATE_RQ()
        pdu.Decode(a_associate_rq)

        user_info = pdu.variable_items[2]

        self.assertEqual(user_info.item_type, 0x50)
        self.assertEqual(user_info.item_length, 62)
        self.assertTrue(isinstance(user_info.item_type, int))
        self.assertTrue(isinstance(user_info.item_length, int))
        self.assertTrue(isinstance(user_info.user_data, list))

        # Test user items
        for item in user_info.user_data:
            # Maximum PDU Length (required)
            if isinstance(item, MaximumLengthSubItem):
                self.assertEqual(item.maximum_length_received, 16382)
                self.assertEqual(user_info.maximum_length, 16382)
                self.assertTrue(isinstance(item.maximum_length_received, int))
                self.assertTrue(isinstance(user_info.maximum_length, int))

            # Implementation Class UID (required)
            elif isinstance(item, ImplementationClassUIDSubItem):
                self.assertEqual(item.item_type, 0x52)
                self.assertEqual(item.item_length, 32)
                self.assertEqual(item.implementation_class_uid,
                                 UID('1.2.826.0.1.3680043.9.3811.0.9.0'))
                self.assertTrue(isinstance(item.item_type, int))
                self.assertTrue(isinstance(item.item_length, int))
                self.assertTrue(isinstance(item.implementation_class_uid, UID))

            # Implementation Version Name (optional)
            elif isinstance(item, ImplementationVersionNameSubItem):
                self.assertEqual(item.item_type, 0x55)
                self.assertEqual(item.item_length, 14)
                self.assertEqual(item.implementation_version_name,
                                 b'PYNETDICOM_090')
                self.assertTrue(isinstance(item.item_type, int))
                self.assertTrue(isinstance(item.item_length, int))
                self.assertTrue(
                    isinstance(item.implementation_version_name, bytes))
    def test_equality(self):
        """Test the equality operator"""
        aa = A_ASSOCIATE_RQ()
        bb = A_ASSOCIATE_RQ()
        assert aa == bb
        assert not aa == 'TEST'

        aa.decode(a_associate_rq)
        assert not aa == bb

        bb.decode(a_associate_rq)
        assert aa == bb

        aa.calling_ae_title = b'TEST_AE_TITLE_00'
        assert not aa == bb

        assert aa == aa
    def test_decode(self):
        """Check decoding assoc_rq produces the correct attribute values."""
        pdu = A_ASSOCIATE_RQ()
        pdu.decode(a_associate_rq)

        assert pdu.protocol_version == 0x01
        assert pdu.calling_ae_title == b'ECHOSCU         '
        assert pdu.called_ae_title == b'ANY-SCP         '
        assert pdu.pdu_type == 0x01
        assert pdu.pdu_length == 209
        assert len(pdu) == 215

        assert len(pdu.presentation_context) == 1
        assert len(pdu.user_information.user_data) == 3

        # Check VariableItems
        #   The actual items will be tested separately
        assert len(pdu.variable_items) == 3
        assert isinstance(pdu.variable_items[0], ApplicationContextItem)
        assert isinstance(pdu.variable_items[1], PresentationContextItemRQ)
        assert isinstance(pdu.variable_items[2], UserInformationItem)
    def test_init(self):
        pdu = A_ASSOCIATE_RQ()
        assert pdu.protocol_version == 0x01
        assert pdu.calling_ae_title == b'Default         '
        assert pdu.called_ae_title == b'Default         '
        assert pdu.variable_items == []
        assert pdu.pdu_type == 0x01
        assert pdu.pdu_length == 68
        assert len(pdu) == 74

        assert pdu.application_context_name is None
        assert pdu.presentation_context == []
        assert pdu.user_information is None
Exemple #29
0
    def test_from_primitive(self):
        """ Check converting PDU to primitive """
        orig_pdu = A_ASSOCIATE_RQ()
        orig_pdu.Decode(a_associate_rq)

        primitive = orig_pdu.ToParams()

        new_pdu = A_ASSOCIATE_RQ()
        new_pdu.FromParams(primitive)

        self.assertEqual(new_pdu, orig_pdu)
    def test_conversion(self):
        """ Check conversion to a PDU produces the correct output """
        assoc = A_ASSOCIATE()
        assoc.application_context_name = "1.2.840.10008.3.1.1.1"
        assoc.calling_ae_title = 'ECHOSCU'
        assoc.called_ae_title = 'ANY-SCP'
        assoc.maximum_length_received = 16382
        assoc.implementation_class_uid = '1.2.826.0.1.3680043.9.3811.0.9.0'

        imp_ver_name = ImplementationVersionNameNotification()
        imp_ver_name.implementation_version_name = 'PYNETDICOM_090'
        assoc.user_information.append(imp_ver_name)

        pc = PresentationContext()
        pc.context_id = 1
        pc.abstract_syntax = '1.2.840.10008.1.1'
        pc.transfer_syntax = ['1.2.840.10008.1.2']
        assoc.presentation_context_definition_list = [pc]

        pdu = A_ASSOCIATE_RQ()
        pdu.from_primitive(assoc)
        data = pdu.encode()

        ref = b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43" \
              b"\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43" \
              b"\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00" \
              b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
              b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e" \
              b"\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e" \
              b"\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31" \
              b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31" \
              b"\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30" \
              b"\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f" \
              b"\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31" \
              b"\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e" \
              b"\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49" \
              b"\x43\x4f\x4d\x5f\x30\x39\x30"

        assert data == ref