Skip to content
Snippets Groups Projects
Commit 061bd008 authored by Christian Boettcher's avatar Christian Boettcher
Browse files

some additional moving around files and restructuring

pytest now works, apiserver now a module
parent a5e89c04
Branches
Tags
1 merge request!1apiserver based on fastAPI
**__pycache__/
**app/
\ No newline at end of file
# contains data for local tests
app/
\ No newline at end of file
from .main import app
\ No newline at end of file
......@@ -6,11 +6,11 @@ from fastapi import HTTPException
from pydantic import BaseModel
from LocationStorage import LocationDataType
from LocationStorage import LocationData
from LocationStorage import AbstractLocationDataStorageAdapter
from .storage import JsonFileStorageAdapter
from JsonFileStorageAdapter import JsonFileStorageAdapter
from .storage import AbstractLocationDataStorageAdapter
from .storage import LocationData
from .storage import LocationDataType
from enum import Enum
......@@ -39,7 +39,8 @@ def list_datasets(location_data_type : LocationDataType):
# register a new dataset, the response will contain the new dataset and its id
@app.put("/{location_data_type}")
def add_dataset(location_data_type : LocationDataType, dataset : LocationData):
return adapter.addNew(location_data_type, dataset)
usr: str = "testuser"
return adapter.addNew(location_data_type, dataset, usr)
# returns all information about a specific dataset, identified by id
@app.get("/{location_data_type}/{dataset_id}")
......@@ -53,6 +54,6 @@ def get_specific_dataset(location_data_type : LocationDataType, dataset_id: str)
@app.put("/{location_data_type}/{dataset_id}")
def update_specific_dataset(location_data_type : LocationDataType, dataset_id: str, dataset : LocationData):
try:
return adapter.updateDetails(location_data_type, dataset_id, dataset)
return adapter.updateDetails(location_data_type, dataset_id, dataset, usr)
except FileNotFoundError:
raise HTTPException(status_code=404, detail='The provided id does not exist for this datatype.')
......@@ -2,7 +2,7 @@ import os
import json
import uuid
from LocationStorage import AbstractLocationDataStorageAdapter, LocationData, LocationDataType
from .LocationStorage import AbstractLocationDataStorageAdapter, LocationData, LocationDataType
from typing import List
......@@ -85,7 +85,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
json.dump(data.__dict__, file)
return {id : data}
def getOwner(self, type: LocationDataType(), id: str):
def getOwner(self, type: LocationDataType, id: str):
raise NotImplementedError()
def checkPerm(self, type: LocationDataType, id: str, usr: str):
......
File moved
from .JsonFileStorageAdapter import JsonFileStorageAdapter
from .LocationStorage import LocationDataType, LocationData, AbstractLocationDataStorageAdapter
\ No newline at end of file
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import apiserver
import apiserver.storage as storage
\ No newline at end of file
......@@ -3,17 +3,19 @@
from fastapi.testclient import TestClient
from apiserver.LocationStorage import LocationDataType
from apiserver import main
from context import apiserver
from context import storage
client = TestClient(main.app)
client = TestClient(apiserver.app)
# get root
def test_root():
rsp = client.get('/')
assert rsp.status_code >= 200 and rsp.status_code < 300 # any 200 response is fine, as a get to the root should not return any error
# get every type in type enum
def test_types():
for location_type in LocationDataType:
for location_type in storage.LocationDataType:
rsp = client.get('/' + location_type.value)
assert rsp.status_code >= 200 and rsp.status_code < 300 # any 200 response is fine, as a get to the datatypes should not return any error
\ No newline at end of file
# This file only exists as a placeholder, so that local testing works immediatly after cloning.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment