Skip to content

Commit

Permalink
nodes and mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
matveyvarg committed Oct 16, 2023
1 parent 6e69ad7 commit f80f378
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
23 changes: 16 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from concurrent.futures import ThreadPoolExecutor
from typing import Dict
from typing import Dict, List
from unittest.mock import patch
from uuid import uuid4

Expand All @@ -12,23 +12,32 @@
from deker.ctx import CTX
from deker.uri import Uri
from deker_local_adapters.storage_adapters.hdf5.hdf5_storage_adapter import HDF5StorageAdapter
from httpx import Client
from pytest_mock import MockerFixture

from tests.mocks import MockedAdaptersFactory

from deker_server_adapters.array_adapter import ServerArrayAdapter
from deker_server_adapters.collection_adapter import ServerCollectionAdapter
from deker_server_adapters.factory import AdaptersFactory
from deker_server_adapters.hash_ring import HashRing
from deker_server_adapters.httpx_client import HttpxClient
from deker_server_adapters.varray_adapter import ServerVarrayAdapter


@pytest.fixture(scope="session")
def collection_path() -> Uri:
return Uri.create("http://localhost:8000/v1/collection")
def nodes() -> List[str]:
return ["http://localhost:8000", "http://localhost:8001"]


@pytest.fixture(scope="session")
def collection_path(nodes: List[str]) -> Uri:
uri = Uri.create("http://localhost:8000/v1/collection")
uri.servers = nodes
return uri


@pytest.fixture(scope="session")
def ctx(session_mocker: MockerFixture, collection_path: Uri) -> CTX:
def ctx(session_mocker: MockerFixture, collection_path: Uri, nodes: List[str]) -> CTX:
ctx = CTX(
uri=collection_path,
config=DekerConfig(
Expand All @@ -43,13 +52,13 @@ def ctx(session_mocker: MockerFixture, collection_path: Uri) -> CTX:
)
with HttpxClient(base_url="http://localhost:8000/") as client:
ctx.extra["httpx_client"] = client
ctx.extra["hash_ring"] = HashRing(nodes)
yield ctx


@pytest.fixture(scope="session")
def adapter_factory(ctx: CTX, collection_path: Uri) -> AdaptersFactory:
with patch.object(AdaptersFactory, "do_healthcheck"):
yield AdaptersFactory(ctx, uri=collection_path)
return MockedAdaptersFactory(ctx, uri=collection_path)


@pytest.fixture()
Expand Down
8 changes: 8 additions & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from deker.ctx import CTX

from deker_server_adapters.factory import AdaptersFactory


class MockedAdaptersFactory(AdaptersFactory):
def do_healthcheck(self, ctx: CTX) -> None:
pass
3 changes: 1 addition & 2 deletions tests/test_cases/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from deker.uri import Uri
from deker_local_adapters.storage_adapters.hdf5 import HDF5StorageAdapter

from tests.mocks import MockedAdaptersFactory

from ..mocks import MockedAdaptersFactory
from deker_server_adapters.array_adapter import ServerArrayAdapter
from deker_server_adapters.collection_adapter import ServerCollectionAdapter
from deker_server_adapters.factory import AdaptersFactory
Expand Down

0 comments on commit f80f378

Please sign in to comment.