Split test_repositories.py into separate files for better maintainability. Closes #703#704
Conversation
- Split 1111-line test_repositories.py into 6 focused test files - test_ioc_repository.py (561 lines): IOC and scoring tests - test_sensor_repository.py (58 lines): Sensor tests - test_cowrie_session_repository.py (175 lines): Cowrie session tests - test_elastic_repository.py (224 lines): Elasticsearch tests - test_firehol_repository.py (39 lines): FireHol tests - test_mass_scanner_repository.py (37 lines): Mass scanner tests - All 101 tests pass successfully - Improved maintainability and navigation
There was a problem hiding this comment.
Pull request overview
This PR refactors the test suite by splitting a monolithic 1,111-line test_repositories.py file into 6 focused test files, each dedicated to testing a specific repository class. This is a pure code organization change with no modifications to test logic.
Changes:
- Deleted the original
test_repositories.pyfile containing all repository tests - Created 6 new test files, each focusing on a single repository class with appropriate imports
- Maintained all 101 tests with identical logic and behavior
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_repositories.py | Removed monolithic file containing all repository tests (1,111 lines) |
| tests/test_ioc_repository.py | Added IOC repository tests including scoring integration and cleanup tests (561 lines) |
| tests/test_sensor_repository.py | Added sensor repository tests for IP address validation and caching (58 lines) |
| tests/test_cowrie_session_repository.py | Added Cowrie session repository tests including cleanup methods (175 lines) |
| tests/test_elastic_repository.py | Added Elasticsearch repository tests and time window calculation tests (224 lines) |
| tests/test_firehol_repository.py | Added FireHol repository tests for blocklist management (39 lines) |
| tests/test_mass_scanner_repository.py | Added mass scanner repository tests (37 lines) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/test_ioc_repository.py
Outdated
| self.repo._honeypot_cache.clear() | ||
| hp = self.repo.create_honeypot("UniqueNewPot123") | ||
| self.assertEqual(hp.name, "UniqueNewPot123") | ||
| self.assertTrue("uniquenewpot123" in self.repo._honeypot_cache) |
There was a problem hiding this comment.
assertTrue(a in b) cannot provide an informative message. Using assertIn(a, b) instead will give more informative messages.
| self.assertTrue("uniquenewpot123" in self.repo._honeypot_cache) | |
| self.assertIn("uniquenewpot123", self.repo._honeypot_cache) |
There was a problem hiding this comment.
Feel free to accept or ignore this. As you like. @opbot-xd
There was a problem hiding this comment.
Thanks for the suggestion You're absolutely right - assertIn provides much better error messages than assertTrue(x in y).
I've applied the change and pushed the update. The assertion now reads:
self.assertIn("uniquenewpot123", self.repo._honeypot_cache)Applied Copilot suggestion to improve test assertion readability. Replace assertTrue(x in y) with assertIn(x, y) for more informative error messages when tests fail.
Description
This PR splits the monolithic
test_repositories.pyfile (1,111 lines) into 6 separate, focused test files - one for each repository class. This improves code maintainability, navigation, and scalability as the test suite grows.Files created:
test_ioc_repository.py(561 lines): IOC and scoring teststest_sensor_repository.py(58 lines): Sensor teststest_cowrie_session_repository.py(175 lines): Cowrie session teststest_elastic_repository.py(224 lines): Elasticsearch teststest_firehol_repository.py(39 lines): FireHol teststest_mass_scanner_repository.py(37 lines): Mass scanner testsTest verification:
Related issues
Closes #703
Type of change
Checklist
develop.Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.