Create a comprehensive testing suite for CatWeazle using Python's standard unittest framework, and set up a GitHub Actions workflow to run the tests automatically on code pushes and pull requests.
Note
All tests will be built using the standard Python library unittest (as requested) and will run completely isolated without requiring a live MongoDB or LDAP instance. All database operations and external HTTP calls will be mocked using unittest.mock.AsyncMock.
We will create a comprehensive suite of unit and integration tests under the tests/ directory:
- tests/test_authorize.py:
- Tests the
Authorizeclass methods:get_user,require_admin,require_user, andrequire_permission.
- Tests the
- tests/test_webhook_executor.py:
- Tests dynamic placeholder replacement (
{instance:id},{instance:meta:role},{secret:SECRET_ID},{trigger}). - Tests the request dispatching logic (methods, params, body, basic auth, ssl certs).
- Tests dynamic placeholder replacement (
We will build tests utilizing the FastAPI TestClient to hit all API routes, mocking database/auth logic to ensure high coverage:
- tests/test_endpoint_authenticate.py:
- Tests login, session retrieval, and logout endpoints.
- tests/test_endpoint_users.py:
- Tests user creation, retrieval, updates, deletion, and searches.
- tests/test_endpoint_users_credentials.py:
- Tests API key/credentials creation, retrieval, deletion, and search.
- tests/test_endpoint_instances.py:
- Tests instance registration, details retrieval, search filters, updates, and deletion.
- tests/test_endpoint_permissions.py:
- Tests permission definitions, lists, updates, and deletion.
- tests/test_endpoint_secrets.py:
- Tests secret storage, lists, retrieval, updates, and deletion.
- tests/test_endpoint_webhooks.py:
- Tests webhook registration, lists, updates, and deletion.
- tests/test_endpoint_webhook_logs.py:
- Tests searching and paginating webhook execution logs.
- GitHub Actions workflow running on pushes and pull requests to
mainor other target branches. - Installs requirements and runs the
unittestdiscover suite.
- Run
python -m unittest discover -s teststo verify all test cases pass locally.