Skip to content

Commit

Permalink
test: Fixed unittest for deployment rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
abates committed Jun 25, 2024
1 parent a56c8ca commit e8fb1b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions nautobot_design_builder/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from typing import Type
from unittest import mock
from unittest.mock import PropertyMock, patch
import uuid

from django.contrib.contenttypes.models import ContentType
from django.test import TestCase

from nautobot.extras.utils import refresh_job_model_from_job_class
from nautobot.extras.models import Job
from nautobot.extras.models import Job, JobResult
from nautobot_design_builder.design_job import DesignJob

logging.disable(logging.INFO)
Expand All @@ -24,7 +26,7 @@ def setUp(self):
"""Setup a mock git repo to watch for config context creation."""
super().setUp()
self.data = {
"instance_name": "Test Design",
"deployment_name": "Test Design",
}
self.logged_messages = []
self.git_patcher = patch("nautobot_design_builder.ext.GitRepo")
Expand All @@ -37,9 +39,12 @@ def setUp(self):

def get_mocked_job(self, design_class: Type[DesignJob]):
"""Create an instance of design_class and properly mock request and job_result for testing."""
refresh_job_model_from_job_class(Job, design_class)
job_model, _ = refresh_job_model_from_job_class(Job, design_class)
job = design_class()
job.job_result = mock.Mock()
job.job_result = JobResult.objects.create(
name="Fake Job Result",
job_model=job_model,
)
job.saved_files = {}

def save_design_file(filename, content):
Expand Down
1 change: 1 addition & 0 deletions nautobot_design_builder/tests/designs/test_designs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class Meta: # pylint:disable=too-few-public-methods
SimpleDesign3,
SimpleDesignReport,
MultiDesignJob,
DesignJobModeDeploymentWithError,
MultiDesignJobWithError,
DesignJobWithExtensions,
DesignWithRefError,
Expand Down
2 changes: 1 addition & 1 deletion nautobot_design_builder/tests/test_design_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_simple_design_rollback_deployment_mode(self):
"""Confirm that database changes are rolled back when an exception is raised and no Design Deployment is created."""
self.assertEqual(0, Manufacturer.objects.all().count())
job = self.get_mocked_job(test_designs.DesignJobModeDeploymentWithError)
job.run(data={**self.data, **{"deployment_name": "whatever"}}, dryrun=False)
self.assertRaises(DesignImplementationError, job.run, dryrun=False, **self.data)
self.assertEqual(0, Manufacturer.objects.all().count())
self.assertEqual(0, Deployment.objects.all().count())

Expand Down

0 comments on commit e8fb1b3

Please sign in to comment.