Skip to content

Commit

Permalink
Resolves #51 & #52
Browse files Browse the repository at this point in the history
  • Loading branch information
whitej6 committed Jul 7, 2022
1 parent 3a4269f commit 85a569f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
21 changes: 18 additions & 3 deletions nautobot_firewall_models/models/core_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ def get_absolute_url(self):

def __str__(self):
"""Stringify instance."""
return self.name
if self.port:
return f"{self.name} ({self.ip_protocol}/{self.port})"
return f"{self.name} ({self.ip_protocol})"

def save(self, *args, **kwargs):
"""Overload save to call full_clean to ensure validators run."""
Expand Down Expand Up @@ -533,9 +535,22 @@ def get_absolute_url(self):

def __str__(self):
"""Stringify instance."""
if self.request_id:
if self.request_id and self.name:
return f"{self.name} - {self.request_id}"
return self.name
if self.name:
return self.name
if self.source_user or self.source_user_group:
return (
f"Source {self.source_address}/{self.source_address_group} -"
f" Destination {self.destination_address}/{self.destination_address_group} -"
f" Service {self.service}/{self.service_group} -"
f" User {self.source_user}/{self.source_user_group}"
)
return (
f"Source {self.source_address}/{self.source_address_group} -"
f" Destination {self.destination_address}/{self.destination_address_group} -"
f" Service {self.service}/{self.service_group}"
)


@extras_features(
Expand Down
3 changes: 2 additions & 1 deletion nautobot_firewall_models/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class TestVersion(unittest.TestCase):
"""Test Version is the same."""

def test_version(self):
# TODO: Disabled while in beta release, test does not account for beta versions.
def _test_version(self):
"""Verify that pyproject.toml version is same as version specified in the package."""
parent_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
poetry_version = toml.load(os.path.join(parent_path, "pyproject.toml"))["tool"]["poetry"]["version"]
Expand Down
4 changes: 2 additions & 2 deletions nautobot_firewall_models/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_create_protocol_only_required(self):
self.assertEqual(protocol.description, "")
self.assertEqual(protocol.name, "HTTPS")
self.assertEqual(protocol.port, "8443")
self.assertEqual(str(protocol), "HTTPS")
self.assertEqual(str(protocol), "HTTPS (TCP/8443)")

def test_create_protocol_all_fields(self):
"""Creates a protocol with all fields."""
Expand All @@ -102,7 +102,7 @@ def test_create_protocol_all_fields(self):
self.assertEqual(protocol.description, "Encrypted HTTP traffic")
self.assertEqual(protocol.name, "HTTPS")
self.assertEqual(protocol.port, "8443")
self.assertEqual(str(protocol), "HTTPS")
self.assertEqual(str(protocol), "HTTPS (TCP/8443)")

def test_create_service_group_only_required(self):
"""Creates a service group with only required fields."""
Expand Down
7 changes: 0 additions & 7 deletions nautobot_firewall_models/tests/test_ui_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ def test_bulk_import_objects_with_permission(self):
def test_bulk_import_objects_without_permission(self):
pass

def test_service_object_str(self):
"""testing str of service object."""
svc = ServiceObject.objects.first()
svc.ip_protocol = "TCP"

self.assertEqual(str(svc), svc.name)

@skip("on_delete set to PROTECT")
def test_bulk_delete_objects_with_constrained_permission(self):
pass
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poetry]
name = "nautobot-firewall-models"
version = "0.1.0"
version = "0.1.0-beta.0"
description = "Nautobot plugin to model firewall objects."
authors = ["Network to Code, LLC <info@networktocode.com>"]
license = "Apache-2.0"
readme = "README.md"
homepage = "https://github.com/networktocode-llc/nautobot-plugin-firewall-model"
repository = "https://github.com/networktocode-llc/nautobot-plugin-firewall-model"
homepage = "https://github.com/nautobot/nautobot-plugin-firewall-models"
repository = "https://github.com/nautobot/nautobot-plugin-firewall-models"
keywords = ["nautobot", "nautobot-plugin"]
include = [
"LICENSE",
Expand Down

0 comments on commit 85a569f

Please sign in to comment.