Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial set of CI tests together with a ephemeral MongoDB container #117

Merged
merged 46 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
119f17e
Add pytest defaults
stuartcampbell Oct 9, 2024
8e736be
Add pytest fixtures
stuartcampbell Oct 9, 2024
48345a7
Add beamline api tests
stuartcampbell Oct 9, 2024
6e592a2
Add asgi-lifespan and pytest-asyncio for testing
stuartcampbell Oct 9, 2024
56ee022
Added pyright to dev requirements
stuartcampbell Oct 10, 2024
01ed1d8
upgrade dependencies
stuartcampbell Oct 10, 2024
4ef5080
Add initial infrastructure tests
stuartcampbell Oct 10, 2024
98138be
Add blank-ish .env file for pytest
stuartcampbell Oct 10, 2024
4f254e3
Refactor so we don't connect to slack on import
stuartcampbell Oct 10, 2024
41f88db
Settings checks for running in pytest
stuartcampbell Oct 10, 2024
192412e
Remove extra check for local mongodb
stuartcampbell Oct 10, 2024
b645a0e
Populate database and alter tests to match
stuartcampbell Oct 10, 2024
b25fef0
Create ci.yml
stuartcampbell Oct 10, 2024
821a3cb
fix indentation error
stuartcampbell Oct 10, 2024
926b32f
Revert to boring stuff for now
stuartcampbell Oct 10, 2024
99124d8
Install krb5 (for n2snusertools)
stuartcampbell Oct 10, 2024
b5c9983
install wheel early as well
stuartcampbell Oct 10, 2024
bce1b24
Add hook to ensure we captialize beamline name before inserting Document
stuartcampbell Oct 11, 2024
6a22d66
Add cycle to test database
stuartcampbell Oct 11, 2024
ee26bfb
Added tests for facility api endpoints
stuartcampbell Oct 11, 2024
0fa6361
Added proposal type into test database
stuartcampbell Oct 11, 2024
7589690
Make types consistent for mongodb DSN
stuartcampbell Oct 14, 2024
af93df2
Add coverage
stuartcampbell Oct 14, 2024
df5758b
Add python 3.13 to test matrix
stuartcampbell Oct 14, 2024
5d72465
Reformat and change default asyncio pytest loop scope
stuartcampbell Oct 16, 2024
c145b16
Mark tests as asyncio
stuartcampbell Oct 16, 2024
0eea6f7
Reformat
stuartcampbell Oct 16, 2024
d2fea12
Update for newest pytest-asyncio event_loop changes
stuartcampbell Oct 16, 2024
c900abb
Add back scope that was accidentally removed
stuartcampbell Oct 16, 2024
77a64a6
cleanup test database
stuartcampbell Oct 16, 2024
b88f6e2
Update requirements
stuartcampbell Oct 16, 2024
007b779
Fix default values in method to match type hints
stuartcampbell Oct 21, 2024
412e6c0
Change default asyncio loop scope
stuartcampbell Oct 21, 2024
22aec1f
Update pytest fixtures
stuartcampbell Oct 21, 2024
c3f9210
Add tests for facility_service
stuartcampbell Oct 21, 2024
2f2e305
Update test to be async
stuartcampbell Oct 21, 2024
0f058fc
Update test to be async
stuartcampbell Oct 21, 2024
0a6eec7
Change to use fastapi status codes rather than ints
stuartcampbell Oct 23, 2024
d632a99
Add a check for beamline existence before dir skeleton
stuartcampbell Oct 23, 2024
3270cd8
Add tests for non exsistent beamlines
stuartcampbell Oct 23, 2024
4081543
Update pyproject.toml to correct python versions
stuartcampbell Oct 25, 2024
ef24315
Upgrade dependencies
stuartcampbell Oct 25, 2024
b2ae974
Code Reformatting
stuartcampbell Oct 25, 2024
91d7c81
Code Reformating
stuartcampbell Nov 1, 2024
c41e4aa
Code Reformating
stuartcampbell Nov 1, 2024
6358db6
Update src/nsls2api/infrastructure/config.py
stuartcampbell Nov 1, 2024
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
Prev Previous commit
Next Next commit
Change to use fastapi status codes rather than ints
  • Loading branch information
stuartcampbell committed Oct 23, 2024
commit 0a6eec75149e1f13d57cb56bb9e4e8330370cb1e
53 changes: 19 additions & 34 deletions src/nsls2api/api/v1/beamline_api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import fastapi
from fastapi import HTTPException, Depends, Request
from fastapi.security.api_key import APIKey

from nsls2api.api.models.proposal_model import (
ProposalDirectoriesList,
)

from nsls2api.infrastructure.logging import logger
from nsls2api.infrastructure.security import (
get_current_user,
validate_admin_role,
)

from nsls2api.models.beamlines import (
Beamline,
BeamlineService,
Detector,
DetectorList,
DirectoryList,
)

from nsls2api.services import beamline_service

router = fastapi.APIRouter()
Expand All @@ -29,7 +27,7 @@ async def details(name: str):
beamline = await beamline_service.beamline_by_name(name)
if beamline is None:
raise HTTPException(
status_code=451, detail=f"Beamline named {name} could not be found"
status_code=fastapi.status.HTTP_404_NOT_FOUND, detail=f"Beamline '{name}' does not exist"
)
return beamline

