|
| 1 | +# Copyright (c) ZenML GmbH 2024. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at: |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 12 | +# or implied. See the License for the specific language governing |
| 13 | +# permissions and limitations under the License. |
| 14 | +from contextlib import ExitStack as does_not_raise |
| 15 | +from datetime import datetime |
| 16 | +from uuid import uuid4 |
| 17 | + |
| 18 | +from zenml.config.pipeline_run_configuration import PipelineRunConfiguration |
| 19 | +from zenml.models import ( |
| 20 | + PipelineBuildResponse, |
| 21 | + PipelineBuildResponseBody, |
| 22 | + RunTemplateResponse, |
| 23 | + RunTemplateResponseBody, |
| 24 | + RunTemplateResponseMetadata, |
| 25 | + RunTemplateResponseResources, |
| 26 | +) |
| 27 | +from zenml.zen_server.template_execution.utils import ( |
| 28 | + deployment_request_from_template, |
| 29 | +) |
| 30 | + |
| 31 | + |
| 32 | +def test_creating_deployment_request_from_template( |
| 33 | + clean_client_with_run, mocker |
| 34 | +): |
| 35 | + mocker.patch( |
| 36 | + "zenml.zen_server.template_execution.utils.zen_store", |
| 37 | + return_value=clean_client_with_run.zen_store, |
| 38 | + ) |
| 39 | + |
| 40 | + deployments = clean_client_with_run.list_deployments(hydrate=True) |
| 41 | + assert len(deployments) == 1 |
| 42 | + |
| 43 | + deployment = deployments[0] |
| 44 | + |
| 45 | + build = PipelineBuildResponse( |
| 46 | + id=uuid4(), |
| 47 | + body=PipelineBuildResponseBody( |
| 48 | + created=datetime.utcnow(), updated=datetime.utcnow() |
| 49 | + ), |
| 50 | + ) |
| 51 | + deployment.metadata.build = build |
| 52 | + |
| 53 | + template_response = RunTemplateResponse( |
| 54 | + id=uuid4(), |
| 55 | + name="template", |
| 56 | + body=RunTemplateResponseBody( |
| 57 | + created=datetime.utcnow(), |
| 58 | + updated=datetime.utcnow(), |
| 59 | + user=deployment.user, |
| 60 | + runnable=True, |
| 61 | + ), |
| 62 | + metadata=RunTemplateResponseMetadata(workspace=deployment.workspace), |
| 63 | + resources=RunTemplateResponseResources( |
| 64 | + source_deployment=deployment, tags=[] |
| 65 | + ), |
| 66 | + ) |
| 67 | + |
| 68 | + with does_not_raise(): |
| 69 | + deployment_request_from_template( |
| 70 | + template=template_response, |
| 71 | + config=PipelineRunConfiguration(), |
| 72 | + user_id=deployment.user.id, |
| 73 | + ) |
0 commit comments