-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbac934
commit 905bdd3
Showing
11 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .base import CustomPoller, Poller | ||
from .base import BasePoller, CustomPoller | ||
from .cli import NetmikoPoller | ||
from .http import RequestsPoller | ||
from .netconf import ScrapliNetconfPoller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from http import HTTPStatus | ||
from typing import Any | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from factories import CommandFactory, PollerFactory | ||
|
||
from validity.dependencies import validity_settings | ||
from validity.forms import PollerForm | ||
from validity.models.polling import Command | ||
from validity.pollers import CustomPoller | ||
from validity.settings import PollerInfo, ValiditySettings | ||
|
||
|
||
class MyCustomPoller(CustomPoller): | ||
host_param_name = "ip_address" | ||
driver_factory = Mock | ||
|
||
def poll_one_command(self, driver: Any, command: Command) -> str: | ||
return "output" | ||
|
||
|
||
@pytest.fixture | ||
def custom_poller(db, di): | ||
settings = ValiditySettings( | ||
custom_pollers=[PollerInfo(klass=MyCustomPoller, name="cupo", color="red", command_types=["custom"])] | ||
) | ||
override = di.override({validity_settings: lambda: settings}) | ||
override.__enter__() | ||
yield PollerFactory(connection_type="cupo") | ||
override.__exit__(None, None, None) | ||
|
||
|
||
def test_custom_poller_model(custom_poller, di): | ||
poller = PollerFactory(connection_type="cupo") | ||
poller.commands.set([CommandFactory(type="custom")]) | ||
backend = poller.get_backend() | ||
assert isinstance(backend, MyCustomPoller) | ||
assert poller.get_connection_type_color() == "red" | ||
poller.validate_commands(poller.commands.all(), di["PollerChoices"].command_types, poller.connection_type) | ||
|
||
|
||
def test_custom_poller_api(custom_poller, admin_client): | ||
resp = admin_client.get(f"/api/plugins/validity/pollers/{custom_poller.pk}/") | ||
assert resp.status_code == HTTPStatus.OK | ||
assert resp.json()["connection_type"] == "cupo" | ||
|
||
|
||
def test_custom_poller_form(custom_poller): | ||
form = PollerForm() | ||
form_choices = {choice[0] for choice in form["connection_type"].field.choices} | ||
assert "cupo" in form_choices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
from factories import PollerFactory | ||
|
||
from validity.pollers import NetmikoPoller, RequestsPoller, ScrapliNetconfPoller | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"connection_type, poller_class", | ||
[("netmiko", NetmikoPoller), ("requests", RequestsPoller), ("scrapli_netconf", ScrapliNetconfPoller)], | ||
) | ||
@pytest.mark.django_db | ||
def test_get_backend(connection_type, poller_class): | ||
poller = PollerFactory(connection_type=connection_type) | ||
backend = poller.get_backend() | ||
assert isinstance(backend, poller_class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters