Skip to content

Commit 728c092

Browse files
AlanCodingPeter Braun
authored andcommitted
Successfully test collection of event_query.yml data (#15761)
* Callback plugin method from cmeyers adapted to global collection list Get tests passing Mild rebranding Put behind feature flag, flip true in dev Add noqa flag * Add missing wait_for_events
1 parent 344fd19 commit 728c092

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

awx/main/tests/live/tests/projects/test_indirect_host_counting.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
import yaml
2+
3+
from awx.main.tests.live.tests.conftest import wait_for_events
4+
15
from awx.main.tasks.host_indirect import build_indirect_host_data
26
from awx.main.models import Job
37

48

59
def test_indirect_host_counting(live_tmp_folder, run_job_from_playbook):
610
run_job_from_playbook('test_indirect_host_counting', 'run_task.yml', scm_url=f'file://{live_tmp_folder}/test_host_query')
711
job = Job.objects.filter(name__icontains='test_indirect_host_counting').order_by('-created').first()
12+
wait_for_events(job) # We must wait for events because system tasks iterate on job.job_events.filter(...)
813

914
# Data matches to awx/main/tests/data/projects/host_query/meta/event_query.yml
1015
# this just does things in-line to be a more localized test for the immediate testing
11-
event_query = {'demo.query.example': '{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}'}
16+
module_jq_str = '{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}'
17+
event_query = {'demo.query.example': module_jq_str}
1218

1319
# Run the task logic directly with local data
1420
results = build_indirect_host_data(job, event_query)
@@ -18,3 +24,12 @@ def test_indirect_host_counting(live_tmp_folder, run_job_from_playbook):
1824
# Asserts on data that will match to the input jq string from above
1925
assert host_audit_entry.canonical_facts == {'host_name': 'foo_host_default'}
2026
assert host_audit_entry.facts == {'device_type': 'Fake Host'}
27+
28+
# Test collection of data
29+
assert 'demo.query' in job.installed_collections
30+
assert 'host_query' in job.installed_collections['demo.query']
31+
hq_text = job.installed_collections['demo.query']['host_query']
32+
hq_data = yaml.safe_load(hq_text)
33+
assert hq_data == {'demo.query.example': module_jq_str}
34+
35+
assert job.ansible_version

0 commit comments

Comments
 (0)