generated from Luis/nextjs-python-web-template
Georg-Stahn-georgs (#25)
Co-authored-by: sara-pervana <saramakishti@gmail.com> Co-authored-by: ui-asset-bot <ui-asset-bot@gchq.icu> Co-authored-by: Onur Arslan <runoxa@hotmail.com> Co-authored-by: Arslan, Erdem <erdem.arslan@valtech.com> Co-authored-by: Luis-Hebendanz <consulting@qube.email> Reviewed-on: #25 Co-authored-by: Georg-Stahn <g.stahn@campus.tu-berlin.de> Co-committed-by: Georg-Stahn <g.stahn@campus.tu-berlin.de>
This commit was merged in pull request #25.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -19,3 +19,7 @@ pkgs.pyproj
|
|||||||
.reports
|
.reports
|
||||||
.ruff_cache
|
.ruff_cache
|
||||||
htmlcov
|
htmlcov
|
||||||
|
|
||||||
|
# georgs
|
||||||
|
pkgs/.vs/
|
||||||
|
pkgs/clan-cli/.hypothesis/
|
||||||
|
|||||||
54
pkgs/clan-cli/clan_cli/webui/api_outputs.py
Normal file
54
pkgs/clan-cli/clan_cli/webui/api_outputs.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
class Status(Enum):
|
||||||
|
ONLINE = "online"
|
||||||
|
OFFLINE = "offline"
|
||||||
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
class Machine(BaseModel):
|
||||||
|
name: str
|
||||||
|
status: Status
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoryBase(BaseModel):
|
||||||
|
title: str
|
||||||
|
description: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoryCreate(RepositoryBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Repository(RepositoryBase):
|
||||||
|
id: int
|
||||||
|
prod_id: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
|
||||||
|
|
||||||
|
class ProducerBase(BaseModel):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
|
||||||
|
class ProducerCreate(ProducerBase):
|
||||||
|
jsonblob: int = Field(
|
||||||
|
42,
|
||||||
|
title="The Json",
|
||||||
|
description="this is the value of json",
|
||||||
|
gt=30,
|
||||||
|
lt=50,
|
||||||
|
list=[1, 2, "3"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Producer(ProducerBase):
|
||||||
|
id: int
|
||||||
|
repos: list[Repository] = []
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List, Optional
|
from typing import List
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class EntityCreate(EntityBase):
|
|||||||
class Entity(EntityCreate):
|
class Entity(EntityCreate):
|
||||||
producers: List[Producer] = []
|
producers: List[Producer] = []
|
||||||
consumers: List[Consumer] = []
|
consumers: List[Consumer] = []
|
||||||
repository: Optional[Repository] = None
|
repository: List[Repository] = []
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|||||||
Binary file not shown.
@@ -1,8 +1,9 @@
|
|||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
from sqlalchemy.orm import Session, sessionmaker
|
# from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.orm import Session, declarative_base, sessionmaker
|
||||||
|
|
||||||
URL = "sqlite:///./sql_app.db"
|
URL = "sqlite:///./sql_app.db"
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ class Entity(Base):
|
|||||||
## Relations ##
|
## Relations ##
|
||||||
producers = relationship("Producer", back_populates="entity")
|
producers = relationship("Producer", back_populates="entity")
|
||||||
consumers = relationship("Consumer", back_populates="entity")
|
consumers = relationship("Consumer", back_populates="entity")
|
||||||
repository = relationship("Repository", uselist=False, back_populates="entity")
|
repository = relationship("Repository", back_populates="entity")
|
||||||
|
# TODO maby refactor to repositories
|
||||||
|
|
||||||
|
|
||||||
class ProducerAbstract(Base):
|
class ProducerAbstract(Base):
|
||||||
|
|||||||
134
pkgs/clan-cli/tests/test_db_api.py
Normal file
134
pkgs/clan-cli/tests/test_db_api.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from api import TestClient
|
||||||
|
|
||||||
|
default_entity_did_url = "entity_did=did%3Asov%3Atest%3A1234"
|
||||||
|
default_entity_did = "did:sov:test:1234"
|
||||||
|
|
||||||
|
|
||||||
|
def assert_extra_info(
|
||||||
|
infos: list[str],
|
||||||
|
request_body: dict[str, Any],
|
||||||
|
response: dict[str, str],
|
||||||
|
) -> None:
|
||||||
|
# print(type())
|
||||||
|
for info in infos:
|
||||||
|
assert info in response.keys()
|
||||||
|
# TODO maybe check the content of the extra info ...
|
||||||
|
response.pop(info)
|
||||||
|
assert response == request_body
|
||||||
|
|
||||||
|
|
||||||
|
def make_test_post_and_get(
|
||||||
|
api: TestClient,
|
||||||
|
request_body: dict[str, Any],
|
||||||
|
paramter: str,
|
||||||
|
get_request: str = default_entity_did_url,
|
||||||
|
apiversion: str = "v1",
|
||||||
|
) -> None:
|
||||||
|
# test post
|
||||||
|
response = api.post(
|
||||||
|
f"/api/{apiversion}/create_{paramter}",
|
||||||
|
json=request_body,
|
||||||
|
headers={"Content-Type": "application/json"},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
if paramter == "repository":
|
||||||
|
assert_extra_info(["time_created"], request_body, response.json())
|
||||||
|
elif paramter == "consumer":
|
||||||
|
assert_extra_info(["id"], request_body, response.json())
|
||||||
|
elif paramter == "entity":
|
||||||
|
assert_extra_info(
|
||||||
|
["consumers", "producers", "repository"], request_body, response.json()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert response.json() == request_body
|
||||||
|
# test get
|
||||||
|
response = api.get(
|
||||||
|
f"api/{apiversion}/get_{paramter}?{get_request}&skip=0&limit=100"
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
if paramter == "repository":
|
||||||
|
assert_extra_info(["time_created"], request_body, response.json()[0])
|
||||||
|
elif paramter == "consumer":
|
||||||
|
assert_extra_info(["id"], request_body, response.json()[0])
|
||||||
|
elif paramter == "entity":
|
||||||
|
assert_extra_info(
|
||||||
|
["consumers", "producers", "repository"], request_body, response.json()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert response.json() == [request_body]
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# #
|
||||||
|
# Producer #
|
||||||
|
# #
|
||||||
|
#########################
|
||||||
|
def test_producer(api: TestClient) -> None:
|
||||||
|
request_body = {
|
||||||
|
"uuid": "8e285c0c-4e40-430a-a477-26b3b81e30df",
|
||||||
|
"service_name": "Carlo'''s Printing",
|
||||||
|
"service_type": "3D Printing",
|
||||||
|
"endpoint_url": "http://127.0.0.1:8000",
|
||||||
|
"status": "unknown",
|
||||||
|
"other": {"test": "test"},
|
||||||
|
"entity_did": default_entity_did,
|
||||||
|
}
|
||||||
|
paramter = "producer"
|
||||||
|
# get_request = "entity_did=did%3Asov%3Atest%3A1234"
|
||||||
|
make_test_post_and_get(api, request_body, paramter)
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# #
|
||||||
|
# Consumer #
|
||||||
|
# #
|
||||||
|
#########################
|
||||||
|
def test_consumer(api: TestClient) -> None:
|
||||||
|
request_body = {
|
||||||
|
"entity_did": default_entity_did,
|
||||||
|
"producer_uuid": "8e285c0c-4e40-430a-a477-26b3b81e30df",
|
||||||
|
"other": {"test": "test"},
|
||||||
|
}
|
||||||
|
paramter = "consumer"
|
||||||
|
# get_request = "entity_did=did%3Asov%3Atest%3A1234"
|
||||||
|
make_test_post_and_get(api, request_body, paramter)
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# #
|
||||||
|
# REPOSITORY #
|
||||||
|
# #
|
||||||
|
#########################
|
||||||
|
def test_repository(api: TestClient) -> None:
|
||||||
|
request_body = {
|
||||||
|
"uuid": "8e285c0c-4e40-430a-a477-26b3b81e30df",
|
||||||
|
"service_name": "Carlo'''s Printing",
|
||||||
|
"service_type": "3D Printing",
|
||||||
|
"endpoint_url": "http://127.0.0.1:8000",
|
||||||
|
"status": "unknown",
|
||||||
|
"other": {"test": "test"},
|
||||||
|
"entity_did": default_entity_did,
|
||||||
|
}
|
||||||
|
paramter = "repository"
|
||||||
|
# get_request = "entity_did=did%3Asov%3Atest%3A1234"
|
||||||
|
make_test_post_and_get(api, request_body, paramter)
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# #
|
||||||
|
# Entity #
|
||||||
|
# #
|
||||||
|
#########################
|
||||||
|
def test_entity(api: TestClient) -> None:
|
||||||
|
request_body = {
|
||||||
|
"did": default_entity_did,
|
||||||
|
"name": "C1",
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"attached": False,
|
||||||
|
"other": {"test": "test"},
|
||||||
|
}
|
||||||
|
paramter = "entity"
|
||||||
|
# get_request = "entity_did=did%3Asov%3Atest%3A1234"
|
||||||
|
make_test_post_and_get(api, request_body, paramter)
|
||||||
Reference in New Issue
Block a user