Skip to content

Fixes #47 [Housekeeping]: Develop Plugin Tests - Models #257

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 18 commits into
base: dev
Choose a base branch
from

Conversation

pheus
Copy link
Contributor

@pheus pheus commented Mar 23, 2025

Pull Request

Related Issue

Fixes: #47 [Housekeeping] Develop Plugin Tests - Models
Fixes #258 [Bug] ACL Interface Assignment Should Be Unique per Interface and Direction

New Behavior

  • Adds model tests for the NetBox ACLs Plugin to improve test coverage.

Contrast to Current Behavior

  • Introduces comprehensive test cases, increasing coverage and helping detect side effects in new development.

Discussion: Benefits and Drawbacks

  • Benefits:
    • Enhances confidence in changes by ensuring the plugin’s model behavior is verified.
    • Prevents regressions by catching issues early during development.
  • Drawbacks:
    • No significant drawbacks, as this is an improvement to test coverage.

Changes to the Documentation

  • Documentation may be updated to outline the extended test coverage for new features.

Proposed Release Note Entry

  • Expanded test coverage for NetBox ACLs Plugin models.

Attribution

Some of the code in this PR is based on previous work by @ryanmerolle in PR #134.

Double Check

  • I have explained my PR according to the information in the comments
    or in a linked issue.
  • My PR targets the dev branch.

ryanmerolle and others added 11 commits March 23, 2025 11:42
Renames `test_models.py` to `models/test_accesslists.py` to improve
test organization and maintainability. This is a structural change
with no modifications to test logic.
Refactor test setup to improve data creation and reusability. Add
detailed fixtures for devices, virtual chassis, clusters,
virtual machines, and prefixes. Update all assignments to reference the
new fixtures for better consistency.
Add test cases to validate AccessList creation and uniqueness for
VirtualChassis and VirtualMachine objects. Extend coverage by ensuring
proper handling of duplicate names and enforcing unique constraints.
@pheus
Copy link
Contributor Author

pheus commented Mar 23, 2025

Note: This is a draft PR.

I rebased the work by @ryanmerolle from PR #134, cleaned up the codebase, and added additional tests. I'll be adding tests for ACLStandardRule and ACLExtendedRule in the coming days.

pheus added 6 commits March 24, 2025 22:08
Introduces internationalization (i18n) to AccessList models. Updates field
definitions to use `gettext_lazy` for translations and improves model class
field consistency. Includes minor corrections to docstrings and comments.
Move validation to the `save` method to enforce that the assigned
interface's host matches the access list's host before saving.
This replaces validation in the `clean` method for better data integrity
enforcement.
Improve test coverage for ACLInterfaceAssignment validation.
Add tests for valid and invalid direction choices,
duplicate assignments, and missing host assignments to ensure robust
validation logic.
Fixes the unique constraint for ACLInterfaceAssignment by removing the
access_list field from the uniqueness check.
Ensures that only one ACL can be assigned per interface and direction.
Adds validation tests to prevent multiple ACLs from being assigned in
the same direction on the same interface.

Fixes netbox-community#258
Moves ACL rule validation logic from forms to model methods to ensure
consistent enforcement across all usages. This improves maintainability
and eliminates redundant validation code.
Adds comprehensive tests for the ACLStandardRule model. Tests cover rule
creation scenarios, validation constraints, and edge cases,
ensuring thorough model behavior validation.

Fixes netbox-community#47
@pheus pheus force-pushed the housekeeping/47-develop-plugin-tests-models branch from 5fb926c to dc69c16 Compare March 28, 2025 15:10
Introduces comprehensive test cases for the ACLExtendedRule model. These
cover rule creation, validation, and edge cases such as duplicate
indices and invalid combinations of parameters.

Fixes netbox-community#47
@pheus pheus force-pushed the housekeeping/47-develop-plugin-tests-models branch from dc69c16 to a872eea Compare March 28, 2025 22:09
@pheus pheus marked this pull request as ready for review March 28, 2025 22:15
@pheus
Copy link
Contributor Author

pheus commented Mar 28, 2025

I included a fix for Bug #258, as it was necessary to properly test the uniqueness of Interface and Direction.

Additionally, I cleaned up the model files access_lists.py and access_list_rules.py and added i18n (internationalization) support.

I appreciate your time reviewing all these changes. Thank you, @cruse1977 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants