Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Oct 20, 2024
1 parent d290749 commit dbac934
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions validity/tests/test_models/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ class TestPoller:
"connection_type, command_type, is_valid", [("netmiko", "CLI", True), ("netmiko", "netconf", False)]
)
@pytest.mark.django_db
def test_match_command_type(self, connection_type, command_type, is_valid):
def test_match_command_type(self, connection_type, command_type, is_valid, di):
command = CommandFactory(type=command_type)
ctx = nullcontext() if is_valid else pytest.raises(ValidationError)
with ctx:
Poller.validate_commands(connection_type=connection_type, commands=[command])
Poller.validate_commands(
connection_type=connection_type, commands=[command], command_types=di["PollerChoices"].command_types
)

@pytest.mark.parametrize(
"retrive_config, is_valid",
Expand All @@ -127,4 +129,4 @@ def only_one_config_command(self, retrive_config, is_valid):
commands = [CommandFactory(type=t) for t in retrive_config]
ctx = nullcontext() if is_valid else pytest.raises(ValidationError)
with ctx:
Poller.validate_commands(connection_type="CLI", commands=commands)
Poller.validate_commands(connection_type="CLI", commands=commands, command_types={})
6 changes: 3 additions & 3 deletions validity/tests/test_pollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestNetmikoPoller:
@pytest.fixture
def get_mocked_poller(self, monkeypatch):
def _get_poller(credentials, commands, mock):
monkeypatch.setattr(NetmikoPoller, "driver_cls", mock)
monkeypatch.setattr(NetmikoPoller, "driver_factory", mock)
return NetmikoPoller(credentials, commands)

return _get_poller
Expand All @@ -30,8 +30,8 @@ def test_get_driver(self, get_mocked_poller, get_mocked_device):
poller = get_mocked_poller(credentials, [], Mock())
device = get_mocked_device("1.1.1.1")
assert poller.get_credentials(device) == credentials | {poller.host_param_name: "1.1.1.1"}
assert poller.get_driver(device) == poller.driver_cls.return_value
poller.driver_cls.assert_called_once_with(**credentials, **{poller.host_param_name: "1.1.1.1"})
assert poller.get_driver(device) == poller.driver_factory.return_value
poller.driver_factory.assert_called_once_with(**credentials, **{poller.host_param_name: "1.1.1.1"})

def test_poll_one_command(self, get_mocked_poller):
poller = get_mocked_poller({}, [], Mock())
Expand Down

0 comments on commit dbac934

Please sign in to comment.