Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-boulharts committed Dec 18, 2023
1 parent 8e862a6 commit c0292b0
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions tests/test_service_catalog/test_models/test_operations.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
from service_catalog.models import Operation
from service_catalog.models import Operation, OperationType
from tests.test_service_catalog.base import BaseTest


class TestOperation(BaseTest):

def assertSurveyIsValid(self):
self.job_template_test.refresh_from_db()
position = 0
for field in self.job_template_test.survey["spec"]:
self.assertTrue(
self.new_operation.tower_survey_fields.filter(variable=field["variable"],
is_customer_field=True, position=position).exists())
position += 1
self.assertEqual(len(self.job_template_test.survey["spec"]), self.new_operation.tower_survey_fields.count())

def setUp(self):
super(TestOperation, self).setUp()
self.new_operation = Operation.objects.create(name="new test",
type=OperationType.UPDATE,
service=self.service_test,
job_template=self.job_template_test,
process_timeout_second=20)

def test_survey_from_job_template_is_copied_on_create(self):
new_operation = Operation.objects.create(name="new test",
service=self.service_test,
job_template=self.job_template_test,
process_timeout_second=20)
for field in self.job_template_test.survey["spec"]:
self.assertTrue(new_operation.tower_survey_fields.filter(variable=field["variable"], is_customer_field=True).exists())
self.assertSurveyIsValid()

def test_service_is_disabled_when_the_create_operation_disabled(self):
self.assertTrue(self.create_operation_test.service.enabled)
Expand All @@ -22,3 +32,29 @@ def test_service_is_disabled_when_the_create_operation_disabled(self):
self.create_operation_test.save()
self.assertFalse(self.create_operation_test.service.enabled)
self.assertFalse(self.create_operation_test.enabled)

def test_update_survey_when_position_is_default(self):
self.new_operation.tower_survey_fields.update(position=0)
self.assertFalse(self.new_operation.tower_survey_fields.exclude(position=0).exists())
self.new_operation.update_survey()
self.assertSurveyIsValid()

def test_update_survey_when_field_is_removed_from_awx(self):
previous_count = len(self.job_template_test.survey["spec"])
self.job_template_test.survey["spec"].pop(1)
self.job_template_test.save()
current_count = len(self.job_template_test.survey["spec"])
self.assertEqual(previous_count - 1, current_count)
self.new_operation.update_survey()
self.assertSurveyIsValid()

def test_update_survey_when_field_is_added_from_awx(self):
previous_count = len(self.job_template_test.survey["spec"])
tmp = self.job_template_test.survey["spec"][1]
self.job_template_test.survey["spec"][1]["variable"] = "test_swapped"
self.job_template_test.survey["spec"].append(tmp)
self.job_template_test.save()
current_count = len(self.job_template_test.survey["spec"])
self.assertEqual(previous_count + 1, current_count)
self.new_operation.update_survey()
self.assertSurveyIsValid()

0 comments on commit c0292b0

Please sign in to comment.