From 9145f0e7cfbfc76ab026c842de412712be01ffc8 Mon Sep 17 00:00:00 2001 From: Nicolas Drebenstedt Date: Fri, 12 Apr 2024 11:48:28 +0200 Subject: [PATCH 1/5] Prepare rule implementations --- .pre-commit-config.yaml | 2 +- mex/backend/exceptions.py | 67 ++++++++++++++ mex/backend/main.py | 37 +------- mex/backend/settings.py | 2 +- mex/backend/types.py | 3 +- pdm.lock | 186 +++++++++++++++++++------------------- pyproject.toml | 6 +- tests/conftest.py | 2 +- 8 files changed, 171 insertions(+), 134 deletions(-) create mode 100644 mex/backend/exceptions.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8398fbe..5b48c13 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.5 + rev: v0.3.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/mex/backend/exceptions.py b/mex/backend/exceptions.py new file mode 100644 index 0000000..6c5efa9 --- /dev/null +++ b/mex/backend/exceptions.py @@ -0,0 +1,67 @@ +from typing import Any, cast + +from fastapi.responses import JSONResponse +from pydantic import BaseModel, ValidationError +from starlette.requests import Request + +from mex.backend.transform import to_primitive +from mex.common.logging import logger + + +class DebuggingScope(BaseModel, extra="ignore"): + """Scope for debugging info of error responses.""" + + http_version: str + method: str + path: str + path_params: dict[str, Any] + query_string: str + scheme: str + + +class DebuggingInfo(BaseModel): + """Debugging information for error responses.""" + + errors: list[dict[str, Any]] + scope: DebuggingScope + + +class ErrorResponse(BaseModel): + """Response model for user and system errors.""" + + message: str + debug: DebuggingInfo + + +def handle_validation_error(request: Request, exc: Exception) -> JSONResponse: + """Handle uncaught errors and provide debugging info.""" + logger.exception("Error %s", exc) + return JSONResponse( + to_primitive( + ErrorResponse( + message=str(exc), + debug=DebuggingInfo( + errors=cast(ValidationError, exc).errors(), + scope=DebuggingScope(**request.scope), + ), + ) + ), + 400, + ) + + +def handle_uncaught_exception(request: Request, exc: Exception) -> JSONResponse: + """Handle uncaught errors and provide debugging info.""" + logger.exception("Error %s", exc) + return JSONResponse( + to_primitive( + ErrorResponse( + message=str(exc), + debug=DebuggingInfo( + errors=[dict(type=type(exc).__name__)], + scope=DebuggingScope(**request.scope), + ), + ) + ), + 500, + ) diff --git a/mex/backend/main.py b/mex/backend/main.py index bd6f2ef..8fca9c2 100644 --- a/mex/backend/main.py +++ b/mex/backend/main.py @@ -6,10 +6,9 @@ from fastapi import APIRouter, Depends, FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.utils import get_openapi -from fastapi.responses import JSONResponse from pydantic import BaseModel, ValidationError -from starlette.requests import Request +from mex.backend.exceptions import handle_uncaught_exception, handle_validation_error from mex.backend.extracted.main import router as extracted_router from mex.backend.identity.main import router as identity_router from mex.backend.ingest.main import router as ingest_router @@ -17,11 +16,8 @@ from mex.backend.merged.main import router as merged_router from mex.backend.security import has_read_access, has_write_access from mex.backend.settings import BackendSettings -from mex.backend.transform import to_primitive from mex.common.cli import entrypoint -from mex.common.connector import ConnectorContext -from mex.common.exceptions import MExError -from mex.common.logging import logger +from mex.common.connector import CONNECTOR_STORE from mex.common.types import Identifier from mex.common.types.identifier import MEX_ID_PATTERN @@ -61,24 +57,11 @@ def create_openapi_schema() -> dict[str, Any]: return app.openapi_schema -def close_connectors() -> None: - """Try to close all connectors in the current context.""" - context = ConnectorContext.get() - for connector_type, connector in context.items(): - try: - connector.close() - except Exception: - logger.exception("Error closing %s", connector_type) - else: - logger.info("Closed %s", connector_type) - context.clear() - - @asynccontextmanager async def lifespan(_: FastAPI) -> AsyncIterator[None]: """Async context manager to execute setup and teardown of the FastAPI app.""" yield None - close_connectors() + CONNECTOR_STORE.reset() app = FastAPI( @@ -116,20 +99,8 @@ def check_system_status() -> SystemStatus: return SystemStatus(status="ok") -def handle_uncaught_exception(request: Request, exc: Exception) -> JSONResponse: - """Handle uncaught errors and provide some debugging clues.""" - logger.exception("Error %s", exc) - if isinstance(exc, ValidationError): - errors: list[Any] = exc.errors() - else: - errors = [dict(type=type(exc).__name__)] - body = dict(message=str(exc), debug=dict(errors=errors)) - return JSONResponse(to_primitive(body), 500) - - app.include_router(router) -app.add_exception_handler(ValidationError, handle_uncaught_exception) -app.add_exception_handler(MExError, handle_uncaught_exception) +app.add_exception_handler(ValidationError, handle_validation_error) app.add_exception_handler(Exception, handle_uncaught_exception) app.add_middleware( CORSMiddleware, diff --git a/mex/backend/settings.py b/mex/backend/settings.py index d36d507..e01a54a 100644 --- a/mex/backend/settings.py +++ b/mex/backend/settings.py @@ -71,7 +71,7 @@ class BackendSettings(BaseSettings): validation_alias="MEX_BACKEND_API_USER_DATABASE", ) identity_provider: IdentityProvider | BackendIdentityProvider = Field( - BackendIdentityProvider.GRAPH, + IdentityProvider.MEMORY, description="Provider to assign stableTargetIds to new model instances.", validation_alias="MEX_IDENTITY_PROVIDER", ) # type: ignore[assignment] diff --git a/mex/backend/types.py b/mex/backend/types.py index abea95b..acb1c6f 100644 --- a/mex/backend/types.py +++ b/mex/backend/types.py @@ -4,7 +4,6 @@ from pydantic import SecretStr from mex.common.models import ( - BASE_MODEL_CLASSES_BY_NAME, EXTRACTED_MODEL_CLASSES_BY_NAME, MERGED_MODEL_CLASSES_BY_NAME, BaseModel, @@ -68,7 +67,7 @@ def __new__( class UnprefixedType(Enum, metaclass=DynamicStrEnum): """Enumeration of possible types without any prefix.""" - __names__ = list(m.removeprefix("Base") for m in BASE_MODEL_CLASSES_BY_NAME) + __names__ = [m.removeprefix("Extracted") for m in EXTRACTED_MODEL_CLASSES_BY_NAME] class ExtractedType(Enum, metaclass=DynamicStrEnum): diff --git a/pdm.lock b/pdm.lock index d1f65de..aa69609 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:2138d47293478f741b83451605c83841dc9703bc6c075dc6af8be3880868c0e0" +content_hash = "sha256:52ecbf0505ec7d6102a3f96c8e8690bab54ed61bc06c0f5cb3856f44b25377da" [[package]] name = "alabaster" @@ -371,13 +371,13 @@ files = [ [[package]] name = "idna" -version = "3.6" +version = "3.7" requires_python = ">=3.5" summary = "Internationalized Domain Names in Applications (IDNA)" groups = ["default", "dev"] files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] [[package]] @@ -542,11 +542,11 @@ files = [ [[package]] name = "mex-common" -version = "0.22.0" -requires_python = ">=3.11" +version = "0.24.0" +requires_python = "<3.13,>=3.11" git = "https://github.com/robert-koch-institut/mex-common.git" -ref = "0.22.0" -revision = "f23a25131fcf35e228b86463b30f99d44c290e0d" +ref = "0.24.0" +revision = "322b726dc01f0de28da12c3e0348b985cb78c5d6" summary = "Common library for MEx python projects." groups = ["default"] dependencies = [ @@ -664,33 +664,33 @@ files = [ [[package]] name = "pandas" -version = "2.2.1" +version = "2.2.2" requires_python = ">=3.9" summary = "Powerful data structures for data analysis, time series, and statistics" groups = ["default"] dependencies = [ - "numpy<2,>=1.23.2; python_version == \"3.11\"", - "numpy<2,>=1.26.0; python_version >= \"3.12\"", + "numpy>=1.23.2; python_version == \"3.11\"", + "numpy>=1.26.0; python_version >= \"3.12\"", "python-dateutil>=2.8.2", "pytz>=2020.1", "tzdata>=2022.7", ] files = [ - {file = "pandas-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f821213d48f4ab353d20ebc24e4faf94ba40d76680642fb7ce2ea31a3ad94f9b"}, - {file = "pandas-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c70e00c2d894cb230e5c15e4b1e1e6b2b478e09cf27cc593a11ef955b9ecc81a"}, - {file = "pandas-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e97fbb5387c69209f134893abc788a6486dbf2f9e511070ca05eed4b930b1b02"}, - {file = "pandas-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:101d0eb9c5361aa0146f500773395a03839a5e6ecde4d4b6ced88b7e5a1a6403"}, - {file = "pandas-2.2.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:7d2ed41c319c9fb4fd454fe25372028dfa417aacb9790f68171b2e3f06eae8cd"}, - {file = "pandas-2.2.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:af5d3c00557d657c8773ef9ee702c61dd13b9d7426794c9dfeb1dc4a0bf0ebc7"}, - {file = "pandas-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:06cf591dbaefb6da9de8472535b185cba556d0ce2e6ed28e21d919704fef1a9e"}, - {file = "pandas-2.2.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:88ecb5c01bb9ca927ebc4098136038519aa5d66b44671861ffab754cae75102c"}, - {file = "pandas-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:04f6ec3baec203c13e3f8b139fb0f9f86cd8c0b94603ae3ae8ce9a422e9f5bee"}, - {file = "pandas-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a935a90a76c44fe170d01e90a3594beef9e9a6220021acfb26053d01426f7dc2"}, - {file = "pandas-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c391f594aae2fd9f679d419e9a4d5ba4bce5bb13f6a989195656e7dc4b95c8f0"}, - {file = "pandas-2.2.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9d1265545f579edf3f8f0cb6f89f234f5e44ba725a34d86535b1a1d38decbccc"}, - {file = "pandas-2.2.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:11940e9e3056576ac3244baef2fedade891977bcc1cb7e5cc8f8cc7d603edc89"}, - {file = "pandas-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:4acf681325ee1c7f950d058b05a820441075b0dd9a2adf5c4835b9bc056bf4fb"}, - {file = "pandas-2.2.1.tar.gz", hash = "sha256:0ab90f87093c13f3e8fa45b48ba9f39181046e8f3317d3aadb2fffbb1b978572"}, + {file = "pandas-2.2.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:696039430f7a562b74fa45f540aca068ea85fa34c244d0deee539cb6d70aa288"}, + {file = "pandas-2.2.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8e90497254aacacbc4ea6ae5e7a8cd75629d6ad2b30025a4a8b09aa4faf55151"}, + {file = "pandas-2.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:58b84b91b0b9f4bafac2a0ac55002280c094dfc6402402332c0913a59654ab2b"}, + {file = "pandas-2.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d2123dc9ad6a814bcdea0f099885276b31b24f7edf40f6cdbc0912672e22eee"}, + {file = "pandas-2.2.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:2925720037f06e89af896c70bca73459d7e6a4be96f9de79e2d440bd499fe0db"}, + {file = "pandas-2.2.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:0cace394b6ea70c01ca1595f839cf193df35d1575986e484ad35c4aeae7266c1"}, + {file = "pandas-2.2.2-cp311-cp311-win_amd64.whl", hash = "sha256:873d13d177501a28b2756375d59816c365e42ed8417b41665f346289adc68d24"}, + {file = "pandas-2.2.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:9dfde2a0ddef507a631dc9dc4af6a9489d5e2e740e226ad426a05cabfbd7c8ef"}, + {file = "pandas-2.2.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e9b79011ff7a0f4b1d6da6a61aa1aa604fb312d6647de5bad20013682d1429ce"}, + {file = "pandas-2.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1cb51fe389360f3b5a4d57dbd2848a5f033350336ca3b340d1c53a1fad33bcad"}, + {file = "pandas-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eee3a87076c0756de40b05c5e9a6069c035ba43e8dd71c379e68cab2c20f16ad"}, + {file = "pandas-2.2.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:3e374f59e440d4ab45ca2fffde54b81ac3834cf5ae2cdfa69c90bc03bde04d76"}, + {file = "pandas-2.2.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:43498c0bdb43d55cb162cdc8c06fac328ccb5d2eabe3cadeb3529ae6f0517c32"}, + {file = "pandas-2.2.2-cp312-cp312-win_amd64.whl", hash = "sha256:d187d355ecec3629624fccb01d104da7d7f391db0311145817525281e2804d23"}, + {file = "pandas-2.2.2.tar.gz", hash = "sha256:9e79019aba43cb4fda9e4d983f8e88ca0373adbb697ae9c6c43093218de28b54"}, ] [[package]] @@ -829,73 +829,73 @@ files = [ [[package]] name = "pydantic" -version = "2.6.4" +version = "2.7.0" requires_python = ">=3.8" summary = "Data validation using Python type hints" groups = ["default"] dependencies = [ "annotated-types>=0.4.0", - "pydantic-core==2.16.3", + "pydantic-core==2.18.1", "typing-extensions>=4.6.1", ] files = [ - {file = "pydantic-2.6.4-py3-none-any.whl", hash = "sha256:cc46fce86607580867bdc3361ad462bab9c222ef042d3da86f2fb333e1d916c5"}, - {file = "pydantic-2.6.4.tar.gz", hash = "sha256:b1704e0847db01817624a6b86766967f552dd9dbf3afba4004409f908dcc84e6"}, + {file = "pydantic-2.7.0-py3-none-any.whl", hash = "sha256:9dee74a271705f14f9a1567671d144a851c675b072736f0a7b2608fd9e495352"}, + {file = "pydantic-2.7.0.tar.gz", hash = "sha256:b5ecdd42262ca2462e2624793551e80911a1e989f462910bb81aef974b4bb383"}, ] [[package]] name = "pydantic-core" -version = "2.16.3" +version = "2.18.1" requires_python = ">=3.8" -summary = "" +summary = "Core functionality for Pydantic validation and serialization" groups = ["default"] dependencies = [ "typing-extensions!=4.7.0,>=4.6.0", ] files = [ - {file = "pydantic_core-2.16.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:519ae0312616026bf4cedc0fe459e982734f3ca82ee8c7246c19b650b60a5ee4"}, - {file = "pydantic_core-2.16.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:b3992a322a5617ded0a9f23fd06dbc1e4bd7cf39bc4ccf344b10f80af58beacd"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8d62da299c6ecb04df729e4b5c52dc0d53f4f8430b4492b93aa8de1f541c4aac"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2acca2be4bb2f2147ada8cac612f8a98fc09f41c89f87add7256ad27332c2fda"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1b662180108c55dfbf1280d865b2d116633d436cfc0bba82323554873967b340"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e7c6ed0dc9d8e65f24f5824291550139fe6f37fac03788d4580da0d33bc00c97"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a6b1bb0827f56654b4437955555dc3aeeebeddc47c2d7ed575477f082622c49e"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:e56f8186d6210ac7ece503193ec84104da7ceb98f68ce18c07282fcc2452e76f"}, - {file = "pydantic_core-2.16.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:936e5db01dd49476fa8f4383c259b8b1303d5dd5fb34c97de194560698cc2c5e"}, - {file = "pydantic_core-2.16.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:33809aebac276089b78db106ee692bdc9044710e26f24a9a2eaa35a0f9fa70ba"}, - {file = "pydantic_core-2.16.3-cp311-none-win32.whl", hash = "sha256:ded1c35f15c9dea16ead9bffcde9bb5c7c031bff076355dc58dcb1cb436c4721"}, - {file = "pydantic_core-2.16.3-cp311-none-win_amd64.whl", hash = "sha256:d89ca19cdd0dd5f31606a9329e309d4fcbb3df860960acec32630297d61820df"}, - {file = "pydantic_core-2.16.3-cp311-none-win_arm64.whl", hash = "sha256:6162f8d2dc27ba21027f261e4fa26f8bcb3cf9784b7f9499466a311ac284b5b9"}, - {file = "pydantic_core-2.16.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:0f56ae86b60ea987ae8bcd6654a887238fd53d1384f9b222ac457070b7ac4cff"}, - {file = "pydantic_core-2.16.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c9bd22a2a639e26171068f8ebb5400ce2c1bc7d17959f60a3b753ae13c632975"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4204e773b4b408062960e65468d5346bdfe139247ee5f1ca2a378983e11388a2"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f651dd19363c632f4abe3480a7c87a9773be27cfe1341aef06e8759599454120"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:aaf09e615a0bf98d406657e0008e4a8701b11481840be7d31755dc9f97c44053"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8e47755d8152c1ab5b55928ab422a76e2e7b22b5ed8e90a7d584268dd49e9c6b"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:500960cb3a0543a724a81ba859da816e8cf01b0e6aaeedf2c3775d12ee49cade"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:cf6204fe865da605285c34cf1172879d0314ff267b1c35ff59de7154f35fdc2e"}, - {file = "pydantic_core-2.16.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d33dd21f572545649f90c38c227cc8631268ba25c460b5569abebdd0ec5974ca"}, - {file = "pydantic_core-2.16.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:49d5d58abd4b83fb8ce763be7794d09b2f50f10aa65c0f0c1696c677edeb7cbf"}, - {file = "pydantic_core-2.16.3-cp312-none-win32.whl", hash = "sha256:f53aace168a2a10582e570b7736cc5bef12cae9cf21775e3eafac597e8551fbe"}, - {file = "pydantic_core-2.16.3-cp312-none-win_amd64.whl", hash = "sha256:0d32576b1de5a30d9a97f300cc6a3f4694c428d956adbc7e6e2f9cad279e45ed"}, - {file = "pydantic_core-2.16.3-cp312-none-win_arm64.whl", hash = "sha256:ec08be75bb268473677edb83ba71e7e74b43c008e4a7b1907c6d57e940bf34b6"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:36fa178aacbc277bc6b62a2c3da95226520da4f4e9e206fdf076484363895d2c"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:dcca5d2bf65c6fb591fff92da03f94cd4f315972f97c21975398bd4bd046854a"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2a72fb9963cba4cd5793854fd12f4cfee731e86df140f59ff52a49b3552db241"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b60cc1a081f80a2105a59385b92d82278b15d80ebb3adb200542ae165cd7d183"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:cbcc558401de90a746d02ef330c528f2e668c83350f045833543cd57ecead1ad"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:fee427241c2d9fb7192b658190f9f5fd6dfe41e02f3c1489d2ec1e6a5ab1e04a"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:f4cb85f693044e0f71f394ff76c98ddc1bc0953e48c061725e540396d5c8a2e1"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:b29eeb887aa931c2fcef5aa515d9d176d25006794610c264ddc114c053bf96fe"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:a425479ee40ff021f8216c9d07a6a3b54b31c8267c6e17aa88b70d7ebd0e5e5b"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:5c5cbc703168d1b7a838668998308018a2718c2130595e8e190220238addc96f"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:99b6add4c0b39a513d323d3b93bc173dac663c27b99860dd5bf491b240d26137"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:75f76ee558751746d6a38f89d60b6228fa174e5172d143886af0f85aa306fd89"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:00ee1c97b5364b84cb0bd82e9bbf645d5e2871fb8c58059d158412fee2d33d8a"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:287073c66748f624be4cef893ef9174e3eb88fe0b8a78dc22e88eca4bc357ca6"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:ed25e1835c00a332cb10c683cd39da96a719ab1dfc08427d476bce41b92531fc"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:86b3d0033580bd6bbe07590152007275bd7af95f98eaa5bd36f3da219dcd93da"}, - {file = "pydantic_core-2.16.3.tar.gz", hash = "sha256:1cac689f80a3abab2d3c0048b29eea5751114054f032a941a32de4c852c59cad"}, + {file = "pydantic_core-2.18.1-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:9ece8a49696669d483d206b4474c367852c44815fca23ac4e48b72b339807f80"}, + {file = "pydantic_core-2.18.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7a5d83efc109ceddb99abd2c1316298ced2adb4570410defe766851a804fcd5b"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5f7973c381283783cd1043a8c8f61ea5ce7a3a58b0369f0ee0ee975eaf2f2a1b"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:54c7375c62190a7845091f521add19b0f026bcf6ae674bdb89f296972272e86d"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dd63cec4e26e790b70544ae5cc48d11b515b09e05fdd5eff12e3195f54b8a586"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:561cf62c8a3498406495cfc49eee086ed2bb186d08bcc65812b75fda42c38294"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68717c38a68e37af87c4da20e08f3e27d7e4212e99e96c3d875fbf3f4812abfc"}, + {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2d5728e93d28a3c63ee513d9ffbac9c5989de8c76e049dbcb5bfe4b923a9739d"}, + {file = "pydantic_core-2.18.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:f0f17814c505f07806e22b28856c59ac80cee7dd0fbb152aed273e116378f519"}, + {file = "pydantic_core-2.18.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d816f44a51ba5175394bc6c7879ca0bd2be560b2c9e9f3411ef3a4cbe644c2e9"}, + {file = "pydantic_core-2.18.1-cp311-none-win32.whl", hash = "sha256:09f03dfc0ef8c22622eaa8608caa4a1e189cfb83ce847045eca34f690895eccb"}, + {file = "pydantic_core-2.18.1-cp311-none-win_amd64.whl", hash = "sha256:27f1009dc292f3b7ca77feb3571c537276b9aad5dd4efb471ac88a8bd09024e9"}, + {file = "pydantic_core-2.18.1-cp311-none-win_arm64.whl", hash = "sha256:48dd883db92e92519201f2b01cafa881e5f7125666141a49ffba8b9facc072b0"}, + {file = "pydantic_core-2.18.1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:b6b0e4912030c6f28bcb72b9ebe4989d6dc2eebcd2a9cdc35fefc38052dd4fe8"}, + {file = "pydantic_core-2.18.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f3202a429fe825b699c57892d4371c74cc3456d8d71b7f35d6028c96dfecad31"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a3982b0a32d0a88b3907e4b0dc36809fda477f0757c59a505d4e9b455f384b8b"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:25595ac311f20e5324d1941909b0d12933f1fd2171075fcff763e90f43e92a0d"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:14fe73881cf8e4cbdaded8ca0aa671635b597e42447fec7060d0868b52d074e6"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ca976884ce34070799e4dfc6fbd68cb1d181db1eefe4a3a94798ddfb34b8867f"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:684d840d2c9ec5de9cb397fcb3f36d5ebb6fa0d94734f9886032dd796c1ead06"}, + {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:54764c083bbe0264f0f746cefcded6cb08fbbaaf1ad1d78fb8a4c30cff999a90"}, + {file = "pydantic_core-2.18.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:201713f2f462e5c015b343e86e68bd8a530a4f76609b33d8f0ec65d2b921712a"}, + {file = "pydantic_core-2.18.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:fd1a9edb9dd9d79fbeac1ea1f9a8dd527a6113b18d2e9bcc0d541d308dae639b"}, + {file = "pydantic_core-2.18.1-cp312-none-win32.whl", hash = "sha256:d5e6b7155b8197b329dc787356cfd2684c9d6a6b1a197f6bbf45f5555a98d411"}, + {file = "pydantic_core-2.18.1-cp312-none-win_amd64.whl", hash = "sha256:9376d83d686ec62e8b19c0ac3bf8d28d8a5981d0df290196fb6ef24d8a26f0d6"}, + {file = "pydantic_core-2.18.1-cp312-none-win_arm64.whl", hash = "sha256:c562b49c96906b4029b5685075fe1ebd3b5cc2601dfa0b9e16c2c09d6cbce048"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:e178e5b66a06ec5bf51668ec0d4ac8cfb2bdcb553b2c207d58148340efd00143"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:72722ce529a76a4637a60be18bd789d8fb871e84472490ed7ddff62d5fed620d"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2fe0c1ce5b129455e43f941f7a46f61f3d3861e571f2905d55cdbb8b5c6f5e2c"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4284c621f06a72ce2cb55f74ea3150113d926a6eb78ab38340c08f770eb9b4d"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:1a0c3e718f4e064efde68092d9d974e39572c14e56726ecfaeebbe6544521f47"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:2027493cc44c23b598cfaf200936110433d9caa84e2c6cf487a83999638a96ac"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:76909849d1a6bffa5a07742294f3fa1d357dc917cb1fe7b470afbc3a7579d539"}, + {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:ee7ccc7fb7e921d767f853b47814c3048c7de536663e82fbc37f5eb0d532224b"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:ee2794111c188548a4547eccc73a6a8527fe2af6cf25e1a4ebda2fd01cdd2e60"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:a139fe9f298dc097349fb4f28c8b81cc7a202dbfba66af0e14be5cfca4ef7ce5"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d074b07a10c391fc5bbdcb37b2f16f20fcd9e51e10d01652ab298c0d07908ee2"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c69567ddbac186e8c0aadc1f324a60a564cfe25e43ef2ce81bcc4b8c3abffbae"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:baf1c7b78cddb5af00971ad5294a4583188bda1495b13760d9f03c9483bb6203"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:2684a94fdfd1b146ff10689c6e4e815f6a01141781c493b97342cdc5b06f4d5d"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:73c1bc8a86a5c9e8721a088df234265317692d0b5cd9e86e975ce3bc3db62a59"}, + {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:e60defc3c15defb70bb38dd605ff7e0fae5f6c9c7cbfe0ad7868582cb7e844a6"}, + {file = "pydantic_core-2.18.1.tar.gz", hash = "sha256:de9d3e8717560eb05e28739d1b35e4eac2e458553a52a301e51352a7ffc86a35"}, ] [[package]] @@ -1049,28 +1049,28 @@ files = [ [[package]] name = "ruff" -version = "0.3.5" +version = "0.3.7" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["dev"] files = [ - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:aef5bd3b89e657007e1be6b16553c8813b221ff6d92c7526b7e0227450981eac"}, - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:89b1e92b3bd9fca249153a97d23f29bed3992cff414b222fcd361d763fc53f12"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5e55771559c89272c3ebab23326dc23e7f813e492052391fe7950c1a5a139d89"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dabc62195bf54b8a7876add6e789caae0268f34582333cda340497c886111c39"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3a05f3793ba25f194f395578579c546ca5d83e0195f992edc32e5907d142bfa3"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dfd3504e881082959b4160ab02f7a205f0fadc0a9619cc481982b6837b2fd4c0"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:87258e0d4b04046cf1d6cc1c56fadbf7a880cc3de1f7294938e923234cf9e498"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:712e71283fc7d9f95047ed5f793bc019b0b0a29849b14664a60fd66c23b96da1"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a532a90b4a18d3f722c124c513ffb5e5eaff0cc4f6d3aa4bda38e691b8600c9f"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:122de171a147c76ada00f76df533b54676f6e321e61bd8656ae54be326c10296"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d80a6b18a6c3b6ed25b71b05eba183f37d9bc8b16ace9e3d700997f00b74660b"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7b6e63194c68bca8e71f81de30cfa6f58ff70393cf45aab4c20f158227d5936"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a759d33a20c72f2dfa54dae6e85e1225b8e302e8ac655773aff22e542a300985"}, - {file = "ruff-0.3.5-py3-none-win32.whl", hash = "sha256:9d8605aa990045517c911726d21293ef4baa64f87265896e491a05461cae078d"}, - {file = "ruff-0.3.5-py3-none-win_amd64.whl", hash = "sha256:dc56bb16a63c1303bd47563c60482a1512721053d93231cf7e9e1c6954395a0e"}, - {file = "ruff-0.3.5-py3-none-win_arm64.whl", hash = "sha256:faeeae9905446b975dcf6d4499dc93439b131f1443ee264055c5716dd947af55"}, - {file = "ruff-0.3.5.tar.gz", hash = "sha256:a067daaeb1dc2baf9b82a32dae67d154d95212080c80435eb052d95da647763d"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, + {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, + {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, + {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, + {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 246ae61..4907f9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,9 +10,9 @@ requires-python = "<3.13,>=3.11" dependencies = [ "fastapi>=0.110.1", "httpx>=0.27.0", - "mex-common@git+https://github.com/robert-koch-institut/mex-common.git@0.22.0", + "mex-common@git+https://github.com/robert-koch-institut/mex-common.git@0.24.0", "neo4j>=5.18.0", - "pydantic>=2.6.4", + "pydantic>=2.7.0", "uvicorn[standard]>=0.29.0", ] optional-dependencies.dev = [ @@ -22,7 +22,7 @@ optional-dependencies.dev = [ "pytest-cov>=4.1.0", "pytest-random-order>=1.1.1", "pytest>=8.1.1", - "ruff>=0.3.3", + "ruff>=0.3.7", "sphinx>=7.2.6", "types-pytz>=2024.1.0", ] diff --git a/tests/conftest.py b/tests/conftest.py index 465b28b..d2a7583 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -161,7 +161,7 @@ def isolate_graph_database( is_integration_test: bool, settings: BackendSettings ) -> None: """Automatically flush the graph database for integration testing.""" - if is_integration_test: + if is_integration_test: # pragma: no cover with GraphDatabase.driver( settings.graph_url, auth=( From de72b96ea552b4d3cb280ebec99ab8b0ef7ec444 Mon Sep 17 00:00:00 2001 From: Nicolas Drebenstedt Date: Thu, 16 May 2024 15:50:16 +0200 Subject: [PATCH 2/5] WIP --- mex/backend/security.py | 8 ++-- tests/conftest.py | 3 +- tests/extracted/test_main.py | 12 ++--- tests/identity/test_provider.py | 8 ++-- tests/test_exceptions.py | 62 +++++++++++++++++++++++++ tests/test_main.py | 81 +-------------------------------- 6 files changed, 78 insertions(+), 96 deletions(-) create mode 100644 tests/test_exceptions.py diff --git a/mex/backend/security.py b/mex/backend/security.py index 55c839c..e2a6294 100644 --- a/mex/backend/security.py +++ b/mex/backend/security.py @@ -77,9 +77,9 @@ def has_write_access( can_write = False if api_key: api_key_database = settings.backend_api_key_database - can_write = APIKey(api_key) in api_key_database.write + can_write = APIKey(api_key) in api_key_database["write"] elif credentials: - api_write_user_db = settings.backend_user_database.write + api_write_user_db = settings.backend_user_database["write"] user, pw = credentials.username, credentials.password.encode("utf-8") if api_write_user := api_write_user_db.get(user): can_write = compare_digest( @@ -130,9 +130,9 @@ def has_read_access( can_read = False if api_key: api_key_database = settings.backend_api_key_database - can_read = APIKey(api_key) in api_key_database.read + can_read = APIKey(api_key) in api_key_database["read"] elif credentials: - api_read_user_db = settings.backend_user_database.read + api_read_user_db = settings.backend_user_database["read"] user, pw = credentials.username, credentials.password.encode("utf-8") if api_read_user := api_read_user_db.get(user): can_read = compare_digest( diff --git a/tests/conftest.py b/tests/conftest.py index d2a7583..ac95646 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,7 +33,6 @@ TextLanguage, Theme, ) -from mex.common.types.identifier import IdentifierT pytest_plugins = ("mex.common.testing.plugin",) @@ -142,7 +141,7 @@ def isolate_identifier_seeds(monkeypatch: MonkeyPatch) -> None: counter = count() original_generate = Identifier.generate - def generate(cls: type[IdentifierT], seed: int | None = None) -> IdentifierT: + def generate(cls: type[Identifier], seed: int | None = None) -> Identifier: return cls(original_generate(seed or next(counter))) monkeypatch.setattr(Identifier, "generate", classmethod(generate)) diff --git a/tests/extracted/test_main.py b/tests/extracted/test_main.py index 701e0b9..08e7f48 100644 --- a/tests/extracted/test_main.py +++ b/tests/extracted/test_main.py @@ -111,18 +111,18 @@ def test_search_extracted_items_mocked( { "$type": "ExtractedContactPoint", "email": ["info@contact-point.one"], - "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUu", + "hadPrimarySource": "gGdOIbDIHRt35He616Fv5q", + "identifier": "gs6yL8KJoXRos9l2ydYFfx", "identifierInPrimarySource": "cp-1", - "stableTargetId": "bFQoRhcVH5DHUv", + "stableTargetId": "wEvxYRPlmGVQCbZx9GAbn", }, { "$type": "ExtractedContactPoint", "email": ["help@contact-point.two"], - "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUw", + "hadPrimarySource": "gGdOIbDIHRt35He616Fv5q", + "identifier": "vQHKlAQWWraW9NPoB5Ewq", "identifierInPrimarySource": "cp-2", - "stableTargetId": "bFQoRhcVH5DHUx", + "stableTargetId": "g32qzYNVH1Ez7JTEk3fvLF", }, ], "total": 2, diff --git a/tests/identity/test_provider.py b/tests/identity/test_provider.py index 5cba1d2..bde9311 100644 --- a/tests/identity/test_provider.py +++ b/tests/identity/test_provider.py @@ -26,9 +26,9 @@ "new-item", { "hadPrimarySource": "psSti00000000001", - "identifier": "bFQoRhcVH5DHUq", + "identifier": "sMgFvmdtJyegb9vkebq04", "identifierInPrimarySource": "new-item", - "stableTargetId": "bFQoRhcVH5DHUr", + "stableTargetId": "gGdOIbDIHRt35He616Fv5q", }, ), ( @@ -101,9 +101,9 @@ def test_assign_identity_inconsistency_mocked( "new-item", { "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUC", + "identifier": "bFQoRhcVH5DHUq", "identifierInPrimarySource": "new-item", - "stableTargetId": "bFQoRhcVH5DHUD", + "stableTargetId": "bFQoRhcVH5DHUr", }, ), ( diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000..e5690aa --- /dev/null +++ b/tests/test_exceptions.py @@ -0,0 +1,62 @@ +import json +from typing import Any +from unittest.mock import Mock + +import pydantic_core +import pytest +from pydantic import ValidationError + +from mex.backend.main import handle_uncaught_exception +from mex.common.exceptions import MExError + + +@pytest.mark.parametrize( + ("exception", "expected"), + [ + ( + TypeError("foo"), + {"debug": {"errors": [{"type": "TypeError"}]}, "message": "foo"}, + ), + ( + ValidationError.from_exception_data( + "foo", + [ + { + "type": pydantic_core.PydanticCustomError( + "TestError", "You messed up!" + ), + "loc": ("integerAttribute",), + "input": "mumbojumbo", + } + ], + ), + { + "debug": { + "errors": [ + { + "input": "mumbojumbo", + "loc": ["integerAttribute"], + "msg": "You messed up!", + "type": "TestError", + } + ] + }, + "message": "1 validation error for foo\n" + "integerAttribute\n" + " You messed up! [type=TestError, input_value='mumbojumbo', " + "input_type=str]", + }, + ), + ( + MExError("bar"), + {"message": "MExError: bar ", "debug": {"errors": [{"type": "MExError"}]}}, + ), + ], + ids=["TypeError", "ValidationError", "MExError"], +) +def test_handle_uncaught_exception( + exception: Exception, expected: dict[str, Any] +) -> None: + response = handle_uncaught_exception(Mock(), exception) + assert response.status_code == 500, response.body + assert json.loads(response.body) == expected diff --git a/tests/test_main.py b/tests/test_main.py index b7f7462..6d217d5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,23 +1,9 @@ -import json -import logging -from typing import Any -from unittest.mock import MagicMock, Mock - -import pydantic_core import pytest from fastapi.testclient import TestClient from neo4j import GraphDatabase -from pydantic import ValidationError -from pytest import LogCaptureFixture -from mex.backend.main import ( - app, - close_connectors, - handle_uncaught_exception, -) +from mex.backend.main import app from mex.backend.settings import BackendSettings -from mex.common.connector import ConnectorContext -from mex.common.exceptions import MExError def test_openapi_schema(client: TestClient) -> None: @@ -44,71 +30,6 @@ def test_health_check(client: TestClient) -> None: assert response.json() == {"status": "ok"} -@pytest.mark.parametrize( - ("exception", "expected"), - [ - ( - TypeError("foo"), - {"debug": {"errors": [{"type": "TypeError"}]}, "message": "foo"}, - ), - ( - ValidationError.from_exception_data( - "foo", - [ - { - "type": pydantic_core.PydanticCustomError( - "TestError", "You messed up!" - ), - "loc": ("integerAttribute",), - "input": "mumbojumbo", - } - ], - ), - { - "debug": { - "errors": [ - { - "input": "mumbojumbo", - "loc": ["integerAttribute"], - "msg": "You messed up!", - "type": "TestError", - } - ] - }, - "message": "1 validation error for foo\n" - "integerAttribute\n" - " You messed up! [type=TestError, input_value='mumbojumbo', " - "input_type=str]", - }, - ), - ( - MExError("bar"), - {"message": "MExError: bar ", "debug": {"errors": [{"type": "MExError"}]}}, - ), - ], - ids=["TypeError", "ValidationError", "MExError"], -) -def test_handle_uncaught_exception( - exception: Exception, expected: dict[str, Any] -) -> None: - response = handle_uncaught_exception(Mock(), exception) - assert response.status_code == 500, response.body - assert json.loads(response.body) == expected - - -def test_close_all_connectors(caplog: LogCaptureFixture) -> None: - context = { - "ConnectorA": Mock(close=MagicMock()), - "ConnectorB": Mock(close=MagicMock(side_effect=Exception())), - } - ConnectorContext.set(context) - - with caplog.at_level(logging.INFO): - close_connectors() - assert "Closed ConnectorA" in caplog.text - assert "Error closing ConnectorB" in caplog.text - - def test_all_endpoints_require_authorization(client: TestClient) -> None: excluded_routes = [ "/openapi.json", From 6269888c9c62f4fe44c10046dadf00f5e39d5312 Mon Sep 17 00:00:00 2001 From: Nicolas Drebenstedt Date: Fri, 24 May 2024 18:00:30 +0200 Subject: [PATCH 3/5] fix tests --- .pre-commit-config.yaml | 6 ++-- mex/backend/graph/connector.py | 2 +- mex/backend/graph/models.py | 2 +- pdm.lock | 52 ++++++++++++++++----------------- pyproject.toml | 4 +-- requirements.txt | 2 +- tests/conftest.py | 20 ++++++++----- tests/extracted/test_main.py | 34 ++++++++++----------- tests/identity/test_main.py | 20 ++++++------- tests/identity/test_provider.py | 20 ++++++------- tests/merged/test_main.py | 10 +++---- 11 files changed, 89 insertions(+), 83 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b48c13..67785b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,11 +3,11 @@ default_language_version: python: python3.11 repos: - repo: https://github.com/psf/black - rev: 24.3.0 + rev: 24.4.2 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.7 + rev: v0.4.5 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -28,7 +28,7 @@ repos: - id: fix-byte-order-marker name: byte-order - repo: https://github.com/pdm-project/pdm - rev: 2.13.2 + rev: 2.15.3 hooks: - id: pdm-lock-check name: pdm diff --git a/mex/backend/graph/connector.py b/mex/backend/graph/connector.py index 9619e25..89abf48 100644 --- a/mex/backend/graph/connector.py +++ b/mex/backend/graph/connector.py @@ -71,7 +71,7 @@ def _check_connectivity_and_authentication(self) -> Result: query_builder = QueryBuilder.get() result = self.commit(query_builder.fetch_database_status()) if (status := result["currentStatus"]) != "online": - raise MExError(f"Database is {status}.") + raise MExError(f"Database is {status}.") from None return result def _seed_constraints(self) -> list[Result]: diff --git a/mex/backend/graph/models.py b/mex/backend/graph/models.py index 73c86de..05d8dca 100644 --- a/mex/backend/graph/models.py +++ b/mex/backend/graph/models.py @@ -61,7 +61,7 @@ def one_or_none(self) -> dict[str, Any] | None: case 0: return None case _: - raise MultipleResultsFoundError + raise MultipleResultsFoundError from None def get_update_counters(self) -> dict[str, int]: """Return a summary of counters for operations the query triggered.""" diff --git a/pdm.lock b/pdm.lock index cf41bc8..2b96c44 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:8126073ff026f592c463a40d146898fddd2c9f3f0743b52f252a0c7d2fe3b2d0" +content_hash = "sha256:816abd48ef2201261101ed22dedc0e649b7064905bec53a3573710fa6369b822" [[package]] name = "alabaster" @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "mex-model" version = "2.3.0" -requires_python = ">=3.11,<4.0" +requires_python = "<4.0,>=3.11" git = "https://github.com/robert-koch-institut/mex-model.git" ref = "2.3.0" revision = "d4aba623fc54f9b0f1b412408a21e62b6913f875" @@ -1027,7 +1027,7 @@ files = [ [[package]] name = "pytest" -version = "8.2.0" +version = "8.2.1" requires_python = ">=3.8" summary = "pytest: simple powerful testing with Python" groups = ["dev"] @@ -1038,8 +1038,8 @@ dependencies = [ "pluggy<2.0,>=1.5", ] files = [ - {file = "pytest-8.2.0-py3-none-any.whl", hash = "sha256:1733f0620f6cda4095bbf0d9ff8022486e91892245bb9e7d5542c018f612f233"}, - {file = "pytest-8.2.0.tar.gz", hash = "sha256:d507d4482197eac0ba2bae2e9babf0672eb333017bcedaa5fb1a3d42c1174b3f"}, + {file = "pytest-8.2.1-py3-none-any.whl", hash = "sha256:faccc5d332b8c3719f40283d0d44aa5cf101cec36f88cde9ed8f2bc0538612b1"}, + {file = "pytest-8.2.1.tar.gz", hash = "sha256:5046e5b46d8e4cac199c373041f26be56fdb81eb4e67dc11d4e10811fc3408fd"}, ] [[package]] @@ -1176,28 +1176,28 @@ files = [ [[package]] name = "ruff" -version = "0.4.4" +version = "0.4.5" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["dev"] files = [ - {file = "ruff-0.4.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:29d44ef5bb6a08e235c8249294fa8d431adc1426bfda99ed493119e6f9ea1bf6"}, - {file = "ruff-0.4.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:c4efe62b5bbb24178c950732ddd40712b878a9b96b1d02b0ff0b08a090cbd891"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4c8e2f1e8fc12d07ab521a9005d68a969e167b589cbcaee354cb61e9d9de9c15"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:60ed88b636a463214905c002fa3eaab19795679ed55529f91e488db3fe8976ab"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b90fc5e170fc71c712cc4d9ab0e24ea505c6a9e4ebf346787a67e691dfb72e85"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:8e7e6ebc10ef16dcdc77fd5557ee60647512b400e4a60bdc4849468f076f6eef"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b9ddb2c494fb79fc208cd15ffe08f32b7682519e067413dbaf5f4b01a6087bcd"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c51c928a14f9f0a871082603e25a1588059b7e08a920f2f9fa7157b5bf08cfe9"}, - {file = "ruff-0.4.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b5eb0a4bfd6400b7d07c09a7725e1a98c3b838be557fee229ac0f84d9aa49c36"}, - {file = "ruff-0.4.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b1867ee9bf3acc21778dcb293db504692eda5f7a11a6e6cc40890182a9f9e595"}, - {file = "ruff-0.4.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:1aecced1269481ef2894cc495647392a34b0bf3e28ff53ed95a385b13aa45768"}, - {file = "ruff-0.4.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9da73eb616b3241a307b837f32756dc20a0b07e2bcb694fec73699c93d04a69e"}, - {file = "ruff-0.4.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:958b4ea5589706a81065e2a776237de2ecc3e763342e5cc8e02a4a4d8a5e6f95"}, - {file = "ruff-0.4.4-py3-none-win32.whl", hash = "sha256:cb53473849f011bca6e754f2cdf47cafc9c4f4ff4570003a0dad0b9b6890e876"}, - {file = "ruff-0.4.4-py3-none-win_amd64.whl", hash = "sha256:424e5b72597482543b684c11def82669cc6b395aa8cc69acc1858b5ef3e5daae"}, - {file = "ruff-0.4.4-py3-none-win_arm64.whl", hash = "sha256:39df0537b47d3b597293edbb95baf54ff5b49589eb7ff41926d8243caa995ea6"}, - {file = "ruff-0.4.4.tar.gz", hash = "sha256:f87ea42d5cdebdc6a69761a9d0bc83ae9b3b30d0ad78952005ba6568d6c022af"}, + {file = "ruff-0.4.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:8f58e615dec58b1a6b291769b559e12fdffb53cc4187160a2fc83250eaf54e96"}, + {file = "ruff-0.4.5-py3-none-macosx_11_0_arm64.whl", hash = "sha256:84dd157474e16e3a82745d2afa1016c17d27cb5d52b12e3d45d418bcc6d49264"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:25f483ad9d50b00e7fd577f6d0305aa18494c6af139bce7319c68a17180087f4"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:63fde3bf6f3ad4e990357af1d30e8ba2730860a954ea9282c95fc0846f5f64af"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:78e3ba4620dee27f76bbcad97067766026c918ba0f2d035c2fc25cbdd04d9c97"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:441dab55c568e38d02bbda68a926a3d0b54f5510095c9de7f95e47a39e0168aa"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1169e47e9c4136c997f08f9857ae889d614c5035d87d38fda9b44b4338909cdf"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:755ac9ac2598a941512fc36a9070a13c88d72ff874a9781493eb237ab02d75df"}, + {file = "ruff-0.4.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f4b02a65985be2b34b170025a8b92449088ce61e33e69956ce4d316c0fe7cce0"}, + {file = "ruff-0.4.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:75a426506a183d9201e7e5664de3f6b414ad3850d7625764106f7b6d0486f0a1"}, + {file = "ruff-0.4.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:6e1b139b45e2911419044237d90b60e472f57285950e1492c757dfc88259bb06"}, + {file = "ruff-0.4.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a6f29a8221d2e3d85ff0c7b4371c0e37b39c87732c969b4d90f3dad2e721c5b1"}, + {file = "ruff-0.4.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:d6ef817124d72b54cc923f3444828ba24fa45c3164bc9e8f1813db2f3d3a8a11"}, + {file = "ruff-0.4.5-py3-none-win32.whl", hash = "sha256:aed8166c18b1a169a5d3ec28a49b43340949e400665555b51ee06f22813ef062"}, + {file = "ruff-0.4.5-py3-none-win_amd64.whl", hash = "sha256:b0b03c619d2b4350b4a27e34fd2ac64d0dabe1afbf43de57d0f9d8a05ecffa45"}, + {file = "ruff-0.4.5-py3-none-win_arm64.whl", hash = "sha256:9d15de3425f53161b3f5a5658d4522e4eee5ea002bf2ac7aa380743dd9ad5fba"}, + {file = "ruff-0.4.5.tar.gz", hash = "sha256:286eabd47e7d4d521d199cab84deca135557e6d1e0f0d01c29e757c3cb151b54"}, ] [[package]] @@ -1410,13 +1410,13 @@ files = [ [[package]] name = "typing-extensions" -version = "4.11.0" +version = "4.12.0" requires_python = ">=3.8" summary = "Backported and Experimental Type Hints for Python 3.8+" groups = ["default", "dev"] files = [ - {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"}, - {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"}, + {file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"}, + {file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 40dcc31..7c36549 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,8 +21,8 @@ optional-dependencies.dev = [ "mypy==1.10.0", "pytest-cov==5.0.0", "pytest-random-order==1.1.1", - "pytest==8.2.0", - "ruff==0.4.4", + "pytest==8.2.1", + "ruff==0.4.5", "sphinx==7.3.7", "types-pytz==2024.1.0.20240417", ] diff --git a/requirements.txt b/requirements.txt index 712004a..21929f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ cruft==2.15.0 -pdm==2.15.2 +pdm==2.15.3 pre-commit==3.7.1 wheel==0.43.0 diff --git a/tests/conftest.py b/tests/conftest.py index ac95646..3710c5d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,7 +13,7 @@ from mex.backend.graph.connector import GraphConnector from mex.backend.main import app from mex.backend.settings import BackendSettings -from mex.backend.types import APIKeyDatabase, APIUserDatabase +from mex.backend.types import APIKeyDatabase, APIUserDatabase, BackendIdentityProvider from mex.common.models import ( MEX_PRIMARY_SOURCE_STABLE_TARGET_ID, AnyExtractedModel, @@ -58,7 +58,7 @@ def skip_integration_test_in_ci(is_integration_test: bool) -> None: @pytest.fixture def client() -> TestClient: """Return a fastAPI test client initialized with our app.""" - with TestClient(app) as test_client: + with TestClient(app, raise_server_exceptions=False) as test_client: return test_client @@ -148,11 +148,17 @@ def generate(cls: type[Identifier], seed: int | None = None) -> Identifier: @pytest.fixture(autouse=True) -def set_identity_provider(is_integration_test: bool) -> None: - """Ensure the identifier provider is set to `MEMORY` in unit tests.""" - if not is_integration_test: - settings = BaseSettings.get() - settings.identity_provider = IdentityProvider.MEMORY +def set_identity_provider(is_integration_test: bool, monkeypatch: MonkeyPatch) -> None: + """Ensure the identifier provider is set correctly for unit and int tests.""" + settings = BaseSettings.get() + if is_integration_test: + # yuck, all this needs cleaning up after MX-1596 + monkeypatch.setitem(settings.model_config, "validate_assignment", False) + monkeypatch.setattr( + settings, "identity_provider", BackendIdentityProvider.GRAPH + ) + else: + monkeypatch.setattr(settings, "identity_provider", IdentityProvider.MEMORY) @pytest.fixture(autouse=True) diff --git a/tests/extracted/test_main.py b/tests/extracted/test_main.py index 31eadbe..087bc41 100644 --- a/tests/extracted/test_main.py +++ b/tests/extracted/test_main.py @@ -93,12 +93,12 @@ def test_search_extracted_items_mocked( { "items": [ { - "hadPrimarySource": "gGdOIbDIHRt35He616Fv5q", - "identifierInPrimarySource": "cp-1", - "email": ["info@contact-point.one"], "$type": "ExtractedContactPoint", - "identifier": "gs6yL8KJoXRos9l2ydYFfx", - "stableTargetId": "wEvxYRPlmGVQCbZx9GAbn", + "email": ["info@contact-point.one"], + "hadPrimarySource": "bFQoRhcVH5DHUr", + "identifier": "bFQoRhcVH5DHUu", + "identifierInPrimarySource": "cp-1", + "stableTargetId": "bFQoRhcVH5DHUv", } ], "total": 7, @@ -111,18 +111,18 @@ def test_search_extracted_items_mocked( { "$type": "ExtractedContactPoint", "email": ["info@contact-point.one"], - "hadPrimarySource": "gGdOIbDIHRt35He616Fv5q", - "identifier": "gs6yL8KJoXRos9l2ydYFfx", + "hadPrimarySource": "bFQoRhcVH5DHUr", + "identifier": "bFQoRhcVH5DHUu", "identifierInPrimarySource": "cp-1", - "stableTargetId": "wEvxYRPlmGVQCbZx9GAbn", + "stableTargetId": "bFQoRhcVH5DHUv", }, { "$type": "ExtractedContactPoint", "email": ["help@contact-point.two"], - "hadPrimarySource": "gGdOIbDIHRt35He616Fv5q", - "identifier": "vQHKlAQWWraW9NPoB5Ewq", + "hadPrimarySource": "bFQoRhcVH5DHUr", + "identifier": "bFQoRhcVH5DHUw", "identifierInPrimarySource": "cp-2", - "stableTargetId": "g32qzYNVH1Ez7JTEk3fvLF", + "stableTargetId": "bFQoRhcVH5DHUx", }, ], "total": 2, @@ -139,10 +139,10 @@ def test_search_extracted_items_mocked( "description": [], "documentation": [], "hadPrimarySource": "00000000000000", - "identifier": "d0MGZryflsy7PbsBF3ZGXO", + "identifier": "bFQoRhcVH5DHUs", "identifierInPrimarySource": "ps-2", "locatedAt": [], - "stableTargetId": "bbTqJnQc3TA8dBJmLMBimb", + "stableTargetId": "bFQoRhcVH5DHUt", "title": [], "unitInCharge": [], "version": "Cool Version v2.13", @@ -152,20 +152,20 @@ def test_search_extracted_items_mocked( }, ), ( - "?stableTargetId=cWWm02l1c6cucKjIhkFqY4", + "?stableTargetId=bFQoRhcVH5DHUz", { "items": [ { "$type": "ExtractedOrganizationalUnit", "alternativeName": [], "email": [], - "hadPrimarySource": "bbTqJnQc3TA8dBJmLMBimb", - "identifier": "gIyDlXYbq0JwItPRU0NcFN", + "hadPrimarySource": "bFQoRhcVH5DHUt", + "identifier": "bFQoRhcVH5DHUy", "identifierInPrimarySource": "ou-1", "name": [{"language": "en", "value": "Unit 1"}], "parentUnit": None, "shortName": [], - "stableTargetId": "cWWm02l1c6cucKjIhkFqY4", + "stableTargetId": "bFQoRhcVH5DHUz", "unitOf": [], "website": [], } diff --git a/tests/identity/test_main.py b/tests/identity/test_main.py index 89d398b..078ae76 100644 --- a/tests/identity/test_main.py +++ b/tests/identity/test_main.py @@ -102,9 +102,9 @@ def test_assign_identity_inconsistency_mocked( }, { "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUq", + "identifier": "bFQoRhcVH5DHUC", "identifierInPrimarySource": "new-item", - "stableTargetId": "bFQoRhcVH5DHUr", + "stableTargetId": "bFQoRhcVH5DHUD", }, ), ( @@ -114,9 +114,9 @@ def test_assign_identity_inconsistency_mocked( }, { "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUq", + "identifier": "bFQoRhcVH5DHUw", "identifierInPrimarySource": "cp-2", - "stableTargetId": "bFQoRhcVH5DHUr", + "stableTargetId": "bFQoRhcVH5DHUx", }, ), ( @@ -232,23 +232,23 @@ def test_fetch_identities_mocked( "items": [ { "hadPrimarySource": "00000000000000", - "identifier": "sMgFvmdtJyegb9vkebq04", + "identifier": "bFQoRhcVH5DHUq", "identifierInPrimarySource": "ps-1", - "stableTargetId": "gGdOIbDIHRt35He616Fv5q", + "stableTargetId": "bFQoRhcVH5DHUr", } ], "total": 1, }, ), ( - "?stableTargetId=cWWm02l1c6cucKjIhkFqY4", + "?stableTargetId=bFQoRhcVH5DHUz", { "items": [ { - "identifier": "gIyDlXYbq0JwItPRU0NcFN", - "hadPrimarySource": "bbTqJnQc3TA8dBJmLMBimb", + "identifier": "bFQoRhcVH5DHUy", + "hadPrimarySource": "bFQoRhcVH5DHUt", "identifierInPrimarySource": "ou-1", - "stableTargetId": "cWWm02l1c6cucKjIhkFqY4", + "stableTargetId": "bFQoRhcVH5DHUz", } ], "total": 1, diff --git a/tests/identity/test_provider.py b/tests/identity/test_provider.py index ce62e64..5cba1d2 100644 --- a/tests/identity/test_provider.py +++ b/tests/identity/test_provider.py @@ -101,19 +101,19 @@ def test_assign_identity_inconsistency_mocked( "new-item", { "hadPrimarySource": "bFQoRhcVH5DHUr", - "identifier": "bFQoRhcVH5DHUq", + "identifier": "bFQoRhcVH5DHUC", "identifierInPrimarySource": "new-item", - "stableTargetId": "bFQoRhcVH5DHUr", + "stableTargetId": "bFQoRhcVH5DHUD", }, ), ( "bFQoRhcVH5DHUr", "cp-2", { - "identifier": "bFQoRhcVH5DHUq", + "identifier": "bFQoRhcVH5DHUw", "hadPrimarySource": "bFQoRhcVH5DHUr", "identifierInPrimarySource": "cp-2", - "stableTargetId": "bFQoRhcVH5DHUr", + "stableTargetId": "bFQoRhcVH5DHUx", }, ), ( @@ -244,23 +244,23 @@ def test_fetch_identities_mocked( None, [ { - "identifier": "sMgFvmdtJyegb9vkebq04", "hadPrimarySource": "00000000000000", + "identifier": "bFQoRhcVH5DHUq", "identifierInPrimarySource": "ps-1", - "stableTargetId": "gGdOIbDIHRt35He616Fv5q", + "stableTargetId": "bFQoRhcVH5DHUr", } ], ), ( None, None, - MergedOrganizationalUnitIdentifier("cWWm02l1c6cucKjIhkFqY4"), + MergedOrganizationalUnitIdentifier("bFQoRhcVH5DHUz"), [ { - "identifier": "gIyDlXYbq0JwItPRU0NcFN", - "hadPrimarySource": "bbTqJnQc3TA8dBJmLMBimb", + "identifier": "bFQoRhcVH5DHUy", + "hadPrimarySource": "bFQoRhcVH5DHUt", "identifierInPrimarySource": "ou-1", - "stableTargetId": "cWWm02l1c6cucKjIhkFqY4", + "stableTargetId": "bFQoRhcVH5DHUz", } ], ), diff --git a/tests/merged/test_main.py b/tests/merged/test_main.py index 0f9fa1c..f481a45 100644 --- a/tests/merged/test_main.py +++ b/tests/merged/test_main.py @@ -122,12 +122,12 @@ def test_search_merged_items_mocked( { "$type": "MergedContactPoint", "email": ["info@contact-point.one"], - "identifier": "wEvxYRPlmGVQCbZx9GAbn", + "identifier": "bFQoRhcVH5DHUv", }, { "$type": "MergedContactPoint", "email": ["help@contact-point.two"], - "identifier": "g32qzYNVH1Ez7JTEk3fvLF", + "identifier": "bFQoRhcVH5DHUx", }, ], "total": 2, @@ -143,7 +143,7 @@ def test_search_merged_items_mocked( "contact": [], "description": [], "documentation": [], - "identifier": "bbTqJnQc3TA8dBJmLMBimb", + "identifier": "bFQoRhcVH5DHUt", "locatedAt": [], "title": [], "unitInCharge": [], @@ -154,14 +154,14 @@ def test_search_merged_items_mocked( }, ), ( - "?identifier=cWWm02l1c6cucKjIhkFqY4", + "?identifier=bFQoRhcVH5DHUz", { "items": [ { "$type": "MergedOrganizationalUnit", "alternativeName": [], "email": [], - "identifier": "cWWm02l1c6cucKjIhkFqY4", + "identifier": "bFQoRhcVH5DHUz", "name": [{"language": "en", "value": "Unit 1"}], "parentUnit": None, "shortName": [], From 6860e1af0924f8fdeb3c54eb9d80dbcfe1f522d7 Mon Sep 17 00:00:00 2001 From: Nicolas Drebenstedt Date: Fri, 24 May 2024 18:07:07 +0200 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 4 ++++ tests/conftest.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b49b8..3986d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - updated graph connector for new queries - improved isolation of neo4j dependency - improved documentation and code-readability +- move exception handling middleware to new module +- change `identity_provider` default to `MEMORY` +- add some stop-gap code waiting to be resolved by MX-1596 +- migrate to `mex-common` > 0.25.1 ### Deprecated diff --git a/tests/conftest.py b/tests/conftest.py index 3710c5d..678a5a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -166,7 +166,7 @@ def isolate_graph_database( is_integration_test: bool, settings: BackendSettings ) -> None: """Automatically flush the graph database for integration testing.""" - if is_integration_test: # pragma: no cover + if is_integration_test: with GraphDatabase.driver( settings.graph_url, auth=( From 191101e3629b9d7817616b22036f010a6cd1cad5 Mon Sep 17 00:00:00 2001 From: Nicolas Drebenstedt Date: Wed, 29 May 2024 17:00:44 +0200 Subject: [PATCH 5/5] update CL --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3986d79..70aa951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - improved documentation and code-readability - move exception handling middleware to new module - change `identity_provider` default to `MEMORY` -- add some stop-gap code waiting to be resolved by MX-1596 -- migrate to `mex-common` > 0.25.1 +- add stop-gap code waiting to be resolved by mx-1596 +- migrate to latest `mex-common` ### Deprecated