diff --git a/hexa/pipeline_templates/schema/mutations.py b/hexa/pipeline_templates/schema/mutations.py index c5e8ecf02..2cc60f905 100644 --- a/hexa/pipeline_templates/schema/mutations.py +++ b/hexa/pipeline_templates/schema/mutations.py @@ -94,7 +94,7 @@ def resolve_create_pipeline_from_template_version(_, info, **kwargs): except PipelineTemplateVersion.DoesNotExist: return {"success": False, "errors": ["PIPELINE_TEMPLATE_VERSION_NOT_FOUND"]} - pipeline_code = template_version.template.source_pipeline.code + pipeline_code = f"{template_version.template.source_pipeline.code} (from Template)" if Pipeline.objects.filter(workspace=workspace, code=pipeline_code).exists(): return {"success": False, "errors": ["PIPELINE_ALREADY_EXISTS"]} pipeline = template_version.create_pipeline(pipeline_code, workspace, request.user) diff --git a/hexa/pipeline_templates/tests/test_schema/test_templates.py b/hexa/pipeline_templates/tests/test_schema/test_templates.py index ce6434f27..0d8133a03 100644 --- a/hexa/pipeline_templates/tests/test_schema/test_templates.py +++ b/hexa/pipeline_templates/tests/test_schema/test_templates.py @@ -32,11 +32,16 @@ def setUpTestData(cls): name="WS1", description="Workspace 1", ) - cls.PIPELINE = Pipeline.objects.create(name="Test Pipeline", workspace=cls.WS1) + cls.PIPELINE = Pipeline.objects.create( + name="Test Pipeline", code="Test Pipeline", workspace=cls.WS1 + ) cls.PIPELINE_VERSION1 = PipelineVersion.objects.create( pipeline=cls.PIPELINE, version_number=1, description="Initial version", + parameters=[{"code": "param_1"}], + config=[{"param_1": 1}], + zipfile=str.encode("some_bytes"), ) cls.PIPELINE_VERSION2 = PipelineVersion.objects.create( pipeline=cls.PIPELINE, @@ -87,6 +92,7 @@ def test_create_template_version(self): def test_create_pipeline_from_template_version(self): self.client.force_login(self.USER_ROOT) + self.create_template_version(self.PIPELINE_VERSION1.id, [{"versionNumber": 1}]) r = self.run_query( """ mutation createPipelineFromTemplateVersion($input: CreatePipelineFromTemplateVersionInput!) { @@ -98,7 +104,9 @@ def test_create_pipeline_from_template_version(self): { "input": { "workspaceSlug": self.WS1.slug, - "pipelineTemplateVersionId": str(self.PIPELINE_VERSION1.id), + "pipelineTemplateVersionId": str( + self.PIPELINE_VERSION1.template_version.id + ), } }, ) @@ -108,8 +116,12 @@ def test_create_pipeline_from_template_version(self): "errors": [], "pipeline": { "name": self.PIPELINE.name, - "code": self.PIPELINE.code, - "currentVersion": {"zipfile": "a", "parameters": "", "config": ""}, + "code": "Test Pipeline (from Template)", + "currentVersion": { + "zipfile": "c29tZV9ieXRlcw==", + "parameters": [{"code": "param_1", "default": None}], + "config": [{"param_1": 1}], + }, }, }, r["data"]["createPipelineFromTemplateVersion"],