intelowlproject / IntelOwl

IntelOwl: manage your Threat Intelligence at scale
https://intelowlproject.github.io
GNU Affero General Public License v3.0
3.85k stars 440 forks source link

Updated the test_interfaces.py with few enhancement. #2535

Closed vignesh1507 closed 3 weeks ago

vignesh1507 commented 1 month ago

Summary of Code Changes

  1. Renamed Test class to TestInterface

    • Reason: More descriptive name that clearly indicates its purpose.
  2. Fixed __init__ method

    • Changed: **init** to __init__
    • Reason: Correct syntax for Python special methods.
  3. Renamed test method

    • Changed: test_validate_playbook_to_execute to test_validate_playbooks
    • Reason: Matches the actual method being tested (validate_playbooks).
  4. Added docstrings

    • Added to TestInterface class and test_validate_playbooks method
    • Reason: Improves code documentation and clarity.
  5. Refactored repetitive code into a helper function

    • Created create_and_test_playbook function inside the test method
    • Reason: Reduces code duplication and improves readability.
  6. Simplified exception handling

    • Removed try/except blocks that were failing the test on exception
    • Used assertRaises for negative test case
    • Reason: More idiomatic way to test for exceptions in unit tests.
  7. Improved variable naming

    • Changed: a to interface
    • Reason: More descriptive name for what the variable represents.
  8. Restructured test cases

    • Now testing three scenarios (no owner, user as owner, superuser as owner) using the same function
    • Reason: More concise and clearly shows the different scenarios being tested.
  9. Removed explicit deletion of PlaybookConfig objects

    • Deletion now happens at the end of each test case in the helper function
    • Reason: Ensures cleanup happens even if an assertion fails.
  10. Removed unused import

    • Removed: from django.db.models import QuerySet
    • Reason: This import was not being used explicitly in the code.
mlodic commented 1 month ago

hey please install linters as suggested in the doc and fix the CI issue

mlodic commented 3 weeks ago

I am not accepting this contribution cause it does not respect the PR rules + the change is not an improvement. If you want to re-use code in tests you should leverage elements of the unittest framework like setUp and not nested functions like you did