Merge pull request #1305 from chrismeyersfsu/feature-labels

job template labels init implementation
This commit is contained in:
Chris Meyers
2016-03-28 09:01:12 -04:00
12 changed files with 230 additions and 9 deletions
+12
View File
@@ -16,6 +16,7 @@ from django.conf import settings
# AWX
from awx.main.models.projects import Project
from awx.main.models.organization import Organization, Permission
from awx.main.models.jobs import JobTemplate
from awx.main.models.base import PERM_INVENTORY_READ
from awx.main.models.ha import Instance
from awx.main.models.fact import Fact
@@ -264,3 +265,14 @@ def team(organization):
def permission_inv_read(organization, inventory, team):
return Permission.objects.create(inventory=inventory, team=team, permission_type=PERM_INVENTORY_READ)
@pytest.fixture
def job_template_labels(organization):
jt = JobTemplate(name='test-job_template')
jt.save()
jt.labels.create(name="label-1", organization=organization)
jt.labels.create(name="label-2", organization=organization)
return jt
@@ -0,0 +1,34 @@
import pytest
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()