Skip to content

Commit

Permalink
api/server: Fix imports to support unittests.
Browse files Browse the repository at this point in the history
  • Loading branch information
somsonson committed Jan 14, 2025
1 parent 0a39608 commit 41aafb8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions api/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .server import app
2 changes: 1 addition & 1 deletion api/server/routes/aas_registry_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import APIRouter, Request, HTTPException

from basyx import ObjectStore
from services.aas_registry_server_service import AasRegistryServerService
from ..services.aas_registry_server_service import AasRegistryServerService


class AasRegistryRouter:
Expand Down
2 changes: 1 addition & 1 deletion api/server/routes/aasx_file_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import APIRouter, Request, HTTPException

from basyx import ObjectStore
from services.aasx_flie_server_service import AasxFileServerService
from ..services.aasx_flie_server_service import AasxFileServerService


class AasxFileServerRouter:
Expand Down
2 changes: 1 addition & 1 deletion api/server/routes/submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import APIRouter, Request, HTTPException

from basyx import ObjectStore
from services.submodel_service import SubmodelService
from ..services.submodel_service import SubmodelService


class SubmodelRouter:
Expand Down
2 changes: 1 addition & 1 deletion api/server/routes/submodel_registry_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import APIRouter, Request, HTTPException

from basyx import ObjectStore
from services.submodel_registry_server_service import SubmodelRegistryServerService
from ..services.submodel_registry_server_service import SubmodelRegistryServerService


class SubmodelRegistryRouter:
Expand Down
2 changes: 1 addition & 1 deletion api/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uvicorn

# Import routers
from routes import submodel, aasx_file_server, aas_registry_server, submodel_registry_server
from .routes import submodel, aasx_file_server, aas_registry_server, submodel_registry_server

from basyx import object_store

Expand Down
17 changes: 17 additions & 0 deletions api/test/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from fastapi.testclient import TestClient
from server import app # Import your FastAPI app

# Create a TestClient instance for your app
client = TestClient(app)

class TestFastAPIEndpoints(unittest.TestCase):
def test_registry_submodel_descriptors(self):
# Test the GET /items/{item_id} endpoint
response = client.get("/api/v3.0/submodels/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])


if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions sdk/basyx/object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,16 @@ def get_parent_referable(self, id_short: str) -> Referable:
return element
raise KeyError("there is no parent Identifiable for id_short {}".format(id_short))

def filter_identifiables_by_instance(self, instance: Type) -> list[Type]:
def get_identifiables_by_type(self, t: Type) -> list[Type]:
"""
Get all identifiables of the specified type.
:param instance: The Type to filter by. For example, we can filter by "aas_core3.types.ConceptDescription"
:param t: The Type to filter by. For example, we can filter by "aas_core3.types.ConceptDescription"
:return: The list of the filtered identifiables
"""
filtered_identifiables = []
for identifiable in self._backend.values():
if isinstance(identifiable, instance):
if isinstance(identifiable, t):
filtered_identifiables.append(identifiable)
return filtered_identifiables

Expand Down

0 comments on commit 41aafb8

Please sign in to comment.