Skip to content

Make the NetBox test suite for GraphQL more adaptable to plugins #15559

@peteeckel

Description

@peteeckel

NetBox version

4.0.0-dev

Feature type

Change to existing functionality

Proposed functionality

As a plugin developer I rely on some - admittedly undocumented - parts of the NetBox test framework for my unit tests. This can be done quite easily for API and view tests using the APITestCase and ModelViewTestCase classes and most of the subclasses of APIViewTestCases and ViewTestCases and for ChangeLoggedFilterSetTests.

There is one exception where adjustment to specific plugin conditions is unnecessarily complicated, though, and that's APITestCase.GraphQLTestCase, and that's for a trivial reason.

The _build_query method calls get_graphql_type_for_model(self.model), which is a utility function in the utilities.api module. This is the only place where this function is used, so it could be moved to a private class method which would make it overridable. Unfortunately this is not the case, so the whole _build_query method needs to be overriden in order to replace it with a function that works for a specific plugin. Overriding the much more complex _build_query method is IMHO problematic.

I see that for _get_graphql_base_name provisions have been made to read graphql_base_name from the model's Meta class, but unfortunately it's not possible to add this property to it yet - that could be a way forward that would make overriding test classes unnecessary altogether if it were pursued further, as get_graphql_type_for_model could be adjusted in much the same was, and the same goes for all the test methods. This is much more flexible and elegant than trying to derive the classes and base names etc. from verbose_name etc.

Use case

Extensive testing of plugin functionality

Database changes

None

External dependencies

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: highExpected to require a large amont of time and effort to implement relative to other tasksnetboxstatus: backlogAwaiting selection for worktopic: pluginsRelates to the plugins frameworktype: featureIntroduction of new functionality to the application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions