def test_recv_assoc_ac_minimal(self, caplog): """Test minimal ACSE.debug_receive_associate_ac.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) self.acse.debug_receive_associate_ac(pdu) messages = [ "Their Implementation Class UID: 1.2.826.0.1.3680043.8.498" ".10207287587329888519122978685894984263", "Their Implementation Version Name: unknown", "Application Context Name: 1.2.840.10008.3.1.1.1", "Calling Application Name: ABCDEFGHIJKLMNOP", "Called Application Name: 1234567890123456", "Their Max PDU Receive Size: 0", "Presentation Contexts:", "Context ID: 1 (Accepted)", "Accepted Transfer Syntax: =JPEG Baseline (Process 1)", "Context ID: 3 (User Rejection)", "Context ID: 5 (Provider Rejection)", "Context ID: 7 (Abstract Syntax Not Supported)", "Context ID: 9 (Transfer Syntax Not Supported)", "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text
def test_send_assoc_ac_async(self, caplog): """Test ACSE.debug_send_associate_ac with async ops.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.ae = ae = AE() ae.add_supported_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) scp = ae.start_server(('', 11112), block=False) assoc = ae.associate('localhost', 11112) self.add_async_ops(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) evt.trigger(assoc, evt.EVT_PDU_SENT, {'pdu': pdu}) messages = [ "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation:", "Maximum Invoked Operations: 2", "Maximum Performed Operations: 3", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text assoc.release() scp.shutdown()
def test_send_assoc_ac_role(self, caplog): """Test ACSE.debug_send_associate_ac with role selection.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.ae = ae = AE() ae.add_supported_context('1.2.840.10008.1.2', scu_role=True, scp_role=True) ae.add_supported_context('1.2.840.10008.1.3', scu_role=True, scp_role=True) ae.add_supported_context('1.2.840.10008.1.4', scu_role=True, scp_role=True) ae.add_requested_context('1.2.840.10008.1.2') ae.add_requested_context('1.2.840.10008.1.3') ae.add_requested_context('1.2.840.10008.1.4') ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) scp = ae.start_server(('', 11112), block=False) ext_neg = [] ext_neg.append(build_role('1.2.840.10008.1.2', scu_role=True)) ext_neg.append(build_role('1.2.840.10008.1.3', scp_role=True)) ext_neg.append( build_role('1.2.840.10008.1.4', scu_role=True, scp_role=True)) assoc = ae.associate('localhost', 11112, ext_neg=ext_neg) self.add_scp_scu_role(self.associate_ac) contexts = self.associate_ac.presentation_context_definition_results_list for ii, cx in enumerate(contexts): cx.context_id = ii * 2 + 1 cx.result = 0 pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) evt.trigger(assoc, evt.EVT_PDU_SENT, {'pdu': pdu}) messages = [ "Abstract Syntax: =Implicit VR Little Endian", "SCP/SCU Role: SCU", "Abstract Syntax: =1.2.840.10008.1.3", "SCP/SCU Role: SCP", "Abstract Syntax: =1.2.840.10008.1.4", "SCP/SCU Role: SCP/SCU", "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text assoc.release() scp.shutdown()
def AE_7(dul): """Association establishment action AE-7. On receiving association request acceptance, issue A-ASSOCIATE-AC State-event triggers: Sta3 + Evt7 References ---------- 1. DICOM Standard 2015b, PS3.8, Table 9-7, "Associate Establishment Related Actions" Parameters ---------- dul : pynetdicom.dul.DULServiceProvider The DICOM Upper Layer Service instance for the local AE Returns ------- str Sta6, the next state of the state machine """ # Send A-ASSOCIATE-AC PDU dul.pdu = A_ASSOCIATE_AC() dul.pdu.from_primitive(dul.primitive) # Callback dul.assoc.acse.debug_send_associate_ac(dul.pdu) bytestream = dul.pdu.encode() dul.socket.send(bytestream) return 'Sta6'
def AE_7(dul): """Association establishment action AE-7. On receiving association request acceptance, issue A-ASSOCIATE-AC State-event triggers: Sta3 + Evt7 Parameters ---------- dul : dul.DULServiceProvider The DICOM Upper Layer Service instance for the local AE Returns ------- str ``'Sta6'``, the next state of the state machine """ # Send A-ASSOCIATE-AC PDU dul.pdu = A_ASSOCIATE_AC() dul.pdu.from_primitive(dul.primitive) dul.socket.send(dul.pdu.encode()) evt.trigger(dul.assoc, evt.EVT_PDU_SENT, {'pdu': dul.pdu}) return 'Sta6'
def test_recv_assoc_ac_user_id(self, caplog): """Test ACSE.debug_receive_associate_ac with User Identity.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.add_user_identity_rsp(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) self.acse.debug_receive_associate_ac(pdu) messages = [ "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: Yes", ] for msg in messages: assert msg in caplog.text
def test_recv_assoc_ac_async(self, caplog): """Test ACSE.debug_receive_associate_ac with async ops.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.add_async_ops(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) self.acse.debug_receive_associate_ac(pdu) messages = [ "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation:", "Maximum Invoked Operations: 2", "Maximum Performed Operations: 3", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text
def test_send_assoc_ac_minimal(self, caplog): """Test minimal ACSE.debug_send_associate_ac.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.ae = ae = AE() ae.add_supported_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) scp = ae.start_server(('', 11112), block=False) assoc = ae.associate('localhost', 11112) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) evt.trigger(assoc, evt.EVT_PDU_SENT, {'pdu': pdu}) messages = [ "Our Implementation Class UID: 1.2.826.0.1.3680043.8.498" ".10207287587329888519122978685894984263", "Application Context Name: 1.2.840.10008.3.1.1.1", "Responding Application Name: resp. AE Title", "Our Max PDU Receive Size: 0", "Presentation Contexts:", "Context ID: 1 (Accepted)", "Abstract Syntax: =Verification SOP Class", "Accepted SCP/SCU Role: Default", "Accepted Transfer Syntax: =JPEG Baseline (Process 1)", "Context ID: 3 (User Rejection)", "Context ID: 5 (Provider Rejection)", "Context ID: 7 (Rejected - Abstract Syntax Not Supported)", "Context ID: 9 (Rejected - Transfer Syntax Not Supported)", "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text assoc.release() scp.shutdown()
def test_recv_assoc_ac_sop_ext(self, caplog): """Test ACSE.debug_receive_associate_ac with SOP Class Extended.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.add_sop_ext(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) self.acse.debug_receive_associate_ac(pdu) messages = [ "Accepted Extended Negotiation:", "SOP Class: =1.2.3.4", "[ 00 01 ]", "SOP Class: =1.2.840.10008.1.1", "[ 00 01 02 03 00 01 02 03 00 01 02 03 00 01 02" " 03", "00 01 02 03 00 01 02 03 00 01 02 03 00 01 02 03", "00 01 02 03 00 01 02 03 ]", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text
def test_recv_assoc_ac_role(self, caplog): """Test ACSE.debug_receive_associate_ac with role selection.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.add_scp_scu_role(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) self.acse.debug_receive_associate_ac(pdu) messages = [ "Accepted Role Selection:", "SOP Class: =Implicit VR Little Endian", "SCP/SCU Role: SCU", "SOP Class: =1.2.840.10008.1.3", "SCP/SCU Role: SCP", "SOP Class: =1.2.840.10008.1.4", "SCP/SCU Role: SCP/SCU", "Accepted Extended Negotiation: None", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text
def test__pdu_to_event(self): """Test that good PDU paramters return expected results""" dul = DummyDUL() p2e = dul._pdu_to_event pdu_types = [A_ASSOCIATE_RQ(), A_ASSOCIATE_AC(), A_ASSOCIATE_RJ(), P_DATA_TF(), A_RELEASE_RQ(), A_RELEASE_RP(), A_ABORT_RQ(), 'TEST'] event_str = ['Evt6', 'Evt3', 'Evt4', 'Evt10', 'Evt12', 'Evt13', 'Evt16', 'Evt19'] for pdu, evt in zip(pdu_types, event_str): assert p2e(pdu) == evt
def test_recv_assoc_ac_sop_ext(self, caplog): """Test ACSE.debug_receive_associate_ac with SOP Class Extended.""" with caplog.at_level(logging.DEBUG, logger='pynetdicom'): self.ae = ae = AE() ae.add_supported_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) ae.add_requested_context(VerificationSOPClass) scp = ae.start_server(('', 11112), block=False) assoc = ae.associate('localhost', 11112) self.add_sop_ext(self.associate_ac) pdu = A_ASSOCIATE_AC() pdu.from_primitive(self.associate_ac) evt.trigger(assoc, evt.EVT_PDU_RECV, {'pdu': pdu}) messages = [ "Accepted Extended Negotiation:", "SOP Class: =1.2.3.4", "00 01", "SOP Class: =1.2.840.10008.1.1", "00 01 02 03 00 01 02 03 00 01 02 03 00 01 02" " 03", "00 01 02 03 00 01 02 03 00 01 02 03 00 01 02" " 03", "00 01 02 03 00 01 02 03", "Accepted Asynchronous Operations Window Negotiation: None", "User Identity Negotiation Response: None", ] for msg in messages: assert msg in caplog.text assoc.release() scp.shutdown()
def AE_7(dul: "DULServiceProvider") -> str: """Association establishment action AE-7. On receiving association request acceptance, issue A-ASSOCIATE-AC State-event triggers: Sta3 + Evt7 Parameters ---------- dul : dul.DULServiceProvider The DICOM Upper Layer Service instance for the local AE Returns ------- str ``'Sta6'``, the next state of the state machine """ # Received A-ASSOCIATE (AC) primitive from local user primitive = cast("A_ASSOCIATE", dul.to_provider_queue.get(False)) # Send A-ASSOCIATE-AC PDU dul._send(A_ASSOCIATE_AC(primitive)) return "Sta6"