Testing Strategy¶
The Downloads Cleanup Manager uses pytest to guarantee system stability and prevent regressions. Since the application is built using Domain-Driven Design (DDD), our testing strategy perfectly mirrors the architecture, testing each layer in complete isolation before validating the full pipeline.
1. Unit Testing Suite¶
The unit tests are located in tests/unit/ and are organized by layer.
Domain Layer Tests (tests/unit/domain/)¶
Domain tests do not require the file system or configuration files. They purely test business logic.
test_models.py: Validates theFileItemmodel's size calculations and extension parsing.test_rules.py: EnsuresKeywordRule,ExtensionRule, andMimeRulecorrectly evaluate files based on strict matching logic.test_policies.py: VerifiesArchivePolicylogic for excluding large files and calculating expiration dates.
Application Layer Tests (tests/unit/application/)¶
test_use_cases.py: Instantiates theOrganizeDownloadsUseCaseusing mock dependencies (in-memory file system and fake configuration). It verifies that files are routed in the correct order: Keywords > Extensions > MIME types > Archive fallback.
Infrastructure Layer Tests (tests/unit/infrastructure/)¶
Infrastructure tests validate that our adapters correctly interact with Python libraries and the operating system.
test_config_parser.py: VerifiesJsonConfigAdaptercan parseconfig.jsonand expand environment variables ($HOME).test_file_system.py: Usespytest'stmp_pathfixture to write real files to disk and verifyLocalFileSystemAdaptercan safely move them, preventing overwrite collisions.test_magic_mime.py: VerifiesMagicMimeDetectorinterfaces successfully withpython-magic.test_notifications.py: Mockssmtplibto guarantee thatSmtpNotifierbuilds the correct email payload without actually sending emails.
2. Integration Testing¶
The integration test suite is located in tests/integration/.
test_pipeline.py: This runs an end-to-end "Dry Run" test. It writes real files to a temporarydownloads/directory, loads a mockconfig.jsonfile using the realJsonConfigAdapter, executes the Use Case using the realLocalFileSystemAdapter, and validates that the output actions exactly match expectations.
3. Running Tests Locally¶
To run the entire test suite, open a terminal in the root directory and ensure the conda environment is active:
4. Continuous Integration (CI)¶
I utilize GitHub Actions to automate testing and documentation deployment.
ci.yml: Triggers on every push and pull request to themainbranch. It sets up Miniconda, installs dependencies, and runspytest. If any test fails, the commit is marked with a red cross.docs.yml: Triggers on every push to themainbranch. It builds this very MkDocs documentation website and automatically deploys it to thegh-pagesbranch.