-
Notifications
You must be signed in to change notification settings - Fork 0
Added some basic tests #13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces comprehensive unit tests for core modules (configuration, constants, and database cleanup) while updating test fixtures in conftest.py to use explicit enum types instead of raw strings and modernizing the database and API initialization patterns.
Key Changes:
- Added 3 new unit test files with thorough coverage of Config, constants, and DataCleanup classes
- Updated test fixtures to use
QueueFullBehaviorenum values for type safety - Modernized database engine initialization from
init_db()toinitialize()
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/unit/test_database_cleanup.py | New comprehensive tests for DataCleanup class covering initialization, cleanup operations, logging, and result validation using mocks |
| tests/unit/test_constants.py | New comprehensive tests for constants module including NODE_TYPE_MAP validation, node_type_name function with edge cases, and immutability checks |
| tests/unit/test_config.py | New comprehensive tests for Config dataclass covering all configuration sections (connection, database, API, webhooks, etc.) with type validation |
| tests/conftest.py | Updated fixtures to use QueueFullBehavior enum, refactored CommandQueueManager initialization with explicit parameters, changed database initialization to use new initialize() method, and simplified test_app fixtures |
Comments suppressed due to low confidence (4)
tests/conftest.py:4
- Import of 'json' is not used.
import json
tests/conftest.py:14
- Import of 'create_engine' is not used.
from sqlalchemy import create_engine
tests/conftest.py:15
- Import of 'sessionmaker' is not used.
from sqlalchemy.orm import Session, sessionmaker
tests/conftest.py:176
- Keyword argument 'db_engine' is not a supported parameter name of EventHandler.init.
handler = EventHandler(
db_engine=db_engine,
webhook_handler=mock_webhook_handler,
)
| meshcore=mock_meshcore, | ||
| config=test_config, | ||
| max_queue_size=test_config.queue_max_size, | ||
| queue_full_behavior=test_config.queue_full_behavior, |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch: test_config.queue_full_behavior is a string (from Config dataclass line 59), but CommandQueueManager.__init__ expects a QueueFullBehavior enum. This will cause a type error at runtime.
The config value should be converted to the enum, e.g.:
queue_full_behavior=QueueFullBehavior(test_config.queue_full_behavior),This assumes the string values in Config match the enum values ("reject" or "drop_oldest").
| queue_full_behavior=test_config.queue_full_behavior, | |
| queue_full_behavior=QueueFullBehavior(test_config.queue_full_behavior), |
| debounce_window_seconds=test_config.debounce_window_seconds, | ||
| debounce_cache_max_size=test_config.debounce_cache_max_size, | ||
| debounce_enabled=test_config.debounce_enabled, | ||
| debounce_commands=set(test_config.debounce_commands.split(",")), |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch: CommandQueueManager.__init__ expects debounce_commands to be Optional[set[CommandType]], but this code passes a set of strings. The string values need to be converted to CommandType enum values.
Example fix:
debounce_commands={CommandType(cmd.strip()) for cmd in test_config.debounce_commands.split(",")},This assumes the string values in Config match CommandType enum values ("send_message", "send_channel_message", etc.).
| from meshcore_api.api.app import create_app | ||
| from meshcore_api.config import Config | ||
| from meshcore_api.database.engine import DatabaseEngine | ||
| from meshcore_api.database.models import Base |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'Base' is not used.
| from meshcore_api.database.models import Base |
| @@ -0,0 +1,195 @@ | |||
| """Unit tests for configuration module - fixed to match actual implementation.""" | |||
|
|
|||
| import pytest | |||
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'pytest' is not used.
| import pytest |
| @@ -0,0 +1,132 @@ | |||
| """Unit tests for constants module - fixed to match actual implementation.""" | |||
|
|
|||
| import pytest | |||
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'pytest' is not used.
| import pytest |
| import pytest | ||
|
|
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'pytest' is not used.
| import pytest |
This pull request introduces new unit tests for configuration, constants, and database cleanup functionality, while also updating test fixtures to better reflect the current implementation and dependencies. The most significant changes are the addition of comprehensive tests for core modules and improvements to how test dependencies are managed in
tests/conftest.py.New unit tests:
tests/unit/test_config.pywith extensive tests for theConfigclass, covering default values, custom settings, webhook configuration, mock settings, database and API settings, type hints, dataclass behavior, and immutability of defaults.tests/unit/test_constants.pywith thorough tests for the constants module, including validation ofNODE_TYPE_MAP, thenode_type_namefunction, input edge cases, and immutability checks.tests/unit/test_database_cleanup.pyto test theDataCleanupclass, verifying initialization, cleanup operations, logging, retention validation, and result accuracy using mocks and patches.Test fixture improvements in
tests/conftest.py:QueueFullBehaviordirectly, ensuring enum values are used instead of raw strings. [1] [2]initialize()method rather thaninit_db(), reflecting updates in the database API.CommandQueueManagerfixture to pass individual config values as arguments, improving clarity and reducing reliance on the full config object.test_appandtest_app_with_authfixtures to create FastAPI test clients without requiring explicit dependency injection, making the tests easier to maintain and extend.