def test_assignment(self): """ Check assignment works correctly """ primitive = A_ABORT() primitive.abort_source = 0 assert primitive.abort_source == 0 primitive.abort_source = 2 assert primitive.abort_source == 2
def send_abort(self, source): """Send an A-ABORT request to the peer. Parameters ---------- source : int The source of the abort request - ``0x00`` - the DUL service user - ``0x02`` - the DUL service provider Raises ------ ValueError If the `source` value is invalid. """ if source not in [0x00, 0x02]: raise ValueError("Invalid 'source' parameter value") # The following parameters must be set for an A-ABORT primitive # (* sent in A-ABORT PDU): # Abort Source* # Provider Reason* (not significant with source 0x00) primitive = A_ABORT() primitive.abort_source = source self.dul.send_pdu(primitive) self.assoc.is_aborted = True self.assoc.is_established = False
def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = A_ABORT() with pytest.raises(ValueError): primitive.abort_source = 1 with pytest.raises(ValueError): primitive.abort_source
def test_conversion(self): """ Check conversion to a PDU produces the correct output """ primitive = A_ABORT() primitive.abort_source = 0 pdu = A_ABORT_RQ() pdu.from_primitive(primitive) data = pdu.encode() assert data == b"\x07\x00\x00\x00\x00\x04\x00\x00\x00\x00"
def test_primitive_to_event(self): """Test that parameter returns expected results""" dul = DULServiceProvider(DummyAssociation()) p2e = dul._primitive_to_event primitive = A_ASSOCIATE() primitive.result = None assert p2e(primitive) == 'Evt1' primitive.result = 0 assert p2e(primitive) == 'Evt7' primitive.result = 1 assert p2e(primitive) == 'Evt8' primitive = A_RELEASE() primitive.result = None assert p2e(primitive) == 'Evt11' primitive.result = 'affirmative' assert p2e(primitive) == 'Evt14' primitive = A_ABORT() assert p2e(primitive) == 'Evt15' primitive = P_DATA() assert p2e(primitive) == 'Evt9' with pytest.raises(ValueError): p2e('TEST')
def AA_4(dul): """Association abort AA-4. If connection closed, issue A-P-ABORT and return to Idle State-event triggers: Sta3/Sta4/Sta5/Sta6/Sta7/Sta8/Sta9/Sta10/Sta11/Sta12 + Evt17 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 Sta1, the next state of the state machine """ # Issue A-P-ABORT indication primitive. dul.primitive = A_ABORT() dul.to_user_queue.put(dul.primitive) return 'Sta1'
def test_recv_primitive(self): """Test processing received primitives""" dul = DULServiceProvider(DummyAssociation()) primitive = A_ASSOCIATE() primitive.result = None dul.to_provider_queue.put(primitive) dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt1" primitive.result = 0 dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt7" primitive.result = 1 dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt8" dul.to_provider_queue.get(False) primitive = A_RELEASE() primitive.result = None dul.to_provider_queue.put(primitive) dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt11" primitive.result = "affirmative" dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt14" dul.to_provider_queue.get(False) primitive = A_ABORT() dul.to_provider_queue.put(primitive) dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt15" dul.to_provider_queue.get(False) primitive = P_DATA() dul.to_provider_queue.put(primitive) dul._process_recv_primitive() assert dul.event_queue.get(False) == "Evt9" dul.to_provider_queue.get(False) msg = "Unknown primitive type 'str' received" with pytest.raises(ValueError, match=msg): dul.to_provider_queue.put("TEST") dul._process_recv_primitive()