|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# Copyright 2024 Atlan Pte. Ltd. |
| 3 | +from typing import Generator |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from pyatlan.client.atlan import AtlanClient |
| 8 | +from pyatlan.model.assets import AIApplication, AIModel |
| 9 | +from pyatlan.model.enums import AIApplicationDevelopmentStage, AIModelStatus |
| 10 | +from tests.integration.client import TestId, delete_asset |
| 11 | + |
| 12 | +MODULE_NAME = TestId.make_unique("AI") |
| 13 | + |
| 14 | +AI_MODEL_NAME = f"test_ai_model_{MODULE_NAME}" |
| 15 | +AI_APPLICATION_NAME = f"test_ai_application_{MODULE_NAME}" |
| 16 | +AI_APPLICATION_VERSION = "2.0" |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(scope="module") |
| 20 | +def ai_model(client: AtlanClient) -> Generator[AIModel, None, None]: |
| 21 | + to_create = AIModel.creator( |
| 22 | + name=AI_MODEL_NAME, |
| 23 | + ai_model_status=AIModelStatus.ACTIVE, |
| 24 | + ) |
| 25 | + response = client.asset.save(to_create) |
| 26 | + result = response.assets_created(asset_type=AIModel)[0] |
| 27 | + yield result |
| 28 | + delete_asset(client, guid=result.guid, asset_type=AIModel) |
| 29 | + |
| 30 | + |
| 31 | +def test_ai_model( |
| 32 | + ai_model: AIModel, |
| 33 | +): |
| 34 | + assert ai_model |
| 35 | + assert ai_model.guid |
| 36 | + assert ai_model.qualified_name |
| 37 | + assert ai_model.name == AI_MODEL_NAME |
| 38 | + assert ai_model.connector_name == "ai" |
| 39 | + assert ai_model.ai_model_status == AIModelStatus.ACTIVE |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture(scope="module") |
| 43 | +def ai_application(client: AtlanClient) -> Generator[AIApplication, None, None]: |
| 44 | + to_create = AIApplication.creator( |
| 45 | + name=AI_APPLICATION_NAME, |
| 46 | + ai_application_version=AI_APPLICATION_VERSION, |
| 47 | + ai_application_development_stage=AIApplicationDevelopmentStage.PRODUCTION, |
| 48 | + ) |
| 49 | + response = client.asset.save(to_create) |
| 50 | + result = response.assets_created(asset_type=AIApplication)[0] |
| 51 | + yield result |
| 52 | + delete_asset(client, guid=result.guid, asset_type=AIApplication) |
| 53 | + |
| 54 | + |
| 55 | +def test_ai_application( |
| 56 | + ai_application: AIApplication, |
| 57 | +): |
| 58 | + assert ai_application |
| 59 | + assert ai_application.guid |
| 60 | + assert ai_application.qualified_name |
| 61 | + assert ai_application.name == AI_APPLICATION_NAME |
| 62 | + assert ai_application.connector_name == "ai" |
| 63 | + assert ai_application.ai_application_version == AI_APPLICATION_VERSION |
| 64 | + assert ( |
| 65 | + ai_application.ai_application_development_stage |
| 66 | + == AIApplicationDevelopmentStage.PRODUCTION |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +def _update_ai_application(client, ai_application: AIApplication): |
| 71 | + updated = AIApplication.updater( |
| 72 | + qualified_name=ai_application.qualified_name, name=ai_application.name |
| 73 | + ) |
| 74 | + updated.ai_application_development_stage = AIApplicationDevelopmentStage.DEVELOPMENT |
| 75 | + updated_response = client.asset.save(updated) |
| 76 | + assert updated_response |
| 77 | + assert updated_response.mutated_entities.UPDATE[0] |
| 78 | + updated_response = updated_response.mutated_entities.UPDATE[0] |
| 79 | + assert updated_response.qualified_name |
| 80 | + assert updated_response.name == AI_APPLICATION_NAME |
| 81 | + assert updated_response.connector_name == "ai" |
| 82 | + assert updated_response.ai_application_version == AI_APPLICATION_VERSION |
| 83 | + assert ( |
| 84 | + updated_response.ai_application_development_stage |
| 85 | + == AIApplicationDevelopmentStage.DEVELOPMENT |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +def _update_ai_model(client, ai_model: AIModel): |
| 90 | + updated = AIModel.updater( |
| 91 | + qualified_name=ai_model.qualified_name, name=ai_model.name |
| 92 | + ) |
| 93 | + updated.ai_model_version = "2.1" |
| 94 | + updated_response = client.asset.save(updated) |
| 95 | + assert updated_response |
| 96 | + assert updated_response.mutated_entities.UPDATE[0] |
| 97 | + updated_response = updated_response.mutated_entities.UPDATE[0] |
| 98 | + assert updated_response.qualified_name |
| 99 | + assert updated_response.name == AI_MODEL_NAME |
| 100 | + assert updated_response.connector_name == "ai" |
| 101 | + assert updated_response.ai_model_version == "2.1" |
| 102 | + |
| 103 | + |
| 104 | +def test_update_ai_assets( |
| 105 | + client: AtlanClient, |
| 106 | + ai_model: AIModel, |
| 107 | + ai_application: AIApplication, |
| 108 | +): |
| 109 | + _update_ai_application(client, ai_application) |
| 110 | + _update_ai_model(client, ai_model) |
0 commit comments