-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use API to get specifications (#343)
* Initial commit for specifications * Formatting and linting commit * Add specification tests * Formatting and linting commit * Give the e2e tests a first go over * Fix MARI rules tests * Fix Specifications _rule_old * Update tests.yml * Adjust e2e to stop requests being made to the FIA-API * Adjust e2e to stop requests being made to the FIA-API * Further adjust test files * Create a fake api for e2e tests to use instead of using the real one * Fix ruff linting error * Fix mypy errors * Ensure that order does not matter as rules that should be last self declare * Formatting and linting commit * Fix pytest error * Review comments/mypy fixes * Quick comment addition * Fix some errors with linting and long comments * Formatting and linting commit --------- Co-authored-by: github-actions <[email protected]>
- Loading branch information
Showing
65 changed files
with
321 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
fia-api/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3.12 | ||
|
||
WORKDIR /fia_api | ||
|
||
COPY . /fia_api | ||
|
||
RUN apt-get update \ | ||
&& apt-get -y install libpq-dev gcc \ | ||
&& python -m pip install --upgrade pip \ | ||
&& python -m pip install --no-cache-dir . | ||
|
||
CMD ["uvicorn", "fake_fia_api.fia_api:app", "--host", "0.0.0.0", "--port", "80"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Fake API app to be used for FastAPI | ||
""" | ||
|
||
from fastapi import FastAPI | ||
|
||
from fake_fia_api.router import ROUTER | ||
|
||
app = FastAPI() | ||
|
||
# This must be updated before exposing outside the vpn | ||
ALLOWED_ORIGINS = ["*"] | ||
|
||
app.include_router(ROUTER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import Any, Literal | ||
|
||
from fastapi import APIRouter | ||
|
||
ROUTER = APIRouter() | ||
|
||
|
||
def get_specification_from_file(instrument: str) -> Any: | ||
""" | ||
Given an instrument, return the specification | ||
:param instrument: The instrument for which specification to get | ||
:return: The specification file contents | ||
""" | ||
path = Path(f"/data/{instrument.lower()}_specification.json") | ||
with path.open(encoding="utf-8") as fle: | ||
return json.load(fle) | ||
|
||
|
||
@ROUTER.get("/instrument/{instrument_name}/specification", response_model=None) | ||
async def get_instrument_specification(instrument_name: str) -> Any: | ||
""" | ||
This is a fake API for the e2e tests to be deployed to provide specifications for rundetection e2e tests | ||
""" | ||
return get_specification_from_file(instrument_name) | ||
|
||
|
||
@ROUTER.get("/healthz") | ||
async def get() -> Literal["ok"]: | ||
"""Health Check endpoint.""" | ||
return "ok" |
Oops, something went wrong.