Skip to content

Commit

Permalink
fix(tests): Fixed Bad Arguments to DummyProvider Constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
acederberg committed Sep 13, 2024
1 parent a95177a commit 0a5dfca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
36 changes: 30 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions tests/test_controllers/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 11 additions & 2 deletions tests/test_views/test_grants_users_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sqlalchemy import select

# --------------------------------------------------------------------------- #
from captura.config import Config
from captura.err import (
ErrAccessUser,
ErrAssocRequestMustForce,
Expand All @@ -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

Expand Down Expand Up @@ -183,15 +185,22 @@ 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."

user, session = dummy.user, dummy.session
(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

Expand Down

0 comments on commit 0a5dfca

Please sign in to comment.