ds_provider_mock_py_lib.linked_service ====================================== .. py:module:: ds_provider_mock_py_lib.linked_service .. autoapi-nested-parse:: **File:** ``__init__.py`` **Region:** ``ds_provider_mock_py_lib/linked_service`` Mock Linked Service This module implements an in-memory linked service for e2e testing. .. rubric:: Example >>> from uuid import uuid4 >>> from ds_provider_mock_py_lib.linked_service import MockLinkedService, MockLinkedServiceSettings >>> linked_service = MockLinkedService( ... id=uuid4(), ... name="mock-connection", ... version="1.0.0", ... settings=MockLinkedServiceSettings(), ... ) >>> linked_service.connect() Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/ds_provider_mock_py_lib/linked_service/mock/index Classes ------- .. autoapisummary:: ds_provider_mock_py_lib.linked_service.MockBackend ds_provider_mock_py_lib.linked_service.MockLinkedService ds_provider_mock_py_lib.linked_service.MockLinkedServiceSettings Package Contents ---------------- .. py:class:: MockBackend(settings: MockLinkedServiceSettings) Object returned by ``.connection``. Stands in for a real SDK client. Tracks call counts so tests can assert round-trips, and applies linked-service level failure rules independent of any dataset. .. py:attribute:: settings .. py:attribute:: call_count :value: 0 .. py:attribute:: closed :value: False .. py:method:: request(page: int) -> None Simulate one round-trip for ``page``. :param page: 1-based page number requested by the dataset. :raises MockBackendError: When the connection is closed or a failure rule matches. .. py:method:: close() -> None Mark the backend handle as closed. .. py:class:: MockLinkedService Bases: :py:obj:`ds_resource_plugin_py_lib.common.resource.linked_service.LinkedService`\ [\ :py:obj:`MockLinkedServiceSettings`\ ] In-memory linked service with tunable connect, health, and request failures. .. py:attribute:: settings :type: MockLinkedServiceSettings .. py:attribute:: _connection :type: MockBackend | None :value: None .. py:attribute:: _connect_attempts :type: int :value: 0 .. py:property:: type :type: ds_provider_mock_py_lib.enums.ResourceType Get the type of the linked service. :returns: ResourceType .. py:property:: connection :type: MockBackend Return the mock backend established by ``connect()``. :returns: The connected backend handle. :rtype: MockBackend :raises ConnectionError: If ``connect()`` has not been called. .. py:method:: connect() -> None Establish a connection to the mock backend. :raises ConnectionError: When connect is configured to fail or is still in the transient-failure window. :raises AuthenticationError: When ``connect_behaviour`` is ``authentication_error``. :raises AuthorizationError: When ``connect_behaviour`` is ``authorization_error``. .. py:method:: test_connection() -> tuple[bool, str] Verify mock backend health without raising on failure. :returns: ``(True, "")`` on success, otherwise ``(False, reason)``. :rtype: tuple[bool, str] .. py:method:: close() -> None Release the mock backend handle. Safe to call repeatedly. .. py:class:: MockLinkedServiceSettings Bases: :py:obj:`ds_resource_plugin_py_lib.common.resource.linked_service.LinkedServiceSettings` Settings required to connect to the in-memory mock backend. .. py:attribute:: connect_behaviour :type: ds_provider_mock_py_lib.enums.ConnectBehaviour What ``connect()`` does after optional transient failures. .. py:attribute:: connect_delay_ms :type: int :value: 0 Artificial delay applied during ``connect()``. .. py:attribute:: connect_fail_first_n :type: int :value: 0 First N ``connect()`` calls raise ``ConnectionError``, then succeed. .. py:attribute:: connect_error :type: ds_provider_mock_py_lib.models.MockError Error spec used when ``connect()`` is configured to fail. .. py:attribute:: test_connection_ok :type: bool :value: True When ``False``, ``test_connection()`` returns a failed health check. .. py:attribute:: test_connection_message :type: str :value: '' Reason returned when ``test_connection_ok`` is ``False``. .. py:attribute:: latency_ms :type: int :value: 0 Artificial delay applied to every ``connection.request()`` call. .. py:attribute:: fail_on_call :type: int | None :value: None Raise ``MockBackendError`` on the Nth ``request()`` call. ``None`` disables. .. py:attribute:: request_error :type: ds_provider_mock_py_lib.models.MockError Error spec used when ``fail_on_call`` matches. .. py:attribute:: drop_after_calls :type: int | None :value: None Every ``request()`` after N calls raises. ``None`` disables. .. py:attribute:: drop_error :type: ds_provider_mock_py_lib.models.MockError Error spec used when the connection is dropped after N calls.