Skip to content

Commit 4312efe

Browse files
authored
feat: adds new procedure types to model (#28)
* feat: adds new procedure types to model * fix: linter * completes coverage * linters
1 parent ea3fce7 commit 4312efe

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

aind-sharepoint-service-server/src/aind_sharepoint_service_server/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
6161
app.include_router(router)
6262

6363
# Clean up the methods names that is generated in the client code
64-
for route in app.routes:
64+
for route in router.routes:
6565
if isinstance(route, APIRoute):
6666
route.operation_id = route.name

aind-sharepoint-service-server/src/aind_sharepoint_service_server/models/nsb_2023.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,16 @@ class NSB2023Procedure(Enum, metaclass=EnumMeta):
800800
TESTES__INJECTION = "Testes Injection"
801801
OVIDUCT__INJECTION = "Oviduct Injection"
802802

803+
# Additional procedure types
804+
THERMISTOR__IMPLANT_WITH = "Thermistor Implant (with Headpost)"
805+
HP_INJ__THERMISTOR__IMPLA = "HP + INJ + Thermistor Implant"
806+
WHC_NP__THERMISTOR__IMPLA = "WHC NP + Thermistor Implant"
807+
DHC__THERMISTOR__IMPLANT = "DHC + Thermistor Implant"
808+
SPINAL__CORD_INJ = "Spinal Cord INJ"
809+
CHRONOS = "Chronos"
810+
ΜLED__IMPLANTATION = "µLED Implantation"
811+
CHRONOS_HP__SKULL__SCREW = "Chronos HP + Skull Screw + Thermistor Implant"
812+
803813

804814
class NSB2023Headpost(Enum, metaclass=EnumMeta):
805815
"""Enum class for NSB2023Headpost."""

aind-sharepoint-service-server/tests/conftest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,26 @@ def client_with_redis() -> Generator[TestClient, Any, None]:
9292
"""Creating a client when settings have a redis_url. Only used in one test
9393
to verify the lifespan method in main is called correctly."""
9494

95-
# Import moved to be able to mock cache
96-
from aind_sharepoint_service_server.main import app
97-
9895
settings_with_redis = settings.model_copy(
9996
update={"redis_url": RedisDsn("redis://example.com:1234")}, deep=True
10097
)
98+
mock_redis = AsyncMock()
10199
with (
102100
patch(
103101
"aind_sharepoint_service_server.main.settings",
104-
return_value=settings_with_redis,
102+
settings_with_redis,
105103
),
106104
patch(
107-
"aind_sharepoint_service_server.main.from_url", return_value=None
105+
"aind_sharepoint_service_server.main.from_url",
106+
return_value=mock_redis,
108107
),
109108
patch(
110109
"aind_sharepoint_service_server.main.RedisBackend",
111110
return_value=None,
112111
),
113112
):
113+
# Import moved inside patch context to ensure settings are patched
114+
from aind_sharepoint_service_server.main import app
115+
114116
with TestClient(app) as c:
115117
yield c

aind-sharepoint-service-server/tests/test_main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
"""Module to test main app"""
22

33
import pytest
4+
from fastapi.routing import APIRoute
45
from fastapi.testclient import TestClient
6+
from aind_sharepoint_service_server.route import router
57

68

79
class TestMain:
810
"""Tests app endpoints"""
911

12+
def test_app_with_in_memory_cache(self, client: TestClient):
13+
"""Tests client is instantiated correctly when redis_url None."""
14+
response = client.get("/healthcheck")
15+
assert 200 == response.status_code
16+
1017
def test_app_with_redis(self, client_with_redis: TestClient):
1118
"""Tests client is instantiated correctly when redis_url set."""
1219
response = client_with_redis.get("/healthcheck")
1320
assert 200 == response.status_code
1421

15-
def test_app_with_in_memory_cache(self, client: TestClient):
16-
"""Tests client is instantiated correctly when redis_url None."""
17-
response = client.get("/healthcheck")
18-
assert 200 == response.status_code
22+
def test_operation_ids_are_set(self, client: TestClient):
23+
"""Test that operation_id is set to route name for all APIRoutes."""
24+
api_routes = [r for r in router.routes if isinstance(r, APIRoute)]
25+
assert len(api_routes) > 0
26+
assert all(r.operation_id == r.name for r in api_routes)
1927

2028

2129
if __name__ == "__main__":

0 commit comments

Comments
 (0)