diff --git a/tests/integration/data_mesh_test.py b/tests/integration/data_mesh_test.py index cb5753460..4b7535732 100644 --- a/tests/integration/data_mesh_test.py +++ b/tests/integration/data_mesh_test.py @@ -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, @@ -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), ) @@ -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), ) @@ -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 @@ -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 @@ -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 diff --git a/tests/unit/model/constants.py b/tests/unit/model/constants.py index 3bb6dc07d..e3feb83fb 100644 --- a/tests/unit/model/constants.py +++ b/tests/unit/model/constants.py @@ -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']}" diff --git a/tests/unit/model/data_contract_test.py b/tests/unit/model/data_contract_test.py index 5ca44fd14..048b57e3e 100644 --- a/tests/unit/model/data_contract_test.py +++ b/tests/unit/model/data_contract_test.py @@ -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, @@ -17,23 +19,46 @@ 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, ) @@ -41,18 +66,16 @@ def test_creator_with_missing_parameters_raise_value_error( 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)