Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Minor fixes#323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Minor fixes #323
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,7 +18,6 @@ | ||
| # injecting models | ||
| from .models.db.state import State | ||
| from .models.db.namespace import Namespace | ||
| from .models.db.graph_template_model import GraphTemplate | ||
| from .models.db.registered_node import RegisteredNode | ||
| @@ -42,7 +41,7 @@ async def lifespan(app: FastAPI): | ||
| # initializing beanie | ||
| client = AsyncMongoClient(settings.mongo_uri) | ||
| db = client[settings.mongo_database_name] | ||
| await init_beanie(db, document_models=[State, Namespace, GraphTemplate, RegisteredNode]) | ||
| await init_beanie(db, document_models=[State, GraphTemplate, RegisteredNode]) | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| logger.info("beanie dbs initialized") | ||
| # initialize secret | ||
| @@ -54,14 +53,15 @@ async def lifespan(app: FastAPI): | ||
| yield | ||
| # end of the server | ||
| logger.info("server shutting down") | ||
| await client.close() | ||
| logger.info("server stopped") | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| app = FastAPI( | ||
| lifespan=lifespan, | ||
| title="Exosphere State Manager", | ||
| description="Exosphere State Manager", | ||
| version="0.1.0", | ||
| version="0.0.2-beta", | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| contact={ | ||
| "name": "Nivedit Jain (Founder exosphere.host)", | ||
| "email": "nivedit@exosphere.host", | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -75,6 +75,6 @@ class Settings: | ||
| ("namespace_name", 1), | ||
| ("node_name", 1), | ||
| ], | ||
| name="idx_enqueue_after" | ||
| name="enqueue_query" | ||
| ) | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,7 +17,6 @@ def test_app_initialization(self): | ||
| assert isinstance(app, FastAPI) | ||
| assert app.title == "Exosphere State Manager" | ||
| assert app.description == "Exosphere State Manager" | ||
| assert app.version == "0.1.0" | ||
| # Check contact info | ||
| assert app.contact is not None | ||
| @@ -113,7 +112,7 @@ class TestLifespan: | ||
| 'MONGO_DATABASE_NAME': 'test_db', | ||
| 'STATE_MANAGER_SECRET': 'test_secret' | ||
| }) | ||
| @patch('app.main.init_beanie') | ||
| @patch('app.main.init_beanie', new_callable=AsyncMock) | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @patch('app.main.AsyncMongoClient') | ||
| @patch('app.main.LogsManager') | ||
| async def test_lifespan_startup_success(self, mock_logs_manager, mock_mongo_client, mock_init_beanie): | ||
| @@ -123,12 +122,11 @@ async def test_lifespan_startup_success(self, mock_logs_manager, mock_mongo_clie | ||
| mock_logs_manager.return_value.get_logger.return_value = mock_logger | ||
| mock_client = MagicMock() | ||
| mock_client.close = AsyncMock() | ||
| mock_mongo_client.return_value = mock_client | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| mock_db = MagicMock() | ||
| mock_client.__getitem__.return_value = mock_db | ||
| mock_init_beanie.return_value = AsyncMock() | ||
| # Create a mock FastAPI app for the lifespan | ||
| mock_app = MagicMock() | ||
| @@ -144,14 +142,14 @@ async def test_lifespan_startup_success(self, mock_logs_manager, mock_mongo_clie | ||
| mock_logger.info.assert_any_call("secret initialized") | ||
| # After context manager exits (shutdown) | ||
| mock_logger.info.assert_any_call("server shutting down") | ||
| mock_logger.info.assert_any_call("server stopped") | ||
| @patch.dict(os.environ, { | ||
| 'MONGO_URI': 'mongodb://test:27017', | ||
| 'MONGO_DATABASE_NAME': 'test_db', | ||
| 'STATE_MANAGER_SECRET': '' # Empty secret | ||
| }) | ||
| @patch('app.main.init_beanie') | ||
| @patch('app.main.init_beanie', new_callable=AsyncMock) | ||
| @patch('app.main.AsyncMongoClient') | ||
| @patch('app.main.LogsManager') | ||
| async def test_lifespan_empty_secret_raises_error(self, mock_logs_manager, mock_mongo_client, mock_init_beanie): | ||
| @@ -160,12 +158,11 @@ async def test_lifespan_empty_secret_raises_error(self, mock_logs_manager, mock_ | ||
| mock_logs_manager.return_value.get_logger.return_value = mock_logger | ||
| mock_client = MagicMock() | ||
| mock_client.close = AsyncMock() | ||
| mock_mongo_client.return_value = mock_client | ||
| mock_db = MagicMock() | ||
| mock_client.__getitem__.return_value = mock_db | ||
| mock_init_beanie.return_value = AsyncMock() | ||
| mock_app = MagicMock() | ||
| with pytest.raises(ValueError, match="STATE_MANAGER_SECRET is not set"): | ||
| @@ -177,7 +174,7 @@ async def test_lifespan_empty_secret_raises_error(self, mock_logs_manager, mock_ | ||
| 'MONGO_DATABASE_NAME': 'test_db', | ||
| 'STATE_MANAGER_SECRET': 'test_secret' | ||
| }) | ||
| @patch('app.main.init_beanie') | ||
| @patch('app.main.init_beanie', new_callable=AsyncMock) | ||
| @patch('app.main.AsyncMongoClient') | ||
| @patch('app.main.LogsManager') | ||
| async def test_lifespan_init_beanie_with_correct_models(self, mock_logs_manager, mock_mongo_client, mock_init_beanie): | ||
| @@ -186,12 +183,11 @@ async def test_lifespan_init_beanie_with_correct_models(self, mock_logs_manager, | ||
| mock_logs_manager.return_value.get_logger.return_value = mock_logger | ||
| mock_client = MagicMock() | ||
| mock_client.close = AsyncMock() | ||
| mock_mongo_client.return_value = mock_client | ||
| mock_db = MagicMock() | ||
| mock_client.__getitem__.return_value = mock_db | ||
| mock_init_beanie.return_value = AsyncMock() | ||
| mock_app = MagicMock() | ||
| async with app_main.lifespan(mock_app): | ||
| @@ -209,11 +205,10 @@ async def test_lifespan_init_beanie_with_correct_models(self, mock_logs_manager, | ||
| # Import the expected models | ||
| from app.models.db.state import State | ||
| from app.models.db.namespace import Namespace | ||
| from app.models.db.graph_template_model import GraphTemplate | ||
| from app.models.db.registered_node import RegisteredNode | ||
| expected_models = [State, Namespace, GraphTemplate, RegisteredNode] | ||
| expected_models = [State, GraphTemplate, RegisteredNode] | ||
| assert document_models == expected_models | ||
| @@ -326,10 +321,7 @@ def test_app_metadata(self): | ||
| # Test description | ||
| assert app.description == "Exosphere State Manager" | ||
| # Test version | ||
| assert app.version == "0.1.0" | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Test contact info | ||
| assert app.contact is not None | ||
| assert app.contact["name"] == "Nivedit Jain (Founder exosphere.host)" | ||
Uh oh!
There was an error while loading. Please reload this page.