Ejemplo n.º 1
0
 def test_is_cancelled_no_match(self):
     """Test is_cancelled with no matching C-CANCEL."""
     assoc = DummyAssoc()
     cancel = C_CANCEL()
     cancel.MessageIDBeingRespondedTo = 5
     assoc.dimse.cancel_req[5] = cancel
     assoc.dimse.cancel_req[3] = cancel
     service = ServiceClass(assoc)
     assert service.is_cancelled(1) is False
     assert service.is_cancelled(2) is False
Ejemplo n.º 2
0
    def test_assignment(self):
        """ Check assignment works correctly """
        primitive = C_CANCEL()

        primitive.MessageIDBeingRespondedTo = 13
        assert primitive.MessageIDBeingRespondedTo == 13
        with pytest.raises(ValueError):
            primitive.MessageIDBeingRespondedTo = 100000
        with pytest.raises(TypeError):
            primitive.MessageIDBeingRespondedTo = 'test'
Ejemplo n.º 3
0
 def test_is_cancelled_match(self):
     """Test is_cancelled with matching C-CANCEL."""
     assoc = DummyAssoc()
     cancel = C_CANCEL()
     cancel.MessageIDBeingRespondedTo = 5
     assoc.dimse.cancel_req[4] = C_GET()
     assoc.dimse.cancel_req[3] = cancel
     service = ServiceClass(assoc)
     assert service.is_cancelled(1) is False
     assert service.is_cancelled(2) is False
     assert service.is_cancelled(3) is True
     service = ServiceClass(assoc)
     assert service.is_cancelled(1) is False
     assert service.is_cancelled(2) is False
     assert service.is_cancelled(3) is False
     assert cancel not in assoc.dimse.cancel_req.values()
Ejemplo n.º 4
0
    def message_to_primitive(self):
        """Convert the ``DIMSEMessage`` class to a DIMSE primitive.

        Returns
        -------
        DIMSEPrimitive sub-class
            One of the DIMSE message primitives from
            :ref:`pynetdicom.dimse_primitives<api_dimse_primitives>` generated
            from the current ``DIMSEMessage`` sub-class object.
        """
        # pylint: disable=too-many-branches
        cls_type_name = self.__class__.__name__
        if 'C_ECHO' in cls_type_name:
            primitive = C_ECHO()
        elif 'C_STORE' in cls_type_name:
            primitive = C_STORE()
        elif 'C_FIND' in cls_type_name:
            primitive = C_FIND()
        elif 'C_GET' in cls_type_name:
            primitive = C_GET()
        elif 'C_MOVE' in cls_type_name:
            primitive = C_MOVE()
        elif 'C_CANCEL' in cls_type_name:
            primitive = C_CANCEL()
        elif 'N_EVENT' in cls_type_name:
            primitive = N_EVENT_REPORT()
        elif 'N_GET' in cls_type_name:
            primitive = N_GET()
        elif 'N_SET' in cls_type_name:
            primitive = N_SET()
        elif 'N_ACTION' in cls_type_name:
            primitive = N_ACTION()
        elif 'N_CREATE' in cls_type_name:
            primitive = N_CREATE()
        elif 'N_DELETE' in cls_type_name:
            primitive = N_DELETE()

        # Command Set
        # For each parameter in the primitive, set the appropriate value
        #   from the Message's Command Set elements
        for elem in self.command_set:
            if hasattr(primitive, elem.keyword):
                setattr(
                    primitive,
                    elem.keyword,
                    self.command_set.__getattr__(elem.keyword)
                )

        # Datasets
        # Set the primitive's DataSet/Identifier/etc attribute
        try:
            dataset_keyword = _DATASET_KEYWORDS[cls_type_name]
            setattr(primitive, dataset_keyword, self.data_set)
        except KeyError:
            pass

        # Set the presentation context ID the message was set under
        primitive._context_id = self.context_id

        return primitive
Ejemplo n.º 5
0
    def receive_pdu():
        """Dummy Receive method to test DIMSEServiceProvider.Receive"""
        pass

    @staticmethod
    def peek_next_pdu():
        return 0x01


REFERENCE_MSG = [
    (C_ECHO(), ('C_ECHO_RQ', 'C_ECHO_RSP')),
    (C_STORE(), ('C_STORE_RQ', 'C_STORE_RSP')),
    (C_FIND(), ('C_FIND_RQ', 'C_FIND_RSP')),
    (C_GET(), ('C_GET_RQ', 'C_GET_RSP')),
    (C_MOVE(), ('C_MOVE_RQ', 'C_MOVE_RSP')),
    (C_CANCEL(), (None, 'C_CANCEL_RQ')),
    (N_EVENT_REPORT(), ('N_EVENT_REPORT_RQ', 'N_EVENT_REPORT_RSP')),
    (N_GET(), ('N_GET_RQ', 'N_GET_RSP')),
    (N_SET(), ('N_SET_RQ', 'N_SET_RSP')),
    (N_ACTION(), ('N_ACTION_RQ', 'N_ACTION_RSP')),
    (N_CREATE(), ('N_CREATE_RQ', 'N_CREATE_RSP')),
    (N_DELETE(), ('N_DELETE_RQ', 'N_DELETE_RSP')),
]


class TestDIMSEProvider(object):
    """Test DIMSE service provider operations."""
    def setup(self):
        """Set up"""
        self.dimse = DIMSEServiceProvider(DummyDUL(), 1)
Ejemplo n.º 6
0
    def receive_pdu():
        """Dummy Receive method to test DIMSEServiceProvider.Receive"""
        pass

    @staticmethod
    def peek_next_pdu():
        return 0x01


REFERENCE_MSG = [
    (C_ECHO(), ("C_ECHO_RQ", "C_ECHO_RSP")),
    (C_STORE(), ("C_STORE_RQ", "C_STORE_RSP")),
    (C_FIND(), ("C_FIND_RQ", "C_FIND_RSP")),
    (C_GET(), ("C_GET_RQ", "C_GET_RSP")),
    (C_MOVE(), ("C_MOVE_RQ", "C_MOVE_RSP")),
    (C_CANCEL(), (None, "C_CANCEL_RQ")),
    (N_EVENT_REPORT(), ("N_EVENT_REPORT_RQ", "N_EVENT_REPORT_RSP")),
    (N_GET(), ("N_GET_RQ", "N_GET_RSP")),
    (N_SET(), ("N_SET_RQ", "N_SET_RSP")),
    (N_ACTION(), ("N_ACTION_RQ", "N_ACTION_RSP")),
    (N_CREATE(), ("N_CREATE_RQ", "N_CREATE_RSP")),
    (N_DELETE(), ("N_DELETE_RQ", "N_DELETE_RSP")),
]


class TestDIMSEProvider:
    """Test DIMSE service provider operations."""
    def setup(self):
        """Set up"""
        self.dimse = DIMSEServiceProvider(DummyAssociation())