mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 14:36:00 -03:30
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import pytest
|
|
|
|
# Django
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
# AWX
|
|
from awx.main.models import UnifiedJobTemplate, JobTemplate, WorkflowJobTemplate, Project
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_subclass_types(rando):
|
|
assert set(UnifiedJobTemplate._submodels_with_roles()) == set([
|
|
ContentType.objects.get_for_model(JobTemplate).id,
|
|
ContentType.objects.get_for_model(Project).id,
|
|
ContentType.objects.get_for_model(WorkflowJobTemplate).id
|
|
])
|
|
|
|
|
|
class TestCreateUnifiedJob:
|
|
'''
|
|
Ensure that copying a job template to a job handles many to many field copy
|
|
'''
|
|
@pytest.mark.django_db
|
|
def test_many_to_many(self, mocker, job_template_labels):
|
|
jt = job_template_labels
|
|
_get_unified_job_field_names = mocker.patch('awx.main.models.jobs.JobTemplate._get_unified_job_field_names', return_value=['labels'])
|
|
j = jt.create_unified_job()
|
|
|
|
_get_unified_job_field_names.assert_called_with()
|
|
assert j.labels.all().count() == 2
|
|
assert j.labels.all()[0] == jt.labels.all()[0]
|
|
assert j.labels.all()[1] == jt.labels.all()[1]
|
|
|
|
'''
|
|
Ensure that data is looked for in parameter list before looking at the object
|
|
'''
|
|
@pytest.mark.django_db
|
|
def test_many_to_many_kwargs(self, mocker, job_template_labels):
|
|
jt = job_template_labels
|
|
mocked = mocker.MagicMock()
|
|
mocked.__class__.__name__ = 'ManyRelatedManager'
|
|
kwargs = {
|
|
'labels': mocked
|
|
}
|
|
_get_unified_job_field_names = mocker.patch('awx.main.models.jobs.JobTemplate._get_unified_job_field_names', return_value=['labels'])
|
|
jt.create_unified_job(**kwargs)
|
|
|
|
_get_unified_job_field_names.assert_called_with()
|
|
mocked.all.assert_called_with()
|