|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# Copyright 2026 Atlan Pte. Ltd. |
| 3 | + |
| 4 | +""" |
| 5 | +Unit tests for ALLOYDB_POSTGRES connector type support (REQ-589). |
| 6 | + |
| 7 | +Verifies that AtlanConnectorType.ALLOYDB_POSTGRES and WorkflowPackage.ALLOYDB_POSTGRES |
| 8 | +are properly defined, enabling programmatic metadata policy creation for AlloyDB assets. |
| 9 | +""" |
| 10 | + |
| 11 | +import pytest |
| 12 | + |
| 13 | +from pyatlan.model.assets import Persona |
| 14 | +from pyatlan.model.enums import ( |
| 15 | + AtlanConnectionCategory, |
| 16 | + AtlanConnectorType, |
| 17 | + AuthPolicyType, |
| 18 | + PersonaMetadataAction, |
| 19 | + WorkflowPackage, |
| 20 | +) |
| 21 | + |
| 22 | +ALLOYDB_POSTGRES_CONNECTION_QN = "default/alloydb-postgres/1686532494" |
| 23 | +PERSONA_GUID = "test-persona-guid-1234" |
| 24 | + |
| 25 | + |
| 26 | +class TestAtlanConnectorTypeAlloydbPostgres: |
| 27 | + def test_enum_member_exists(self): |
| 28 | + assert hasattr(AtlanConnectorType, "ALLOYDB_POSTGRES") |
| 29 | + |
| 30 | + def test_enum_value(self): |
| 31 | + assert AtlanConnectorType.ALLOYDB_POSTGRES.value == "alloydb-postgres" |
| 32 | + |
| 33 | + def test_enum_category(self): |
| 34 | + assert ( |
| 35 | + AtlanConnectorType.ALLOYDB_POSTGRES.category |
| 36 | + == AtlanConnectionCategory.DATABASE |
| 37 | + ) |
| 38 | + |
| 39 | + def test_lookup_by_value(self): |
| 40 | + connector = AtlanConnectorType("alloydb-postgres") |
| 41 | + assert connector == AtlanConnectorType.ALLOYDB_POSTGRES |
| 42 | + |
| 43 | + def test_resolve_from_qualified_name(self): |
| 44 | + connector = AtlanConnectorType._get_connector_type_from_qualified_name( |
| 45 | + ALLOYDB_POSTGRES_CONNECTION_QN |
| 46 | + ) |
| 47 | + assert connector == AtlanConnectorType.ALLOYDB_POSTGRES |
| 48 | + assert connector.value == "alloydb-postgres" |
| 49 | + |
| 50 | + def test_to_qualified_name_format(self): |
| 51 | + qn = AtlanConnectorType.ALLOYDB_POSTGRES.to_qualified_name() |
| 52 | + parts = qn.split("/") |
| 53 | + assert parts[0] == "default" |
| 54 | + assert parts[1] == "alloydb-postgres" |
| 55 | + |
| 56 | + |
| 57 | +class TestWorkflowPackageAlloydbPostgres: |
| 58 | + def test_enum_member_exists(self): |
| 59 | + assert hasattr(WorkflowPackage, "ALLOYDB_POSTGRES") |
| 60 | + |
| 61 | + def test_enum_value(self): |
| 62 | + assert WorkflowPackage.ALLOYDB_POSTGRES.value == "atlan-alloydb-postgres" |
| 63 | + |
| 64 | + def test_lookup_by_value(self): |
| 65 | + pkg = WorkflowPackage("atlan-alloydb-postgres") |
| 66 | + assert pkg == WorkflowPackage.ALLOYDB_POSTGRES |
| 67 | + |
| 68 | + |
| 69 | +class TestPersonaMetadataPolicyAlloydbPostgres: |
| 70 | + """ |
| 71 | + Reproduces the CME use case: programmatically creating metadata policies |
| 72 | + for AlloyDB Postgres connections (REQ-589). |
| 73 | + """ |
| 74 | + |
| 75 | + def test_create_metadata_policy_for_alloydb_postgres(self): |
| 76 | + policy = Persona.create_metadata_policy( |
| 77 | + name="AlloyDB read access", |
| 78 | + persona_id=PERSONA_GUID, |
| 79 | + policy_type=AuthPolicyType.ALLOW, |
| 80 | + actions={PersonaMetadataAction.READ}, |
| 81 | + connection_qualified_name=ALLOYDB_POSTGRES_CONNECTION_QN, |
| 82 | + resources={f"entity:{ALLOYDB_POSTGRES_CONNECTION_QN}"}, |
| 83 | + ) |
| 84 | + |
| 85 | + assert policy is not None |
| 86 | + assert policy.policy_sub_category == "metadata" |
| 87 | + assert policy.connection_qualified_name == ALLOYDB_POSTGRES_CONNECTION_QN |
| 88 | + assert f"entity:{ALLOYDB_POSTGRES_CONNECTION_QN}" in policy.policy_resources |
| 89 | + assert PersonaMetadataAction.READ.value in policy.policy_actions |
| 90 | + assert policy.policy_type == AuthPolicyType.ALLOW |
| 91 | + |
| 92 | + def test_create_metadata_policy_with_table_resource(self): |
| 93 | + table_resource = ( |
| 94 | + f"entity:{ALLOYDB_POSTGRES_CONNECTION_QN}/mydb/myschema/mytable" |
| 95 | + ) |
| 96 | + policy = Persona.create_metadata_policy( |
| 97 | + name="AlloyDB table access", |
| 98 | + persona_id=PERSONA_GUID, |
| 99 | + policy_type=AuthPolicyType.ALLOW, |
| 100 | + actions={PersonaMetadataAction.READ, PersonaMetadataAction.UPDATE}, |
| 101 | + connection_qualified_name=ALLOYDB_POSTGRES_CONNECTION_QN, |
| 102 | + resources={table_resource}, |
| 103 | + ) |
| 104 | + |
| 105 | + assert policy is not None |
| 106 | + assert table_resource in policy.policy_resources |
| 107 | + assert len(policy.policy_actions) == 2 |
0 commit comments