Skip to content

Commit

Permalink
Fix test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Jodry authored and Etienne Jodry committed Apr 25, 2024
1 parent 35d5591 commit fc057a8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/biodm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.1.3'
__version_info__ = tuple([int(num) for num in __version__.split('.')])
__version_info__ = ([int(num) for num in __version__.split('.')])
10 changes: 9 additions & 1 deletion src/biodm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def dispatch(self, request: Request, call_next) -> Response:
body = await request.body()
h = {
'username_user': username,
'endpoint': str(request.url).split(self.server_host)[-1],
'endpoint': str(request.url).rsplit(self.server_host, maxsplit=1)[-1],
'method': request.method,
'content': body if body else ""
}
Expand All @@ -61,6 +61,14 @@ async def dispatch(self, request: Request, call_next) -> Response:


class Api(Starlette):
""" Main Server class.
- Sets up and holds managers + OpenAPI schema generator
- Instanciates CORE_CONTROLLERS and passed controllers
- Sets up routes
- adds our middlewares
- listens on events
"""
logger = logging.getLogger(__name__)

def __init__(self, config=None, controllers=[], routes=[], tables=None, schemas=None, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions src/biodm/basics/rootcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def routes(self, **_) -> List[Route]:
Route("/schema", endpoint=self.openapi_schema),
]

@staticmethod
async def live(_):
"""
description: Liveness check endpoint
Expand Down
12 changes: 6 additions & 6 deletions src/biodm/components/controllers/admincontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ def __init__(self,
super().__init__(entity, table, schema)

@admin_required
def create(self, *args, **kwargs):
async def create(self, *args, **kwargs):
return super().create(*args, **kwargs)

def read(self, *args, **kwargs):
async def read(self, *args, **kwargs):
return super().read(*args, **kwargs)

@admin_required
def update(self, *args, **kwargs):
async def update(self, *args, **kwargs):
return super().update(*args, **kwargs)

@admin_required
def delete(self, *args, **kwargs):
async def delete(self, *args, **kwargs):
return super().delete(*args, **kwargs)

@admin_required
def create_update(self, *args, **kwargs):
async def create_update(self, *args, **kwargs):
return super().create_update(*args, **kwargs)

def query(self, *args, **kwargs):
async def query(self, *args, **kwargs):
return super().query(*args, **kwargs)
12 changes: 6 additions & 6 deletions src/biodm/components/controllers/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ def serialize(data: Any, schema: Schema, many: bool) -> (str | Any):

# CRUD operations
@abstractmethod
def create(self, request):
async def create(self, request):
raise NotImplementedError

@abstractmethod
def read(self, request):
async def read(self, request):
raise NotImplementedError

@abstractmethod
def update(self, request):
async def update(self, request):
raise NotImplementedError

@abstractmethod
def delete(self, request):
async def delete(self, request):
raise NotImplementedError

@abstractmethod
def create_update(self, request):
async def create_update(self, request):
raise NotImplementedError

@abstractmethod
def query(self, request):
async def query(self, request):
raise NotImplementedError
26 changes: 13 additions & 13 deletions src/biodm/components/services/dbservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ def __init__(self, app):
self.app = app

@abstractmethod
async def create(self, stmt_only=False, **kwargs):
"""CREATE one row."""
async def create(self, data, stmt_only=False, **kwargs):
"""CREATE."""
raise NotImplementedError

@abstractmethod
async def read(self, **kwargs):
async def read(self, pk_val, **kwargs):
"""READ one row."""
raise NotImplementedError

@abstractmethod
async def update(self, **kwargs):
async def update(self, pk_val, data: dict, **kwargs):
"""UPDATE one row."""
raise NotImplementedError

@abstractmethod
async def create_update(self, **kwargs):
async def create_update(self, pk_val, data: dict):
"""CREATE UPDATE."""
raise NotImplementedError

@abstractmethod
async def delete(self, **kwargs):
async def delete(self, pk_val, **kwargs):
"""DELETE."""
raise NotImplementedError

@abstractmethod
async def filter(self, **kwargs):
async def filter(self, query_params: QueryParams, **kwargs):
"""FILTER."""
raise NotImplementedError

Expand Down Expand Up @@ -389,10 +389,10 @@ async def create(self, data: List[dict] | dict, **kwargs) -> Base | CompositeIns
f = self._create_many if isinstance(data, list) else self._create_one
return await f(data, **kwargs)

async def update(self, pk_val, data: dict) -> Base:
# TODO
raise NotImplementedError
# async def update(self, pk_val, data: dict) -> Base:
# # TODO
# raise NotImplementedError

async def delete(self, pk_val) -> Any:
# TODO
raise NotImplementedError
# async def delete(self, pk_val, **kwargs) -> Any:
# # TODO
# raise NotImplementedError
3 changes: 1 addition & 2 deletions src/example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from example.entities.controllers import CONTROLLERS
from example.entities import tables, schemas
sys.path.append(os.path.join(os.path.dirname(__file__), "config"))
import config
from example import config


def main():
Expand Down
7 changes: 4 additions & 3 deletions src/example/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys
import pytest
from pathlib import Path

from starlette.responses import HTMLResponse
from starlette.testclient import TestClient

sys.path.append('../')
import app

from example import app


# @pytest.fixture
Expand All @@ -14,6 +15,6 @@

def test_liveness():
with TestClient(app.main(), backend_options={"use_uvloop": True}) as client:
response = client.get('/')
response = client.get('/live')
assert response.status_code == 200
assert response.text == 'live\n'
3 changes: 3 additions & 0 deletions src/test_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://stackoverflow.com/a/47188103/6847689
import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

0 comments on commit fc057a8

Please sign in to comment.