Skip to content

Gsoc2025 refactor analyzer test docs #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion docs/IntelOwl/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,33 @@ You may want to look at a few existing examples to start to build a new one, suc
After having written the new python module, you have to remember to:

1. Put the module in the `file_analyzers` or `observable_analyzers` directory based on what it can analyze
2. Remember to use `_monkeypatch()` in its class to create automated tests for the new analyzer. This is a trick to have tests in the same class of its analyzer.
2. **Write Unit Tests for the Analyzer**
- Monkeypatch-based tests are no longer used.
- Instead, write a unit test class that inherits from `BaseAnalyzerTest` located at:
```
tests/api_app/analyzers_manager/unit_tests/[observable_analyzers|file_analyzers]/base_test_class.py
```
- Place your test file under the appropriate directory (`observable_analyzers` or `file_analyzers`).
- Example structure:
```
tests/
└── api_app/
└── analyzers_manager/
└── unit_tests/
├── observable_analyzers/
│ ├── test_mynewanalyzer.py
│ └── base_test_class.py
└── file_analyzers/
├── ...
```

- Your test case should:
- Set `analyzer_class = YourAnalyzerClass`
- Implement `get_mocked_response()` using `unittest.mock.patch` to mock external calls
- Optionally implement `get_extra_config()` to provide additional runtime config

- **For reference**, you can find numerous analyzer test examples already implemented under `tests/api_app/analyzers_manager/unit_tests/observable_analyzers/` and `file_analyzers/`.

3. Create the configuration inside django admin in `Analyzers_manager/AnalyzerConfigs` (\* = mandatory, ~ = mandatory on conditions)
1. \*Name: specific name of the configuration
2. \*Python module: <module_name>.<class_name>
Expand Down