Skip to content
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

Adds some tests #227

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10"]
nautobot-version: ["1.5.4", "latest"]
nautobot-version: ["1.5.4", "stable"]
runs-on: "ubuntu-20.04"
env:
INVOKE_NAUTOBOT_CHATOPS_PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
1 change: 1 addition & 0 deletions changes/227.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added some tests for VLAN chatops.
1 change: 1 addition & 0 deletions changes/227.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed parameters that should be set to None if they have not been defined yet by default.
56 changes: 56 additions & 0 deletions nautobot_chatops/tests/workers/test_nautobot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests for the /nautobot chatops commands."""
from unittest.mock import MagicMock

from django.test import TestCase
from nautobot.dcim.models import Site
from nautobot.ipam.models import VLAN
from nautobot.extras.models import Status
from nautobot_chatops.choices import CommandStatusChoices

from nautobot_chatops.dispatchers import Dispatcher
from nautobot_chatops.workers.nautobot import get_vlans


class IpamTestCase(TestCase):
"""Tests related to IPAM ChatOps commands."""

def setUp(self):
"""Per-test-case setup function."""
self.active_status = Status.objects.get(name="Active")
self.site = Site.objects.create(name="site-1", status=self.active_status)
self.vlans, _ = VLAN.objects.get_or_create(vid=1, name="vlan-1", status=self.active_status, site=self.site)

# Mock the dispatcher
self.dispatcher = MagicMock(Dispatcher)

def test_get_vlans_initial_prompt(self):
"""Test get VLANs initial command."""
self.assertFalse(get_vlans(self.dispatcher))
self.dispatcher.send_error.assert_not_called()
self.dispatcher.prompt_from_menu.assert_called_with(
"nautobot get-vlans",
"select a vlan filter",
[
("VLAN ID", "id"),
("Group", "group"),
("Name", "name"),
("Role", "role"),
("Site", "site"),
("Status", "status"),
("Tenant", "tenant"),
("All (no filter)", "all"),
],
)

def test_get_vlans_filter_type_sent_filter_name(self):
"""Test get VLANs with filter type Name selected."""
self.assertFalse(get_vlans(self.dispatcher, "name"))
self.dispatcher.send_error.assert_not_called()
self.dispatcher.prompt_from_menu.assert_called_with(
"nautobot get-vlans name", "select a vlan name", [("vlan-1", "vlan-1")], offset=0
)

def test_get_vlans_filter_type_sent_filter_all(self):
"""Test get VLANs with filter type All selected."""
self.assertEqual(get_vlans(self.dispatcher, "all"), CommandStatusChoices.STATUS_SUCCEEDED)
self.dispatcher.send_error.assert_not_called()
2 changes: 1 addition & 1 deletion nautobot_chatops/workers/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def examine_termination_endpoints(circuit):

# pylint: disable=too-many-statements
@subcommand_of("nautobot")
def get_vlans(dispatcher, filter_type, filter_value_1):
def get_vlans(dispatcher, filter_type=None, filter_value_1=None):
"""Return a filtered list of VLANs based on filter type and/or `filter_value_1`."""
# pylint: disable=no-else-return
if not filter_type:
Expand Down