Skip to content

Commit

Permalink
Add first passing create/get test
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuba committed Jul 31, 2024
1 parent d8abdf8 commit 626a8ba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion api/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"python.testing.pytestArgs": [
"."
".",
"-vv"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
2 changes: 1 addition & 1 deletion api/api/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def persist_doc(self, model_doc: shared_data_models.DocumentMixin):
raise exceptions.InvalidUpdateException(str(e))

async def get_doc(self, uuid: shared_data_models.UUID, doc_type):
doc = await self._get_doc_raw({"uuid": uuid})
doc = await self._get_doc_raw(uuid=uuid)

if doc is None:
raise exceptions.DocumentNotFound("Study does not exist")
Expand Down
3 changes: 2 additions & 1 deletion api/api/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import bia_shared_datamodels.bia_data_model as shared_data_models
from .models.repository import Repository
from . import constants
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, status

router = APIRouter(
prefix="/private",
Expand Down Expand Up @@ -35,4 +35,5 @@ async def post_item(doc: t, db: Repository = Depends()) -> None:
summary=f"Create {t.__name__}",
methods=["POST"],
endpoint=make_post_item(t),
status_code=status.HTTP_201_CREATED,
)
10 changes: 5 additions & 5 deletions api/api/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def make_get_item(t):
async def get_item(
uuid: shared_data_models.UUID, db: Repository = Depends()
) -> dict:
return db.get_doc(uuid, t)
return await db.get_doc(uuid, t)

return get_item


for t in models_public:
router.add_api_route(
"/" + to_snake(t.__name__),
f"/{to_snake(t.__name__)}/{{uuid}}",
response_model=t,
operation_id=f"get{t.__name__}",
summary=f"Get {t.__name__}",
Expand All @@ -45,6 +45,6 @@ def not_overwritten(n: int) -> int:
return n


@router.get("/study")
def yes_overwritten(n: int) -> int:
return n
# @router.get("/study")
# def yes_overwritten(n: int) -> int:
# return n
29 changes: 25 additions & 4 deletions api/api/tests/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def api_client() -> TestClient:
return client


def test_create_thing(api_client: TestClient):
def test_create_study(api_client: TestClient):
study_uuid = get_uuid()
study = {
"uuid": study_uuid,
Expand All @@ -50,15 +50,36 @@ def test_create_thing(api_client: TestClient):
"licence": "CC_BY_4.0",
"see_also": [],
"model": {"type_name": "Study", "version": 1},
"acknowledgement": "test",
"funding_statement": "test",
"grant": [],
"keyword": [],
"related_publication": [],
"author": [
{
"display_name": "Georg Brenneis",
"contact_email": "[email protected]",
"affiliation": [{"display_name": "University of Vienna"}],
"address": None,
"display_name": "Test name",
"contact_email": "[email protected]",
"orcid": None,
"role": None,
"rorid": None,
"website": None,
"affiliation": [
{
"display_name": "Test",
"address": None,
"rorid": None,
"website": None,
}
],
}
],
"attribute": {},
}

rsp = api_client.post("private/study", json=study)
assert rsp.status_code == 201, rsp.json()

rsp = api_client.get(f"study/{study['uuid']}")
assert rsp.status_code == 200, rsp.text
assert rsp.json() == study

0 comments on commit 626a8ba

Please sign in to comment.