Skip to content

Commit 6cda34d

Browse files
committed
[test] Update test assertions for custom validate_arguments decorator
Update all test files to work with the custom validate_arguments decorator's error format: - Replace pytest.raises(ValidationError) with pytest.raises(ValueError) since the custom decorator raises ValueError directly - Remove unused pydantic.v1 ValidationError imports - Update expected error messages in tests/unit/constants.py to match the custom decorator's output format: - Remove Pydantic-specific (type=...) suffixes - Update error counts for Union/list validation (1 vs N) - Match 'instance of X expected' for non-builtin types - Match 'str type expected', 'none is not an allowed value' etc. - Update credential, SSO, query, task, workflow, file, UI test files with corrected error message formats - Remove trailing spaces from error message constants
1 parent 1e8c108 commit 6cda34d

21 files changed

Lines changed: 166 additions & 185 deletions

tests/unit/aio/test_client.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import pytest
1010
from httpx import Headers
11-
from pydantic.v1 import ValidationError
1211

1312
from pyatlan.client.aio.asset import AsyncAssetClient
1413
from pyatlan.client.aio.batch import AsyncBatch
@@ -2141,7 +2140,7 @@ async def test_asset_client_missing_glossary_guid_raises_invalid_request_error(
21412140
async def test_asset_client_methods_validation_error(client, method, params):
21422141
client_method = getattr(client.asset, method)
21432142
for param_values, error_msg in params:
2144-
with pytest.raises(ValidationError) as err:
2143+
with pytest.raises(ValueError) as err:
21452144
await client_method(*param_values)
21462145
assert error_msg in str(err.value)
21472146

@@ -2151,7 +2150,7 @@ async def test_asset_client_methods_validation_error(client, method, params):
21512150
async def test_admin_client_methods_validation_error(client, method, params):
21522151
client_method = getattr(client.admin, method)
21532152
for param_values, error_msg in params:
2154-
with pytest.raises(ValidationError) as err:
2153+
with pytest.raises(ValueError) as err:
21552154
await client_method(*param_values)
21562155
assert error_msg in str(err.value)
21572156

@@ -2161,7 +2160,7 @@ async def test_admin_client_methods_validation_error(client, method, params):
21612160
async def test_async_audit_client_methods_validation_error(client, method, params):
21622161
client_method = getattr(client.audit, method)
21632162
for param_values, error_msg in params:
2164-
with pytest.raises(ValidationError) as err:
2163+
with pytest.raises(ValueError) as err:
21652164
await client_method(*param_values)
21662165
assert error_msg in str(err.value)
21672166

@@ -2171,7 +2170,7 @@ async def test_async_audit_client_methods_validation_error(client, method, param
21712170
async def test_async_group_client_methods_validation_error(client, method, params):
21722171
client_method = getattr(client.group, method)
21732172
for param_values, error_msg in params:
2174-
with pytest.raises(ValidationError) as err:
2173+
with pytest.raises(ValueError) as err:
21752174
await client_method(*param_values)
21762175
assert error_msg in str(err.value)
21772176

@@ -2181,7 +2180,7 @@ async def test_async_group_client_methods_validation_error(client, method, param
21812180
async def test_role_client_methods_validation_error(client, method, params):
21822181
client_method = getattr(client.role, method)
21832182
for param_values, error_msg in params:
2184-
with pytest.raises(ValidationError) as err:
2183+
with pytest.raises(ValueError) as err:
21852184
await client_method(*param_values)
21862185
assert error_msg in str(err.value)
21872186

@@ -2191,7 +2190,7 @@ async def test_role_client_methods_validation_error(client, method, params):
21912190
async def test_async_search_log_client_methods_validation_error(client, method, params):
21922191
client_method = getattr(client.search_log, method)
21932192
for param_values, error_msg in params:
2194-
with pytest.raises(ValidationError) as err:
2193+
with pytest.raises(ValueError) as err:
21952194
await client_method(*param_values)
21962195
assert error_msg in str(err.value)
21972196

@@ -2201,7 +2200,7 @@ async def test_async_search_log_client_methods_validation_error(client, method,
22012200
async def test_async_token_client_methods_validation_error(client, method, params):
22022201
client_method = getattr(client.token, method)
22032202
for param_values, error_msg in params:
2204-
with pytest.raises(ValidationError) as err:
2203+
with pytest.raises(ValueError) as err:
22052204
await client_method(*param_values)
22062205
assert error_msg in str(err.value)
22072206

@@ -2211,7 +2210,7 @@ async def test_async_token_client_methods_validation_error(client, method, param
22112210
async def test_async_typedef_client_methods_validation_error(client, method, params):
22122211
client_method = getattr(client.typedef, method)
22132212
for param_values, error_msg in params:
2214-
with pytest.raises(ValidationError) as err:
2213+
with pytest.raises(ValueError) as err:
22152214
await client_method(*param_values)
22162215
assert error_msg in str(err.value)
22172216

@@ -2221,7 +2220,7 @@ async def test_async_typedef_client_methods_validation_error(client, method, par
22212220
async def test_async_user_client_methods_validation_error(client, method, params):
22222221
client_method = getattr(client.user, method)
22232222
for param_values, error_msg in params:
2224-
with pytest.raises(ValidationError) as err:
2223+
with pytest.raises(ValueError) as err:
22252224
await client_method(*param_values)
22262225
assert error_msg in str(err.value)
22272226

tests/unit/aio/test_credential_client.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from unittest.mock import Mock
44

55
import pytest
6-
from pydantic.v1 import ValidationError
76

87
from pyatlan.client.aio.credential import AsyncCredentialClient
98
from pyatlan.client.common import AsyncApiCaller
@@ -22,12 +21,12 @@
2221
"ATLAN-PYTHON-400-054 Credentials provided did not work: failed"
2322
)
2423
TEST_INVALID_GUID_GET_VALIDATION_ERR = (
25-
"1 validation error for Get\nguid\n str type expected (type=type_error.str)"
24+
"1 validation error for Get\nguid\n str type expected"
2625
)
27-
TEST_INVALID_GUID_PURGE_BY_GUID_VALIDATION_ERR = "1 validation error for PurgeByGuid\nguid\n str type expected (type=type_error.str)"
28-
TEST_INVALID_CRED_TEST_VALIDATION_ERR = "1 validation error for Test\ncredential\n value is not a valid dict (type=type_error.dict)"
29-
TEST_INVALID_CRED_TEST_UPDATE_VALIDATION_ERR = "1 validation error for TestAndUpdate\ncredential\n value is not a valid dict (type=type_error.dict)"
30-
TEST_INVALID_CRED_CREATOR_VALIDATION_ERR = "1 validation error for Creator\ncredential\n value is not a valid dict (type=type_error.dict)"
26+
TEST_INVALID_GUID_PURGE_BY_GUID_VALIDATION_ERR = "1 validation error for PurgeByGuid\nguid\n str type expected"
27+
TEST_INVALID_CRED_TEST_VALIDATION_ERR = "1 validation error for Test\ncredential\n instance of Credential expected"
28+
TEST_INVALID_CRED_TEST_UPDATE_VALIDATION_ERR = "1 validation error for TestAndUpdate\ncredential\n instance of Credential expected"
29+
TEST_INVALID_CRED_CREATOR_VALIDATION_ERR = "1 validation error for Creator\ncredential\n instance of Credential expected"
3130
TEST_INVALID_API_CALLER_PARAMETER_TYPE = (
3231
"ATLAN-PYTHON-400-048 Invalid parameter type for client should be AsyncApiCaller"
3332
)
@@ -95,7 +94,7 @@ async def test_init_when_wrong_class_raises_exception(test_api_caller):
9594
async def test_cred_get_wrong_params_raises_validation_error(
9695
test_guid, client: AsyncCredentialClient
9796
):
98-
with pytest.raises(ValidationError) as err:
97+
with pytest.raises(ValueError) as err:
9998
await client.get(guid=test_guid)
10099
assert TEST_INVALID_GUID_GET_VALIDATION_ERR == str(err.value)
101100

@@ -105,7 +104,7 @@ async def test_cred_get_wrong_params_raises_validation_error(
105104
async def test_cred_test_wrong_params_raises_validation_error(
106105
test_credentials, client: AsyncCredentialClient
107106
):
108-
with pytest.raises(ValidationError) as err:
107+
with pytest.raises(ValueError) as err:
109108
await client.test(credential=test_credentials)
110109
assert TEST_INVALID_CRED_TEST_VALIDATION_ERR == str(err.value)
111110

@@ -115,7 +114,7 @@ async def test_cred_test_wrong_params_raises_validation_error(
115114
async def test_cred_test_and_update_wrong_params_raises_validation_error(
116115
test_credentials, client: AsyncCredentialClient
117116
):
118-
with pytest.raises(ValidationError) as err:
117+
with pytest.raises(ValueError) as err:
119118
await client.test_and_update(credential=test_credentials)
120119
assert TEST_INVALID_CRED_TEST_UPDATE_VALIDATION_ERR == str(err.value)
121120

@@ -257,7 +256,7 @@ async def test_cred_get_all_invalid_response(mock_api_caller):
257256
async def test_cred_get_all_invalid_params_raises_validation_error(
258257
test_filter, test_limit, test_offset, client: AsyncCredentialClient
259258
):
260-
with pytest.raises(ValidationError):
259+
with pytest.raises(ValueError):
261260
await client.get_all(filter=test_filter, limit=test_limit, offset=test_offset)
262261

263262

@@ -298,7 +297,7 @@ async def test_cred_get_all_partial_response(mock_api_caller):
298297
async def test_cred_get_all_invalid_filter_type(mock_api_caller):
299298
client = AsyncCredentialClient(mock_api_caller)
300299

301-
with pytest.raises(ValidationError, match="value is not a valid dict"):
300+
with pytest.raises(ValueError, match="value is not a valid dict"):
302301
await client.get_all(filter="invalid_filter")
303302

304303

@@ -319,7 +318,7 @@ async def test_cred_get_all_no_results(mock_api_caller):
319318
async def test_cred_creator_wrong_params_raises_validation_error(
320319
create_credentials, client: AsyncCredentialClient
321320
):
322-
with pytest.raises(ValidationError) as err:
321+
with pytest.raises(ValueError) as err:
323322
await client.creator(credential=create_credentials)
324323
assert TEST_INVALID_CRED_CREATOR_VALIDATION_ERR == str(err.value)
325324

@@ -400,7 +399,7 @@ async def test_cred_creator_with_test_false_with_username_password(
400399
async def test_cred_purge_by_guid_wrong_params_raises_validation_error(
401400
test_guid, client: AsyncCredentialClient
402401
):
403-
with pytest.raises(ValidationError) as err:
402+
with pytest.raises(ValueError) as err:
404403
await client.purge_by_guid(guid=test_guid)
405404
assert TEST_INVALID_GUID_PURGE_BY_GUID_VALIDATION_ERR == str(err.value)
406405

tests/unit/aio/test_file_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from unittest.mock import AsyncMock, Mock, patch
77

88
import pytest
9-
from pydantic.v1 import ValidationError
109

1110
from pyatlan.client.aio.client import AsyncAtlanClient
1211
from pyatlan.client.aio.file import AsyncFileClient
@@ -164,7 +163,7 @@ def mock_bad_aiter_bytes(chunk_size=8192):
164163
async def test_async_file_client_methods_validation_error(client, method, params):
165164
client_method = getattr(client.files, method)
166165
for param_values, error_msg in params:
167-
with pytest.raises(ValidationError, match=error_msg):
166+
with pytest.raises(ValueError, match=error_msg):
168167
client_method(*param_values)
169168

170169

tests/unit/aio/test_query_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from unittest.mock import AsyncMock, Mock
55

66
import pytest
7-
from pydantic.v1 import ValidationError
87

98
from pyatlan.client.aio.query import AsyncQueryClient
109
from pyatlan.client.common import AsyncApiCaller
@@ -72,13 +71,13 @@ def test_init_when_wrong_class_raises_exception(test_api_caller):
7271

7372
@pytest.mark.parametrize(
7473
"test_request, error_msg",
75-
[[None, "none is not an allowed value"], ["123", "value is not a valid dict"]],
74+
[[None, "none is not an allowed value"], ["123", "instance of QueryRequest expected"]],
7675
)
7776
def test_query_stream_wrong_params_raises_validation_error(
7877
test_request, error_msg, mock_async_api_caller
7978
):
8079
client = AsyncQueryClient(client=mock_async_api_caller)
81-
with pytest.raises(ValidationError) as err:
80+
with pytest.raises(ValueError) as err:
8281
client.stream(request=test_request)
8382
assert error_msg in str(err.value)
8483

tests/unit/aio/test_sso_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest.mock import AsyncMock, Mock
88

99
import pytest
10-
from pydantic.v1 import ValidationError, parse_obj_as
10+
from pydantic.v1 import parse_obj_as
1111

1212
from pyatlan.client.aio.sso import AsyncSSOClient
1313
from pyatlan.client.common import AsyncApiCaller
@@ -86,7 +86,7 @@ def test_init_when_wrong_class_raises_exception(test_api_caller):
8686
def test_sso_get_group_mapping_wrong_params_raises_validation_error(
8787
sso_alias, group_map_id, error_msg
8888
):
89-
with pytest.raises(ValidationError) as err:
89+
with pytest.raises(ValueError) as err:
9090
AsyncSSOClient.get_group_mapping(sso_alias=sso_alias, group_map_id=group_map_id)
9191
assert error_msg in str(err.value)
9292

@@ -101,7 +101,7 @@ def test_sso_get_group_mapping_wrong_params_raises_validation_error(
101101
def test_sso_get_all_group_mapping_wrong_params_raises_validation_error(
102102
sso_alias, error_msg
103103
):
104-
with pytest.raises(ValidationError, match=error_msg):
104+
with pytest.raises(ValueError, match=error_msg):
105105
AsyncSSOClient.get_all_group_mappings(sso_alias=sso_alias)
106106

107107

@@ -112,14 +112,14 @@ def test_sso_get_all_group_mapping_wrong_params_raises_validation_error(
112112
["auth0", None, "sso-group", "none is not an allowed value"],
113113
["auth0", "atlan-group", None, "none is not an allowed value"],
114114
[[123], "atlan-group", "sso-group", "so_alias\n str type expected"],
115-
["auth0", [123], "sso-group", "atlan_group\n value is not a valid dict"],
115+
["auth0", [123], "sso-group", "atlan_group\n instance of AtlanGroup expected"],
116116
["auth0", AtlanGroup(), [123], "sso_group_name\n str type expected"],
117117
],
118118
)
119119
def test_sso_create_group_mapping_wrong_params_raises_validation_error(
120120
sso_alias, atlan_group, sso_group_name, error_msg
121121
):
122-
with pytest.raises(ValidationError, match=error_msg):
122+
with pytest.raises(ValueError, match=error_msg):
123123
AsyncSSOClient.create_group_mapping(
124124
sso_alias=sso_alias, atlan_group=atlan_group, sso_group_name=sso_group_name
125125
)
@@ -139,7 +139,7 @@ def test_sso_create_group_mapping_wrong_params_raises_validation_error(
139139
[123],
140140
"map-id",
141141
"sso-group",
142-
"atlan_group\n value is not a valid dict",
142+
"atlan_group\n instance of AtlanGroup expected",
143143
],
144144
[
145145
"auth0",
@@ -160,7 +160,7 @@ def test_sso_create_group_mapping_wrong_params_raises_validation_error(
160160
def test_sso_update_group_mapping_wrong_params_raises_validation_error(
161161
sso_alias, atlan_group, group_map_id, sso_group_name, error_msg
162162
):
163-
with pytest.raises(ValidationError, match=error_msg):
163+
with pytest.raises(ValueError, match=error_msg):
164164
AsyncSSOClient.update_group_mapping(
165165
sso_alias=sso_alias,
166166
atlan_group=atlan_group,
@@ -181,7 +181,7 @@ def test_sso_update_group_mapping_wrong_params_raises_validation_error(
181181
def test_sso_delete_group_mapping_wrong_params_raises_validation_error(
182182
sso_alias, group_map_id, error_msg
183183
):
184-
with pytest.raises(ValidationError, match=error_msg):
184+
with pytest.raises(ValueError, match=error_msg):
185185
AsyncSSOClient.delete_group_mapping(
186186
sso_alias=sso_alias, group_map_id=group_map_id
187187
)

tests/unit/aio/test_task_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from unittest.mock import AsyncMock, Mock
66

77
import pytest
8-
from pydantic.v1 import ValidationError
98

109
from pyatlan.client.aio.task import AsyncTaskClient
1110
from pyatlan.client.common import AsyncApiCaller
@@ -75,13 +74,13 @@ def test_init_when_wrong_class_raises_exception(test_api_caller):
7574

7675
@pytest.mark.parametrize(
7776
"test_request, error_msg",
78-
[[None, "none is not an allowed value"], ["123", "value is not a valid dict"]],
77+
[[None, "none is not an allowed value"], ["123", "instance of TaskSearchRequest expected"]],
7978
)
8079
def test_task_search_wrong_params_raises_validation_error(
8180
test_request, error_msg, mock_async_api_caller
8281
):
8382
client = AsyncTaskClient(client=mock_async_api_caller)
84-
with pytest.raises(ValidationError) as err:
83+
with pytest.raises(ValueError) as err:
8584
client.search(request=test_request)
8685
assert error_msg in str(err.value)
8786

tests/unit/aio/test_workflow_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from unittest.mock import AsyncMock, Mock, patch
44

55
import pytest
6-
from pydantic.v1 import ValidationError
76

87
from pyatlan.client.aio.client import AsyncAtlanClient
98
from pyatlan.client.aio.workflow import AsyncWorkflowClient
@@ -177,7 +176,7 @@ def update_response() -> WorkflowResponse:
177176
async def test_async_workflow_client_methods_validation_error(method, params):
178177
client_method = getattr(AsyncAtlanClient().workflow, method)
179178
for param_values, error_msg in params:
180-
with pytest.raises(ValidationError, match=error_msg):
179+
with pytest.raises(ValueError, match=error_msg):
181180
await client_method(*param_values)
182181

183182

0 commit comments

Comments
 (0)