Expand All @@ -39,19 +37,19 @@ async def get_beamline_accounts(name: str, api_key: APIKey = Depends(get_current
service_accounts = await beamline_service.service_accounts(name)
if service_accounts is None:
raise HTTPException(
status_code=404, detail=f"Beamline named {name} could not be found"
status_code=fastapi.status.HTTP_404_NOT_FOUND, detail=f"Beamline '{name}' does not exist"
)
return service_accounts


@router.get("/beamline/{name}/slack-channel-managers")
async def get_beamline_slack_channel_managers(
name: str, api_key: APIKey = Depends(get_current_user)
name: str, api_key: APIKey = Depends(get_current_user)
):
slack_channel_managers = await beamline_service.slack_channel_managers(name)
if slack_channel_managers is None:
raise HTTPException(
status_code=404, detail=f"Beamline named {name} could not be found"
status_code=fastapi.status.HTTP_404_NOT_FOUND, detail=f"Beamline named {name} could not be found"
)
return slack_channel_managers

Expand All @@ -63,7 +61,7 @@ async def get_beamline_detectors(name: str) -> DetectorList:
detectors = await beamline_service.detectors(name)
if detectors is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No detectors for the {name} beamline could not be found.",
)

Expand All @@ -84,19 +82,19 @@ async def get_beamline_detectors(name: str) -> DetectorList:
dependencies=[Depends(validate_admin_role)],
)
async def add_or_delete_detector(
request: Request, name: str, detector_name: str, detector: Detector | None = None
request: Request, name: str, detector_name: str, detector: Detector | None = None
):
if request.method == "PUT":
logger.info(f"Adding detector {detector_name} to beamline {name}")

if not detector:
raise HTTPException(
status_code=422,
status_code=fastapi.status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"No detector information supplied in request body.",
)
if detector_name != detector.name:
raise HTTPException(
status_code=400,
status_code=fastapi.status.HTTP_400_BAD_REQUEST,
detail=f"Detector name in path '{detector_name}' does not match name in body '{detector.name}'.",
)

Expand All @@ -111,7 +109,7 @@ async def add_or_delete_detector(

if new_detector is None:
raise HTTPException(
status_code=409,
status_code=fastapi.status.HTTP_409_CONFLICT,
detail=f"Detector already exists in beamline {name} with either name '{detector.name}' or directory name '{detector.directory_name}'",
)

Expand All @@ -126,7 +124,7 @@ async def add_or_delete_detector(

if deleted_detector is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"Detector {detector_name} was not found for beamline {name}",
)

Expand All @@ -140,19 +138,6 @@ async def add_or_delete_detector(
response_model=ProposalDirectoriesList,
deprecated=True,
)
async def get_beamline_proposal_directory_skeleton(name: str):
directory_skeleton = await beamline_service.directory_skeleton(name)
if directory_skeleton is None:
raise HTTPException(
status_code=404,
detail=f"No proposal directory skeleton for the {name} beamline could be generated.",
)
response_model = ProposalDirectoriesList(
directory_count=len(directory_skeleton), directories=directory_skeleton
)
return response_model


@router.get(
"/beamline/{name}/directory-skeleton",
response_model=DirectoryList,
Expand All @@ -161,7 +146,7 @@ async def get_beamline_directory_skeleton(name: str):
directory_skeleton = await beamline_service.directory_skeleton(name)
if directory_skeleton is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No proposal directory skeleton for the {name} beamline could be generated.",
)
response_model = ProposalDirectoriesList(
Expand All @@ -181,7 +166,7 @@ async def get_beamline_workflow_username(name: str):
workflow_user = await beamline_service.workflow_username(name)
if workflow_user is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No workflow user has been defined for the {name} beamline",
)
return workflow_user
Expand All @@ -194,7 +179,7 @@ async def get_beamline_ioc_username(name: str):
ioc_user = await beamline_service.ioc_username(name)
if ioc_user is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No IOC user has been defined for the {name} beamline",
)
return ioc_user
Expand All @@ -207,7 +192,7 @@ async def get_beamline_bluesky_username(name: str):
bluesky_user = await beamline_service.bluesky_username(name)
if bluesky_user is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No bluesky user has been defined for the {name} beamline",
)
return bluesky_user
Expand All @@ -222,7 +207,7 @@ async def get_beamline_epics_services_username(name: str):
epics_user = await beamline_service.epics_services_username(name)
if epics_user is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No EPICS services user has been defined for the {name} beamline",
)
return epics_user
Expand All @@ -235,7 +220,7 @@ async def get_beamline_operator_username(name: str):
operator_user = await beamline_service.operator_username(name)
if operator_user is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"No operator user has been defined for the {name} beamline",
)
return operator_user
Expand All @@ -250,7 +235,7 @@ async def get_beamline_services(name: str):
beamline_services = await beamline_service.all_services(name)
if beamline_services is None:
raise HTTPException(
status_code=404, detail=f"Beamline named {name} could not be found"
status_code=fastapi.status.HTTP_404_NOT_FOUND, detail=f"Beamline named {name} could not be found"
)
return beamline_services

Expand All @@ -275,7 +260,7 @@ async def add_beamline_service(name: str, service: BeamlineService):

if new_service is None:
raise HTTPException(
status_code=404,
status_code=fastapi.status.HTTP_404_NOT_FOUND,
detail=f"Service {service.name} already exists in beamline {name}",
)

Expand Down