Loading edge_cloud_management_api/configs/env_config.py +1 −1 Original line number Diff line number Diff line import os from pydantic import BaseSettings from pydantic.v1 import BaseSettings from dotenv import load_dotenv load_dotenv() Loading edge_cloud_management_api/controllers/app_controllers.py +3 −3 Original line number Diff line number Diff line from flask import jsonify # from database import mongo from pydantic import ValidationError from edge_cloud_management_api.models.application_models import AppManifest # from edge_cloud_management_api.models.application_models import AppManifest def submit_app(body: dict): Loading @@ -11,7 +11,7 @@ def submit_app(body: dict): """ try: # Validate the input data using Pydantic validated_data = AppManifest(**body) # validated_data = AppManifest(**body) # Insert into MongoDB # app_id = mongo.db.applications.insert_one(validated_data.dict()).inserted_id Loading edge_cloud_management_api/managers/db_manager.py +25 −1 Original line number Diff line number Diff line Loading @@ -3,14 +3,38 @@ from edge_cloud_management_api.configs.env_config import Config class MongoManager: """ A utility class for managing MongoDB operations. The class implements the context manager protocol to ensure that the connection is closed after use. Methods: insert_document: Inserts a document into a collection. find_document: Finds a single document in a collection. find_documents: Finds multiple documents in a collection. update_document: Updates a single document in a collection. delete_document: Deletes a single document in a collection. close_connection: Closes the MongoDB connection. Example: with MongoManager() as db: db.insert_document("users", {"name": "Test User", "email": "test-user@sunrise6g.eu"}) """ def __init__(self): """ Initializes the MongoDB connection using the URI from Config. """ self.client = MongoClient(Config.MONGO_URI) self.client = MongoClient(Config.MONGO_URI, maxPoolSize=50) mongo_db_name: str = Config.MONGO_URI.split("/")[-1] self.db = self.client[mongo_db_name] def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.close_connection() def insert_document(self, collection_name, document): """ Inserts a document into the specified collection. Loading pyproject.toml +12 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [dependency-groups] dev = ["hatchling>=1.26.3", "ruff>=0.8.1"] dev = [ "hatchling>=1.26.3", "mongomock>=4.3.0", "mypy>=1.14.1", "pytest>=8.3.4", "ruff>=0.8.1", "tox>=4.23.2", ] [tool.pytest.ini_options] pythonpath = ["."] testpaths = ["tests"] [tool.ruff] exclude = [".eggs", ".git", ".ruff_cache", ".tox", ".venv"] Loading tests/controllers/test_app_controllers.py 0 → 100644 +16 −0 Original line number Diff line number Diff line import pytest from edge_cloud_management_api.controllers.app_controllers import get_app @pytest.mark.parametrize("app_id, x_correlator, expected", [ (1, None, "do some magic!"), (2, "123", "do some magic!"), ]) def test_get_app(app_id, x_correlator, expected): """ Test the get_app controller. """ result = get_app(app_id, x_correlator) assert result == expected Loading
edge_cloud_management_api/configs/env_config.py +1 −1 Original line number Diff line number Diff line import os from pydantic import BaseSettings from pydantic.v1 import BaseSettings from dotenv import load_dotenv load_dotenv() Loading
edge_cloud_management_api/controllers/app_controllers.py +3 −3 Original line number Diff line number Diff line from flask import jsonify # from database import mongo from pydantic import ValidationError from edge_cloud_management_api.models.application_models import AppManifest # from edge_cloud_management_api.models.application_models import AppManifest def submit_app(body: dict): Loading @@ -11,7 +11,7 @@ def submit_app(body: dict): """ try: # Validate the input data using Pydantic validated_data = AppManifest(**body) # validated_data = AppManifest(**body) # Insert into MongoDB # app_id = mongo.db.applications.insert_one(validated_data.dict()).inserted_id Loading
edge_cloud_management_api/managers/db_manager.py +25 −1 Original line number Diff line number Diff line Loading @@ -3,14 +3,38 @@ from edge_cloud_management_api.configs.env_config import Config class MongoManager: """ A utility class for managing MongoDB operations. The class implements the context manager protocol to ensure that the connection is closed after use. Methods: insert_document: Inserts a document into a collection. find_document: Finds a single document in a collection. find_documents: Finds multiple documents in a collection. update_document: Updates a single document in a collection. delete_document: Deletes a single document in a collection. close_connection: Closes the MongoDB connection. Example: with MongoManager() as db: db.insert_document("users", {"name": "Test User", "email": "test-user@sunrise6g.eu"}) """ def __init__(self): """ Initializes the MongoDB connection using the URI from Config. """ self.client = MongoClient(Config.MONGO_URI) self.client = MongoClient(Config.MONGO_URI, maxPoolSize=50) mongo_db_name: str = Config.MONGO_URI.split("/")[-1] self.db = self.client[mongo_db_name] def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.close_connection() def insert_document(self, collection_name, document): """ Inserts a document into the specified collection. Loading
pyproject.toml +12 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [dependency-groups] dev = ["hatchling>=1.26.3", "ruff>=0.8.1"] dev = [ "hatchling>=1.26.3", "mongomock>=4.3.0", "mypy>=1.14.1", "pytest>=8.3.4", "ruff>=0.8.1", "tox>=4.23.2", ] [tool.pytest.ini_options] pythonpath = ["."] testpaths = ["tests"] [tool.ruff] exclude = [".eggs", ".git", ".ruff_cache", ".tox", ".venv"] Loading
tests/controllers/test_app_controllers.py 0 → 100644 +16 −0 Original line number Diff line number Diff line import pytest from edge_cloud_management_api.controllers.app_controllers import get_app @pytest.mark.parametrize("app_id, x_correlator, expected", [ (1, None, "do some magic!"), (2, "123", "do some magic!"), ]) def test_get_app(app_id, x_correlator, expected): """ Test the get_app controller. """ result = get_app(app_id, x_correlator) assert result == expected