From 0a5dfca2e9e17e856d80ad4f4c06476596ec2a2e Mon Sep 17 00:00:00 2001 From: Adrian Cederberg Date: Fri, 13 Sep 2024 12:44:25 -0600 Subject: [PATCH] fix(tests): Fixed Bad Arguments to ``DummyProvider`` Constructor. --- tests/conftest.py | 36 ++++++++++++++++++---- tests/test_controllers/test_access.py | 9 ++++-- tests/test_models.py | 18 ++++++++--- tests/test_views/test_grants_users_unit.py | 13 ++++++-- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 82cc876..6d55243 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,6 +20,7 @@ from captura.schemas import mwargs from captura.views import AppView from simulatus import DummyHandler, DummyProvider, DummyProviderYAML +from simulatus.config import ConfigSimulatus from tests.config import PytestClientConfig, PytestConfig from tests.flakey import FLAKEY_PATH, Flakey @@ -262,6 +263,11 @@ def client_config(pytestconfig: pytest.Config) -> PytestClientConfig: return pytestconfig.stash[STASHKEY_CONFIG_LEGERE].model_copy() +@pytest.fixture(scope="session") +def config_simulatus(config: PytestConfig): + return ConfigSimulatus(dummy=config.dummy) + + # NOTE: Was this necessary? Currently impartial. class PytestContext(BaseModel): reloaded: bool = False @@ -362,11 +368,17 @@ def dummy_handler( @pytest.fixture -def dummy(request, dummy_handler: DummyHandler): +def dummy( + request, + config: PytestConfig, + config_simulatus: ConfigSimulatus, + dummy_handler: DummyHandler, +): logger.info("Providing random dummy.") with dummy_handler.sessionmaker() as session: dummy = DummyProvider( - dummy_handler.config, + config, + config_simulatus, session, auth=dummy_handler.auth, client_config_cls=PytestClientConfig, @@ -380,11 +392,17 @@ def dummy(request, dummy_handler: DummyHandler): @pytest.fixture -def dummy_new(request, dummy_handler: DummyHandler): +def dummy_new( + request, + config: PytestConfig, + config_simulatus: ConfigSimulatus, + dummy_handler: DummyHandler, +): logger.info("Providing new dummy.") with dummy_handler.sessionmaker() as session: dummy = DummyProvider( - dummy_handler.config, + config, + config_simulatus, session, auth=dummy_handler.auth, use_existing=False, @@ -399,11 +417,17 @@ def dummy_new(request, dummy_handler: DummyHandler): @pytest.fixture -def dummy_disposable(request, dummy_handler: DummyHandler): +def dummy_disposable( + request, + config: PytestConfig, + config_simulatus: ConfigSimulatus, + dummy_handler: DummyHandler, +): logger.info("Providing disposable dummy.") with dummy_handler.sessionmaker() as session: dummy = DummyProvider( - dummy_handler.config, + config, + config_simulatus, session, auth=dummy_handler.auth, client_config_cls=PytestClientConfig, diff --git a/tests/test_controllers/test_access.py b/tests/test_controllers/test_access.py index 1086f9a..ba6be4f 100644 --- a/tests/test_controllers/test_access.py +++ b/tests/test_controllers/test_access.py @@ -11,6 +11,7 @@ # --------------------------------------------------------------------------- # from captura import util +from captura.config import Config from captura.controllers.access import Access from captura.controllers.base import ( Data, @@ -46,6 +47,7 @@ UUIDSplit, ) from simulatus import DummyHandler, DummyProvider, DummyProviderYAML, GetPrimaryKwargs +from simulatus.config import ConfigSimulatus from tests.test_controllers.util import expect_exc from ..conftest import COUNT @@ -134,10 +136,13 @@ def test_d_fn(self, dummy: DummyProvider): ... @pytest.fixture(scope="class") def dummy( - self, dummy_handler: DummyHandler + self, + config: Config, + config_simulatus: ConfigSimulatus, + dummy_handler: DummyHandler ) -> Generator[DummyProvider, None, None]: with dummy_handler.sessionmaker() as session: - dummy = DummyProvider(dummy_handler.config, session) + dummy = DummyProvider(config, config_simulatus, session) yield dummy def test_d_fn(self) -> None: diff --git a/tests/test_models.py b/tests/test_models.py index 87e3ec3..564aa53 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -8,6 +8,7 @@ # --------------------------------------------------------------------------- # from captura import __version__, util +from captura.config import Config from captura.fields import Level, PendingFrom from captura.models import ( Assignment, @@ -21,6 +22,7 @@ Resolvable, ) from simulatus import DummyHandler, DummyProvider +from simulatus.config import ConfigSimulatus from tests.check import Check from tests.conftest import COUNT @@ -225,11 +227,15 @@ def test_document_deletion(self, dummy_disposable: DummyProvider, count: int): raise AssertionError("All documents have empty assignments.") def test_user_deletion_documents( - self, dummy_handler: DummyHandler, session: Session, count: int + self, + config: Config, + config_simulatus: ConfigSimulatus, + session: Session, + count: int, ): n_empty_grants = 0 for _ in range(5): - dummy = DummyProvider(dummy_handler.config, session) + dummy = DummyProvider(config, config_simulatus, session) user = dummy.user q_grants = user.q_select_grants(exclude_deleted=False) grants = dummy.session.scalars(q_grants) @@ -270,11 +276,15 @@ def test_user_deletion_documents( dummy.dispose() def test_user_deletion_collections( - self, dummy_handler: DummyHandler, session: Session, count: int + self, + config: Config, + config_simulatus: ConfigSimulatus, + session: Session, + count: int, ): n_no_collections = 0 for _ in range(0, 3): - dummy = DummyProvider(dummy_handler.config, session) + dummy = DummyProvider(config, config_simulatus, session) user = dummy.user uuid_collections = set( session.scalars( diff --git a/tests/test_views/test_grants_users_unit.py b/tests/test_views/test_grants_users_unit.py index 05e69a4..760084d 100644 --- a/tests/test_views/test_grants_users_unit.py +++ b/tests/test_views/test_grants_users_unit.py @@ -10,6 +10,7 @@ from sqlalchemy import select # --------------------------------------------------------------------------- # +from captura.config import Config from captura.err import ( ErrAccessUser, ErrAssocRequestMustForce, @@ -22,6 +23,7 @@ from captura.schemas import AsOutput, GrantSchema, KindNesting, OutputWithEvents, mwargs from legere.requests import Requests from simulatus import DummyProvider, GetPrimaryKwargs +from simulatus.config import ConfigSimulatus from tests.conftest import COUNT from tests.test_views.util import BaseEndpointTest @@ -183,7 +185,12 @@ def fn(self, requests: Requests): # NOTE: Many tests bc pain in the ass. @pytest.mark.asyncio async def test_success_200_simple( - self, dummy: DummyProvider, requests: Requests, count: int + self, + dummy: DummyProvider, + config: Config, + config_simulatus: ConfigSimulatus, + requests: Requests, + count: int, ): "Test requesting a (single) grant that does not already exist and is not deleted." @@ -191,7 +198,9 @@ async def test_success_200_simple( (other_user,) = dummy.get_users(1) assert user.uuid != other_user.uuid - other_dummy = DummyProvider(dummy.config, session, use_existing=other_user) + other_dummy = DummyProvider( + config, config_simulatus, session, use_existing=other_user + ) (other_document,) = other_dummy.get_documents(1, level=Level.own) assert other_document.deleted is False