Add tests for rotate CLI and celery tasks#78
Merged
Conversation
Cover critical production paths that had zero test coverage: rotate CLI (8 tests): - request_rotation: commit/no-commit, message/no-message, error handling, success/failure metrics - Bulk rotation regression test: all 6 endpoints rotated, not 5 (list-mutation bug) - Single-endpoint rotation and dry-run mode Celery tasks (12 tests): - certificate_rotate: CLI dispatch, notification config, region routing, SoftTimeLimitExceeded, success metric - certificate_reissue: CLI dispatch, timeout, success metric - notify_expirations: CLI dispatch, config passthrough, timeout - clean_all_sources: per-source task dispatch, success metric
The autouse fixtures patching lemur.common.celery triggered module-level create_app() during pytest collection, creating a second Flask app that corrupted the session-scoped SQLAlchemy session for other tests.
Production (lemur-deploy) runs Python 3.12 but CI only tested 3.10 and 3.11. Add 3.12 to the matrix so CI matches what we deploy.
lemur.common.celery calls create_app() at module level when no Flask current_app exists. Importing it outside an app context (e.g. during pytest collection or early in a test) creates a second Flask app that corrupts the session-scoped SQLAlchemy session, breaking 20 tests in test_certificates.py. Fix: use _import_celery_task() helper that defers the import to inside the test body where the app context is active. Also require the session fixture to ensure DB state is clean.
…with test suite lemur.common.celery unconditionally calls create_app() at import time when no Flask current_app exists. This creates a second Flask app that corrupts the session-scoped SQLAlchemy session, breaking 20 existing tests in test_certificates.py. No amount of deferred importing helps because Python's module cache means the damage persists for the entire pytest session once any test triggers the import. The celery tasks are thin wrappers around CLI functions that ARE tested (test_rotate_cli.py). Revisit celery task tests after fixing the module-level create_app() pattern in celery.py.
Upstream Lemur fails during setup on Python 3.12 (tox config and dependencies need updates). Track 3.12 support separately.
Coverage Report for CI Build 28867722577Coverage remained the same at 59.879%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 20 tests covering critical production paths that previously had zero test coverage.
Rotate CLI (
test_rotate_cli.py— 8 tests)request_rotation(5 tests):rotate_certificateand sends notification on commit--commit--messageBulk rotation
rotate -o OLD -n NEW(3 tests):--commit)Celery tasks (
test_celery_tasks.py— 12 tests)certificate_rotate: CLI dispatch, notification config, region routing, SoftTimeLimitExceeded, success metriccertificate_reissue: CLI dispatch, timeout, success metricnotify_expirations: CLI dispatch, config passthrough, timeoutclean_all_sources: per-source task dispatch, success metricContext
The list-mutation bug was discovered during the
*.g2.spotify.commigration — 5 of 6 SSL proxies rotated, 1 silently skipped. The fix (list()snapshot) was already applied upstream before archival, but had no regression test.