Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/mock_vws/add_target/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/authorization_header/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/content_length/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/database_summary/contract/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/date_header/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/delete_target/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
170 changes: 127 additions & 43 deletions tests/mock_vws/fixtures/vuforia_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,40 +561,108 @@ def _setup_model_target_backend(
)


# Tests which use this are run against the real Vuforia and against each
# mock. This is useful for verifying the mocks.
fixture_verify_mock_vuforia = backend_fixture(
name="verify_mock_vuforia",
@beartype
def _defer_backend_setup(
*,
backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Leave setup to the shared fixture after backend selection.

Yields:
``None``, without setting up the selected backend.
"""
del backend, request
yield


# These adapter-internal fixtures select and apply skip policy for a backend.
# Public fixtures below set up and tear down the selected backend without
# exposing that selection to the shared suite.
fixture_vws_backend = backend_fixture(
name="_vws_backend",
backends=_ALL_BACKENDS,
setup_for=_setup_backend,
setup_for=_defer_backend_setup,
)

# Model Target Web API contract tests, run against the real Vuforia and
# against each mock.
fixture_verify_model_target_mock_vuforia = backend_fixture(
name="verify_model_target_mock_vuforia",
fixture_model_target_backend = backend_fixture(
name="_model_target_backend",
backends=_ALL_BACKENDS,
setup_for=_setup_model_target_backend,
setup_for=_defer_backend_setup,
)

# Model Target Web API tests which need scopes that the real test account does
# not have, run against each mock only.
fixture_model_target_mock_only_vuforia = backend_fixture(
name="model_target_mock_only_vuforia",
fixture_model_target_mock_backend = backend_fixture(
name="_model_target_mock_backend",
backends=_MOCK_BACKENDS,
setup_for=_setup_model_target_backend,
setup_for=_defer_backend_setup,
)

# Tests which use this are run against each mock, and not against the
# real Vuforia. This is useful for testing the mock using fixtures which
# connect to Vuforia.
fixture_mock_only_vuforia = backend_fixture(
name="mock_only_vuforia",
fixture_mock_vws_backend = backend_fixture(
name="_mock_vws_backend",
backends=_MOCK_BACKENDS,
setup_for=_setup_backend,
setup_for=_defer_backend_setup,
)


@pytest.fixture(name="verify_mock_vuforia")
def fixture_verify_mock_vuforia(
*,
_vws_backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Set up and tear down the selected VWS/query backend.

Yields:
``None``, once the backend is ready for shared tests.
"""
yield from _setup_backend(backend=_vws_backend, request=request)


@pytest.fixture(name="verify_model_target_mock_vuforia")
def fixture_verify_model_target_mock_vuforia(
*,
_model_target_backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Set up and tear down the selected Model Target backend.

Yields:
``None``, once the backend is ready for shared tests.
"""
yield from _setup_model_target_backend(
backend=_model_target_backend,
request=request,
)


@pytest.fixture(name="model_target_mock_only_vuforia")
def fixture_model_target_mock_only_vuforia(
*,
_model_target_mock_backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Set up and tear down a Model Target mock backend.

Yields:
``None``, once the backend is ready for mock-only tests.
"""
yield from _setup_model_target_backend(
backend=_model_target_mock_backend,
request=request,
)


@pytest.fixture(name="mock_only_vuforia")
def fixture_mock_only_vuforia(
*,
_mock_vws_backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Set up and tear down a VWS/query mock backend.

Yields:
``None``, once the backend is ready for mock-only tests.
"""
yield from _setup_backend(backend=_mock_vws_backend, request=request)


@beartype
def _cloud_database_adder(
*,
Expand All @@ -621,16 +689,19 @@ def add_flask_cloud_database(*, cloud_database: CloudDatabase) -> None:
@pytest.fixture(name="add_cloud_database")
def fixture_add_cloud_database(
*,
mock_only_vuforia: VuforiaBackend,
mock_only_vuforia: None,
_mock_vws_backend: VuforiaBackend,
) -> AddCloudDatabase:
"""The database creation operation for the running mock backend."""
return _cloud_database_adder(backend=mock_only_vuforia)
del mock_only_vuforia
return _cloud_database_adder(backend=_mock_vws_backend)


@pytest.fixture(name="rate_limited_database")
def fixture_rate_limited_database(
*,
verify_mock_vuforia: VuforiaBackend,
verify_mock_vuforia: None,
_vws_backend: VuforiaBackend,
vuforia_database: CloudDatabase,
) -> CloudDatabase:
"""Return a database which applies real Vuforia's request rate limits.
Expand All @@ -639,24 +710,27 @@ def fixture_rate_limited_database(
database with the limits, so that the shared database which the other
tests use is not limited.
"""
if verify_mock_vuforia == VuforiaBackend.REAL:
del verify_mock_vuforia
if _vws_backend == VuforiaBackend.REAL:
return vuforia_database

database = CloudDatabase(
request_rate_limits=DOCUMENTED_REQUEST_RATE_LIMITS
)
add_cloud_database = _cloud_database_adder(backend=verify_mock_vuforia)
add_cloud_database = _cloud_database_adder(backend=_vws_backend)
add_cloud_database(cloud_database=database)
return database


@pytest.fixture(name="seed_recognition_counts")
def fixture_seed_recognition_counts(
*,
mock_only_vuforia: VuforiaBackend,
mock_only_vuforia: None,
_mock_vws_backend: VuforiaBackend,
) -> SeedRecognitionCounts:
"""The recognition-count operation for the running mock backend."""
if mock_only_vuforia == VuforiaBackend.MOCK:
del mock_only_vuforia
if _mock_vws_backend == VuforiaBackend.MOCK:

@beartype
def seed_in_memory_counts(
Expand Down Expand Up @@ -712,11 +786,13 @@ def seed_flask_counts(
@pytest.fixture(name="unrouted_requests")
def fixture_unrouted_requests(
*,
verify_mock_vuforia: VuforiaBackend,
verify_mock_vuforia: None,
_vws_backend: VuforiaBackend,
base_vws_url: str,
) -> UnroutedRequests:
"""The transport for unmatched requests on the running backend."""
if verify_mock_vuforia == VuforiaBackend.FLASK_IN_PROCESS:
del verify_mock_vuforia
if _vws_backend == VuforiaBackend.FLASK_IN_PROCESS:
return UnroutedRequests(
send=_send_flask_unrouted_request,
returns_response=True,
Expand Down Expand Up @@ -752,7 +828,7 @@ def send_http_request(

return UnroutedRequests(
send=send_http_request,
returns_response=verify_mock_vuforia != VuforiaBackend.MOCK,
returns_response=_vws_backend != VuforiaBackend.MOCK,
)


Expand Down Expand Up @@ -813,22 +889,26 @@ def _model_target_credentials_for_backend(
@pytest.fixture(name="model_target_credentials")
def fixture_model_target_credentials(
*,
verify_model_target_mock_vuforia: VuforiaBackend,
verify_model_target_mock_vuforia: None,
_model_target_backend: VuforiaBackend,
) -> ModelTargetCredentials:
"""Model Target credentials supplied by the running backend."""
del verify_model_target_mock_vuforia
return _model_target_credentials_for_backend(
backend=verify_model_target_mock_vuforia,
backend=_model_target_backend,
)


@pytest.fixture(name="mock_model_target_credentials")
def fixture_mock_model_target_credentials(
*,
model_target_mock_only_vuforia: VuforiaBackend,
model_target_mock_only_vuforia: None,
_model_target_mock_backend: VuforiaBackend,
) -> ModelTargetCredentials:
"""Model Target credentials for tests which require a mock."""
del model_target_mock_only_vuforia
return _model_target_credentials_for_backend(
backend=model_target_mock_only_vuforia,
backend=_model_target_mock_backend,
)


Expand Down Expand Up @@ -871,28 +951,32 @@ def _skip_unrequested_real_signing(
@pytest.fixture(name="signed_model_target_credentials")
def fixture_signed_model_target_credentials(
*,
verify_model_target_mock_vuforia: VuforiaBackend,
verify_model_target_mock_vuforia: None,
_model_target_backend: VuforiaBackend,
request: pytest.FixtureRequest,
) -> ModelTargetCredentials:
"""Credentials for signing tests, after applying the real-service
opt-in policy.
"""
del verify_model_target_mock_vuforia
_skip_unrequested_real_signing(
request=request,
backend=verify_model_target_mock_vuforia,
backend=_model_target_backend,
)
return _model_target_credentials_for_backend(
backend=verify_model_target_mock_vuforia,
backend=_model_target_backend,
)


@pytest.fixture(name="backend_capabilities")
def fixture_backend_capabilities(
*,
verify_mock_vuforia: VuforiaBackend,
verify_mock_vuforia: None,
_vws_backend: VuforiaBackend,
) -> BackendCapabilities:
"""The behavior supported by the running VWS and query backend."""
is_mock = verify_mock_vuforia != VuforiaBackend.REAL
del verify_mock_vuforia
is_mock = _vws_backend != VuforiaBackend.REAL
return BackendCapabilities(
deterministic_target_order=is_mock,
deterministic_query_order=is_mock,
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_vws/get_duplicates/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/get_target/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/header_size/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/invalid_given_id/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
2 changes: 1 addition & 1 deletion tests/mock_vws/invalid_json/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_mock_vuforia: object,
verify_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_mock_vuforia
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_model_target_mock_vuforia: object,
verify_model_target_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_model_target_mock_vuforia
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture(autouse=True)
def fixture_verify_backend(
*,
verify_model_target_mock_vuforia: object,
verify_model_target_mock_vuforia: None,
) -> None:
"""Set up the backend for every contract test in this directory."""
del verify_model_target_mock_vuforia
Loading
Loading