|
5 | 5 | import pytest
|
6 | 6 |
|
7 | 7 | from pyatlan.errors import InvalidRequestError
|
| 8 | +from pyatlan.model.enums import AtlanConnectionCategory, AtlanConnectorType |
8 | 9 | from pyatlan.model.utils import construct_object_key
|
9 | 10 | from pyatlan.utils import (
|
10 | 11 | ComparisonCategory,
|
@@ -292,3 +293,120 @@ def test_validate_type_with_valid_values(name, the_type, value):
|
292 | 293 | def test_contruct_object_key(prefix, name, expected_key):
|
293 | 294 | key = construct_object_key(prefix, name)
|
294 | 295 | assert key == expected_key
|
| 296 | + |
| 297 | + |
| 298 | +@pytest.mark.parametrize( |
| 299 | + "custom_connectors", |
| 300 | + [ |
| 301 | + [ |
| 302 | + AtlanConnectorType.CREATE_CUSTOM( |
| 303 | + name="FOO", value="foo", category=AtlanConnectionCategory.BI |
| 304 | + ), |
| 305 | + AtlanConnectorType.CREATE_CUSTOM( |
| 306 | + name="BAR", value="bar", category=AtlanConnectionCategory.API |
| 307 | + ), |
| 308 | + AtlanConnectorType.CREATE_CUSTOM( |
| 309 | + name="BAZ", value="baz", category=AtlanConnectionCategory.WAREHOUSE |
| 310 | + ), |
| 311 | + ] |
| 312 | + ], |
| 313 | +) |
| 314 | +def test_atlan_connector_type_create_custom(custom_connectors): |
| 315 | + for custom_connector in custom_connectors: |
| 316 | + assert custom_connector and custom_connector.category |
| 317 | + assert custom_connector.value in AtlanConnectorType.get_values() |
| 318 | + assert custom_connector.strip() in AtlanConnectorType.get_values() |
| 319 | + assert custom_connector.name in AtlanConnectorType.get_names() |
| 320 | + assert ( |
| 321 | + custom_connector.name, |
| 322 | + custom_connector.value, |
| 323 | + ) in AtlanConnectorType.get_items() |
| 324 | + |
| 325 | + |
| 326 | +@pytest.mark.parametrize( |
| 327 | + "custom_asset_qns", |
| 328 | + [ |
| 329 | + [ |
| 330 | + "default/c1/1234567890/asset/name", |
| 331 | + "default/c2/1234567890/asset/name", |
| 332 | + "default/c3/1234567890/asset/name", |
| 333 | + # Duplicate custom connector names |
| 334 | + "default/c1/1234567890/asset/name", |
| 335 | + "default/c2/1234567890/asset/name", |
| 336 | + "default/c3/1234567890/asset/name", |
| 337 | + # Duplicate custom connector names |
| 338 | + "default/c1/1234567890/asset/name", |
| 339 | + "default/c2/1234567890/asset/name", |
| 340 | + "default/c3/1234567890/asset/name", |
| 341 | + ] |
| 342 | + ], |
| 343 | +) |
| 344 | +def test_atlan_connector_type_custom_asset_qn(custom_asset_qns): |
| 345 | + # Calculate the unique custom QNs |
| 346 | + unique_custom_qns = set(custom_asset_qns) |
| 347 | + |
| 348 | + # Calculate the initial lengths of predefined values, names, and items |
| 349 | + len_get_values = len(AtlanConnectorType.get_values()) |
| 350 | + len_get_names = len(AtlanConnectorType.get_names()) |
| 351 | + len_get_items = len(AtlanConnectorType.get_items()) |
| 352 | + |
| 353 | + # Check each custom QN |
| 354 | + for custom_qn in custom_asset_qns: |
| 355 | + custom_connector = AtlanConnectorType._get_connector_type_from_qualified_name( |
| 356 | + custom_qn |
| 357 | + ) |
| 358 | + custom_connector.category = AtlanConnectionCategory.CUSTOM |
| 359 | + assert custom_connector.value in AtlanConnectorType.get_values() |
| 360 | + assert custom_connector.strip() in AtlanConnectorType.get_values() |
| 361 | + assert ( |
| 362 | + custom_connector.name, |
| 363 | + custom_connector.value, |
| 364 | + ) in AtlanConnectorType.get_items() |
| 365 | + |
| 366 | + # Ensure the value is only added once (i.e no duplicates) |
| 367 | + assert len(AtlanConnectorType.get_values()) == len_get_values + len( |
| 368 | + unique_custom_qns |
| 369 | + ) |
| 370 | + assert len(AtlanConnectorType.get_names()) == len_get_names + len(unique_custom_qns) |
| 371 | + assert len(AtlanConnectorType.get_items()) == len_get_items + len(unique_custom_qns) |
| 372 | + |
| 373 | + |
| 374 | +@pytest.mark.parametrize( |
| 375 | + "custom_connection_qns", |
| 376 | + [ |
| 377 | + [ |
| 378 | + "default/cm1/1234567890", |
| 379 | + "default/cm2/1234567890", |
| 380 | + "default/cm3/1234567890", |
| 381 | + # Duplicate custom connector names |
| 382 | + "default/cm1/1234567890", |
| 383 | + "default/cm2/1234567890", |
| 384 | + "default/cm3/1234567890", |
| 385 | + # Duplicate custom connector names |
| 386 | + "default/cm1/1234567890", |
| 387 | + "default/cm2/1234567890", |
| 388 | + "default/cm3/1234567890", |
| 389 | + ] |
| 390 | + ], |
| 391 | +) |
| 392 | +def test_atlan_connector_type_custom_connection_qn(custom_connection_qns): |
| 393 | + # Calculate the unique custom QNs |
| 394 | + unique_custom_qns = set(custom_connection_qns) |
| 395 | + |
| 396 | + # Calculate the initial lengths of predefined values, names, and items |
| 397 | + len_get_values = len(AtlanConnectorType.get_values()) |
| 398 | + len_get_names = len(AtlanConnectorType.get_names()) |
| 399 | + len_get_items = len(AtlanConnectorType.get_items()) |
| 400 | + |
| 401 | + # Check each custom QN |
| 402 | + for custom_qn in custom_connection_qns: |
| 403 | + custom_connector_name = AtlanConnectorType.get_connector_name(custom_qn) |
| 404 | + assert custom_connector_name in AtlanConnectorType.get_values() |
| 405 | + assert custom_connector_name.strip() in AtlanConnectorType.get_values() |
| 406 | + |
| 407 | + # Ensure the value is only added once (i.e no duplicates) |
| 408 | + assert len(AtlanConnectorType.get_values()) == len_get_values + len( |
| 409 | + unique_custom_qns |
| 410 | + ) |
| 411 | + assert len(AtlanConnectorType.get_names()) == len_get_names + len(unique_custom_qns) |
| 412 | + assert len(AtlanConnectorType.get_items()) == len_get_items + len(unique_custom_qns) |
0 commit comments