Skip to content

Commit

Permalink
Adds tests for multiple features
Browse files Browse the repository at this point in the history
  • Loading branch information
joewesch committed Aug 28, 2023
1 parent d8e9521 commit 47f8b1e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion nautobot_golden_config/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def setUp(self):
self.feature1 = self.rule1.feature
self.rule2 = create_feature_rule_cli(self.device2, feature="Feature 2")
self.feature2 = self.rule2.feature
self.rule3 = create_feature_rule_cli(self.device1, feature="Feature 3")
self.feature3 = self.rule3.feature
self.status1 = Status.objects.get(name="Not Approved")
self.status2 = Status.objects.get(name="Approved")
self.tag1, _ = Tag.objects.get_or_create(name="Tag 1")
Expand Down Expand Up @@ -360,7 +362,7 @@ def setUp(self):
job_result_id=self.job_result2.id,
)
self.config_plan3.tags.add(self.tag2)
self.config_plan3.feature.add(self.feature1)
self.config_plan3.feature.set([self.feature1, self.feature3])
self.config_plan3.validated_save()
self.config_plan4 = models.ConfigPlan.objects.create(
device=self.device2,
Expand Down
22 changes: 22 additions & 0 deletions nautobot_golden_config/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,28 @@ def test_create_config_plan_intended(self):
self.assertEqual(config_plan.status, self.status)
self.assertEqual(config_plan.plan_type, "intended")

def test_create_config_plan_intended_multiple_features(self):
"""Test Create Object."""
rule2 = create_feature_rule_json(self.device, feature="feature2")
config_plan = ConfigPlan.objects.create(
device=self.device,
plan_type="intended",
config_set="test intended config",
change_control_id="1234",
change_control_url="https://1234.example.com/",
status=self.status,
job_result_id=self.job_result.id,
)
config_plan.feature.set([self.feature, rule2.feature])
config_plan.validated_save()
self.assertEqual(config_plan.device, self.device)
self.assertIn(self.feature.id, config_plan.feature.all().values_list("id", flat=True))
self.assertIn(rule2.feature.id, config_plan.feature.all().values_list("id", flat=True))
self.assertEqual(config_plan.config_set, "test intended config")
self.assertEqual(config_plan.change_control_id, "1234")
self.assertEqual(config_plan.status, self.status)
self.assertEqual(config_plan.plan_type, "intended")

def test_create_config_plan_missing(self):
"""Test Create Object."""
config_plan = ConfigPlan.objects.create(
Expand Down
5 changes: 3 additions & 2 deletions nautobot_golden_config/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_csv_export_with_filter(self):
self.assertEqual(device_names_in_export, device_names_in_site_1)


# pylint: disable=too-many-ancestors
# pylint: disable=too-many-ancestors,too-many-locals
class ConfigPlanTestCase(
ViewTestCases.GetObjectViewTestCase,
ViewTestCases.GetObjectChangelogViewTestCase,
Expand All @@ -321,6 +321,7 @@ def setUpTestData(cls):
rule1 = create_feature_rule_json(device1, feature="Test Feature 1")
rule2 = create_feature_rule_json(device2, feature="Test Feature 2")
rule3 = create_feature_rule_json(device3, feature="Test Feature 3")
rule4 = create_feature_rule_json(device3, feature="Test Feature 4")

job_result1 = create_job_result()
job_result2 = create_job_result()
Expand Down Expand Up @@ -360,7 +361,7 @@ def setUpTestData(cls):
status=not_approved_status,
job_result_id=job_result3.id,
)
plan3.feature.add(rule3.feature)
plan3.feature.set([rule3.feature, rule4.feature])
plan3.validated_save()

# Used for EditObjectViewTestCase
Expand Down

0 comments on commit 47f8b1e

Please sign in to comment.