copy organization when copying a WFJT

This commit is contained in:
AlanCoding 2016-11-19 11:33:26 -05:00
parent 31a95e5c04
commit 4a992e531a
4 changed files with 16 additions and 7 deletions

View File

@ -79,10 +79,6 @@ class SurveyJobTemplateMixin(models.Model):
default={},
)
@classmethod
def _get_unified_jt_copy_names(cls):
return cls._get_unified_job_field_names() + ['survey_spec', 'survey_enabled']
def survey_password_variables(self):
vars = []
if self.survey_enabled and 'spec' in self.survey_spec:

View File

@ -357,6 +357,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
dest_field.add(*list(src_field_value.all().values_list('id', flat=True)))
return unified_job
@classmethod
def _get_unified_jt_copy_names(cls):
return cls._get_unified_job_field_names()
def copy_unified_jt(self):
'''
Create a copy of this unified job template.

View File

@ -362,7 +362,13 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl
@classmethod
def _get_unified_job_field_names(cls):
return ['name', 'description', 'extra_vars', 'labels', 'survey_passwords', 'schedule', 'launch_type']
return ['name', 'description', 'extra_vars', 'labels', 'survey_passwords',
'schedule', 'launch_type']
@classmethod
def _get_unified_jt_copy_names(cls):
return (super(WorkflowJobTemplate, cls)._get_unified_jt_copy_names() +
['survey_spec', 'survey_enabled', 'organization'])
def get_absolute_url(self):
return reverse('api:workflow_job_template_detail', args=(self.pk,))

View File

@ -99,8 +99,10 @@ class TestWorkflowJob:
@pytest.mark.django_db
class TestWorkflowJobTemplate:
@pytest.fixture
def wfjt(self, workflow_job_template_factory):
wfjt = workflow_job_template_factory('test').workflow_job_template
def wfjt(self, workflow_job_template_factory, organization):
wfjt = workflow_job_template_factory(
'test', organization=organization).workflow_job_template
wfjt.organization = organization
nodes = [WorkflowJobTemplateNode.objects.create(workflow_job_template=wfjt) for i in range(0, 3)]
nodes[0].success_nodes.add(nodes[1])
nodes[1].failure_nodes.add(nodes[2])
@ -145,6 +147,7 @@ class TestWorkflowJobTemplate:
new_wfjt = wfjt.user_copy(admin_user)
for fd in ['description', 'survey_spec', 'survey_enabled', 'extra_vars']:
assert getattr(wfjt, fd) == getattr(new_wfjt, fd)
assert new_wfjt.organization == wfjt.organization
assert len(new_wfjt.workflow_job_template_nodes.all()) == 3
nodes = new_wfjt.workflow_job_template_nodes.all()
assert nodes[0].success_nodes.all()[0] == nodes[1]