def test_assignment(self):
     """ Check assignment works correctly """
     primitive = A_ABORT()
     primitive.abort_source = 0
     self.assertEqual(primitive.abort_source, 0)
     primitive.abort_source = 2
     self.assertEqual(primitive.abort_source, 2)
    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()

        self.assertEqual(data, b"\x07\x00\x00\x00\x00\x04\x00\x00\x00\x00")
Beispiel #4
0
    def abort_assoc(self, source=0x02, reason=0x00):
        """Abort the Association with the peer Application Entity.

        ACSE issued A-ABORT request primitive to the DICOM UL service provider.
        The source may be either the DUL service user or provider.

        See PS3.8 7.3-4 and 9.3.8

        Parameters
        ----------
        source : int, optional
            The source of the abort request (default: 0x02 DUL provider)

            - 0x00 - the DUL service user
            - 0x02 - the DUL service provider
        reason : int, optional
            The reason for aborting the association (default: 0x00 reason not
            specified).

            If source 0x00 (DUL user):

            - 0x00 - reason field not significant

            If source 0x02 (DUL provider):

            - 0x00 - reason not specified
            - 0x01 - unrecognised PDU
            - 0x02 - unexpected PDU
            - 0x04 - unrecognised PDU parameter
            - 0x05 - unexpected PDU parameter
            - 0x06 - invalid PDU parameter value
        """
        primitive = A_ABORT()

        if source in [0x00, 0x02]:
            primitive.abort_source = source
            if source == 0x00:
                primitive.reason = 0x00
            elif reason in [0x00, 0x01, 0x02, 0x04, 0x05, 0x06]:
                primitive.reason = reason
            else:
                raise ValueError("acse.abort_assoc() invalid reason "
                                 "'{0!s}'".format(reason))

        else:
            raise ValueError("acse.abort_assoc() invalid source "
                             "'{0!s}'".format(source))

        self.dul.send_pdu(primitive)
Beispiel #5
0
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

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

    Parameters
    ----------
    dul : pynetdicom3.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'
Beispiel #6
0
    def test__primitive_to_event(self):
        """Test that parameter returns expected results"""
        dul = DummyDUL()
        p2e = dul._primitive_to_event

        primitive = A_ASSOCIATE()
        primitive.result = None
        self.assertEqual(p2e(primitive), 'Evt1')
        primitive.result = 0
        self.assertEqual(p2e(primitive), 'Evt7')
        primitive.result = 1
        self.assertEqual(p2e(primitive), 'Evt8')

        primitive = A_RELEASE()
        primitive.result = None
        self.assertEqual(p2e(primitive), 'Evt11')
        primitive.result = 'affirmative'
        self.assertEqual(p2e(primitive), 'Evt14')

        primitive = A_ABORT()
        self.assertEqual(p2e(primitive), 'Evt15')

        primitive = P_DATA()
        self.assertEqual(p2e(primitive), 'Evt9')

        with self.assertRaises(ValueError):
            p2e('TEST')