Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
Updated data_mesh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Jun 10, 2024
1 parent ffa6b70 commit 400780b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
22 changes: 16 additions & 6 deletions tests/integration/data_mesh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import pytest

from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import Asset, DataContract, DataDomain, DataProduct, Table
from pyatlan.model.assets import (
Asset,
Connection,
DataContract,
DataDomain,
DataProduct,
Table,
)
from pyatlan.model.core import Announcement
from pyatlan.model.enums import (
AnnouncementType,
Expand Down Expand Up @@ -280,18 +287,18 @@ def test_product(client: AtlanClient, product: DataProduct):
def contract(
client: AtlanClient,
table: Table,
connection: Connection,
) -> Generator[DataContract, None, None]:
assert table and table.guid
contract_json = {
"type": table.type_name,
"status": CertificateStatus.DRAFT,
"kind": "DataContract",
"data_source": table.connection_qualified_name,
"data_source": connection.name,
"dataset": table.name,
"description": "Automated testing of the Python SDK.",
}
contract = DataContract.creator(
name=DATA_CONTRACT_NAME,
asset_qualified_name=table.qualified_name,
contract_json=dumps(contract_json),
)
Expand All @@ -305,18 +312,18 @@ def contract(
def updated_contract(
client: AtlanClient,
table: Table,
connection: Connection,
) -> Generator[DataContract, None, None]:
assert table and table.guid
contract_json = {
"type": table.type_name,
"status": CertificateStatus.DRAFT,
"kind": "DataContract",
"data_source": table.connection_qualified_name,
"data_source": connection.name,
"dataset": table.name,
"description": "Automated testing of the Python SDK (UPDATED).",
}
contract = DataContract.creator(
name=DATA_CONTRACT_NAME,
asset_qualified_name=table.qualified_name,
contract_json=dumps(contract_json),
)
Expand All @@ -340,6 +347,7 @@ def test_contract(
assert table.data_contract_latest
table_data_contract = table.data_contract_latest
assert contract and table_data_contract
assert table.name and contract.name and table.name in contract.name
assert contract.guid == table_data_contract.guid
assert contract.data_contract_json
assert contract.data_contract_version == 1
Expand All @@ -354,7 +362,8 @@ def test_update_contract(
assert table.has_contract
assert table.data_contract_latest
table_data_contract = table.data_contract_latest
assert updated_contract and table_data_contract
assert table.name and updated_contract and table_data_contract
assert updated_contract.name and table.name in updated_contract.name
assert updated_contract.guid == table_data_contract.guid
assert updated_contract.data_contract_asset_guid == table.guid
assert updated_contract.data_contract_json
Expand Down Expand Up @@ -414,6 +423,7 @@ def test_retrieve_contract(
)
assert test_contract
assert test_contract.name == updated_contract.name
assert table.name and updated_contract.name and table.name in updated_contract.name
assert test_contract.guid == updated_contract.guid
assert test_contract.qualified_name == updated_contract.qualified_name
assert test_contract.data_contract_asset_guid == table.guid
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/model/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"type": "Table",
"status": "DRAFT",
"kind": "DataContract",
"data_source": ASSET_QUALIFIED_NAME,
"data_source": "some-asset-connection-name",
"dataset": "some-asset-name",
}
DATA_CONTRACT_NAME = f"Data contract for {DATA_CONTRACT_JSON['dataset']}"
Expand Down
45 changes: 34 additions & 11 deletions tests/unit/model/data_contract_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from json import dumps
from typing import Union

import pytest

from pyatlan.errors import InvalidRequestError
from pyatlan.model.assets import DataContract
from tests.unit.model.constants import (
ASSET_QUALIFIED_NAME,
Expand All @@ -17,42 +19,63 @@ def _assert_contract(
assert contract.name == DATA_CONTRACT_NAME
assert contract.qualified_name == DATA_CONTRACT_QUALIFIED_NAME
if assert_json:
assert contract.data_contract_json == str(DATA_CONTRACT_JSON)
assert contract.data_contract_json == dumps(DATA_CONTRACT_JSON)


@pytest.mark.parametrize(
"name, asset_qualified_name, contract_json, message",
"asset_qualified_name, contract_json, message",
[
(None, "qn", "json", "name is required"),
("name", None, "json", "asset_qualified_name is required"),
("name", "qn", None, "contract_json is required"),
(None, "json", "asset_qualified_name is required"),
("qn", None, "contract_json is required"),
],
)
def test_creator_with_missing_parameters_raise_value_error(
name: str, asset_qualified_name: str, contract_json: str, message: str
asset_qualified_name: str, contract_json: str, message: str
):
with pytest.raises(ValueError, match=message):
DataContract.creator(
name=name,
asset_qualified_name=asset_qualified_name,
contract_json=contract_json,
)


@pytest.mark.parametrize(
"asset_qualified_name, contract_json, error_msg",
[
(
"asset-qn",
"some-invalid-json",
"ATLAN-PYTHON-400-062 Provided data contract JSON is invalid.",
),
(
"asset-qn",
'{"kind":"DataContract", "description":"Missing dataset property"}',
"ATLAN-PYTHON-400-062 Provided data contract JSON is invalid.",
),
],
)
def test_creator_with_invalid_contract_json_raises_error(
asset_qualified_name: str, contract_json: str, error_msg: str
):
with pytest.raises(InvalidRequestError, match=error_msg):
DataContract.creator(
asset_qualified_name=asset_qualified_name,
contract_json=contract_json,
)


def test_creator_atttributes_with_required_parameters():
attributes = DataContract.Attributes.creator(
name=DATA_CONTRACT_NAME,
asset_qualified_name=ASSET_QUALIFIED_NAME,
contract_json=str(DATA_CONTRACT_JSON),
contract_json=dumps(DATA_CONTRACT_JSON),
)
_assert_contract(attributes)


def test_creator_with_required_parameters():
test_contract = DataContract.creator(
name=DATA_CONTRACT_NAME,
asset_qualified_name=ASSET_QUALIFIED_NAME,
contract_json=str(DATA_CONTRACT_JSON),
contract_json=dumps(DATA_CONTRACT_JSON),
)
_assert_contract(test_contract)

Expand Down

0 comments on commit 400780b

Please sign in to comment.