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