mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 22:16:00 -03:30
Inventory source file-type combined with a linked project will allow the inventory source to be updated when the project is updated. The inventory update runs in the post-run hook of the project update.
44 lines
2.0 KiB
Python
44 lines
2.0 KiB
Python
import pytest
|
|
import mock
|
|
import os
|
|
|
|
from awx.main.tasks import RunProjectUpdate, RunInventoryUpdate
|
|
from awx.main.models import ProjectUpdate, InventoryUpdate
|
|
|
|
|
|
@pytest.fixture
|
|
def scm_revision_file(tmpdir_factory):
|
|
# Returns path to temporary testing revision file
|
|
revision_file = tmpdir_factory.mktemp('revisions').join('revision.txt')
|
|
with open(str(revision_file), 'w') as f:
|
|
f.write('1234567890123456789012345678901234567890')
|
|
return os.path.join(revision_file.dirname, 'revision.txt')
|
|
|
|
|
|
@pytest.mark.django_db
|
|
class TestDependentInventoryUpdate:
|
|
|
|
def test_dependent_inventory_updates_is_called(self, scm_inventory_source, scm_revision_file):
|
|
task = RunProjectUpdate()
|
|
task.revision_path = scm_revision_file
|
|
proj_update = ProjectUpdate.objects.create(project=scm_inventory_source.scm_project)
|
|
with mock.patch.object(RunProjectUpdate, '_update_dependent_inventories') as inv_update_mck:
|
|
task.post_run_hook(proj_update, 'successful')
|
|
inv_update_mck.assert_called_once_with(scm_inventory_source.scm_project, mock.ANY)
|
|
|
|
def test_no_unwanted_dependent_inventory_updates(self, project, scm_revision_file):
|
|
task = RunProjectUpdate()
|
|
task.revision_path = scm_revision_file
|
|
proj_update = ProjectUpdate.objects.create(project=project)
|
|
with mock.patch.object(RunProjectUpdate, '_update_dependent_inventories') as inv_update_mck:
|
|
task.post_run_hook(proj_update, 'successful')
|
|
assert not inv_update_mck.called
|
|
|
|
def test_dependent_inventory_updates(self, scm_inventory_source):
|
|
task = RunProjectUpdate()
|
|
with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock:
|
|
task._update_dependent_inventories(scm_inventory_source.scm_project, [scm_inventory_source])
|
|
assert InventoryUpdate.objects.count() == 1
|
|
inv_update = InventoryUpdate.objects.first()
|
|
iu_run_mock.assert_called_once_with(inv_update.id)
|