IntelOwl icon indicating copy to clipboard operation
IntelOwl copied to clipboard

Updated the test_interfaces.py with few enhancement.

Open vignesh1507 opened this issue 1 year ago • 1 comments

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.

vignesh1507 avatar Oct 15 '24 06:10 vignesh1507

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

mlodic avatar Oct 18 '24 14:10 mlodic

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

mlodic avatar Oct 29 '24 11:10 mlodic