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)