From e0212fed837aed4f77f445708e044b87a43efefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20L=C3=B3pez=20Dato?= Date: Fri, 13 Dec 2024 16:19:10 -0300 Subject: [PATCH 1/4] Add GET /api/v1/identities endpoint --- src/edge_proxy/server.py | 8 ++++++++ tests/test_server.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/edge_proxy/server.py b/src/edge_proxy/server.py index 1413417..f0f4940 100644 --- a/src/edge_proxy/server.py +++ b/src/edge_proxy/server.py @@ -91,6 +91,14 @@ async def identity( data = environment_service.get_identity_response_data(input_data, x_environment_key) return ORJSONResponse(data) +@app.get("/api/v1/identities/", response_class=ORJSONResponse) +async def get_identities( + identifier: str, + x_environment_key: str = Header(None), +): + data = environment_service.get_identity_response_data(IdentityWithTraits(identifier=identifier), x_environment_key) + return ORJSONResponse(data) + @app.on_event("startup") @repeat_every( diff --git a/tests/test_server.py b/tests/test_server.py index 9bf7ea1..fc1f20d 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -259,3 +259,27 @@ def test_post_identity__invalid_trait_data__expected_response( "constrained-str", ] assert response.json()["detail"][-1]["type"] == "string_too_long" + + +def test_get_identities(mocker: MockerFixture, client: TestClient): + x_environment_key = "test_environment_key" + identifier = "test_identifier" + + mocked_environment_cache = mocker.patch( + "edge_proxy.server.environment_service.cache" + ) + mocked_environment_cache.get_environment.return_value = environment_1 + mocked_environment_cache.get_identity.return_value = { + "environment_api_key": x_environment_key, + "identifier": identifier, + } + + response = client.get( + "/api/v1/identities/", + headers={"x-environment-key": x_environment_key}, + params={"identifier": identifier} + ) + data = response.json() + + assert response.status_code == 200 + assert data["traits"] == [] \ No newline at end of file From c1592429153ab4eb7e9a1d851961632961fcba90 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 19:24:04 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/edge_proxy/server.py | 5 ++++- tests/test_server.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/edge_proxy/server.py b/src/edge_proxy/server.py index f0f4940..37a74b8 100644 --- a/src/edge_proxy/server.py +++ b/src/edge_proxy/server.py @@ -91,12 +91,15 @@ async def identity( data = environment_service.get_identity_response_data(input_data, x_environment_key) return ORJSONResponse(data) + @app.get("/api/v1/identities/", response_class=ORJSONResponse) async def get_identities( identifier: str, x_environment_key: str = Header(None), ): - data = environment_service.get_identity_response_data(IdentityWithTraits(identifier=identifier), x_environment_key) + data = environment_service.get_identity_response_data( + IdentityWithTraits(identifier=identifier), x_environment_key + ) return ORJSONResponse(data) diff --git a/tests/test_server.py b/tests/test_server.py index fc1f20d..3757c72 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -277,9 +277,9 @@ def test_get_identities(mocker: MockerFixture, client: TestClient): response = client.get( "/api/v1/identities/", headers={"x-environment-key": x_environment_key}, - params={"identifier": identifier} + params={"identifier": identifier}, ) data = response.json() assert response.status_code == 200 - assert data["traits"] == [] \ No newline at end of file + assert data["traits"] == [] From d395cf4c46aaa7ae11941e2398dbf5174e1c4555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20L=C3=B3pez=20Dato?= Date: Thu, 19 Dec 2024 10:32:39 -0300 Subject: [PATCH 3/4] Add return type Co-authored-by: Kim Gustyr --- src/edge_proxy/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edge_proxy/server.py b/src/edge_proxy/server.py index 37a74b8..0d26b85 100644 --- a/src/edge_proxy/server.py +++ b/src/edge_proxy/server.py @@ -96,7 +96,7 @@ async def identity( async def get_identities( identifier: str, x_environment_key: str = Header(None), -): +) -> ORJSONResponse: data = environment_service.get_identity_response_data( IdentityWithTraits(identifier=identifier), x_environment_key ) From 31eb4199846b65bd5187a7a450acf46113d9773d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20L=C3=B3pez=20Dato?= Date: Thu, 19 Dec 2024 10:32:46 -0300 Subject: [PATCH 4/4] formatting Co-authored-by: Kim Gustyr --- tests/test_server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_server.py b/tests/test_server.py index 3757c72..3e6c6ff 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -261,7 +261,10 @@ def test_post_identity__invalid_trait_data__expected_response( assert response.json()["detail"][-1]["type"] == "string_too_long" -def test_get_identities(mocker: MockerFixture, client: TestClient): +def test_get_identities( + mocker: MockerFixture, + client: TestClient, +) -> None: x_environment_key = "test_environment_key" identifier = "test_identifier"