|
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | from pyatlan.model.assets import Column, Table, alpha_DQRule |
| 7 | +from pyatlan.model.dq_rule_conditions import DQRuleConditionsBuilder |
7 | 8 | from pyatlan.model.enums import ( |
8 | 9 | alpha_DQDimension, |
9 | 10 | alpha_DQRuleAlertPriority, |
10 | 11 | alpha_DQRuleStatus, |
| 12 | + alpha_dqRuleTemplateConfigRuleConditions, |
11 | 13 | alpha_DQRuleThresholdCompareOperator, |
12 | 14 | alpha_DQRuleThresholdUnit, |
13 | 15 | ) |
@@ -39,6 +41,12 @@ def mock_client(): |
39 | 41 | } |
40 | 42 | } |
41 | 43 | ) |
| 44 | + config.alpha_dq_rule_template_config_rule_conditions = json.dumps( |
| 45 | + {"enum": ["STRING_LENGTH_BETWEEN", "STRING_LENGTH_EQUAL"]} |
| 46 | + ) |
| 47 | + config.alpha_dq_rule_template_advanced_settings = json.dumps( |
| 48 | + {"alpha_dqRuleRowScopeFilteringEnabled": True} |
| 49 | + ) |
42 | 50 |
|
43 | 51 | client.dq_template_config_cache.get_template_config.return_value = { |
44 | 52 | "name": "Test Template", |
@@ -383,6 +391,140 @@ def test_column_level_rule_creator_with_optional_parameters(mock_client): |
383 | 391 | ) |
384 | 392 |
|
385 | 393 |
|
| 394 | +def test_column_level_rule_creator_with_row_scope_filtering(mock_client): |
| 395 | + asset = Table.ref_by_qualified_name(qualified_name=ALPHA_DQ_TABLE_QUALIFIED_NAME) |
| 396 | + asset.alpha_asset_d_q_row_scope_filter_column_qualified_name = ( |
| 397 | + ALPHA_DQ_COLUMN_QUALIFIED_NAME |
| 398 | + ) |
| 399 | + column = Column.ref_by_qualified_name(qualified_name=ALPHA_DQ_COLUMN_QUALIFIED_NAME) |
| 400 | + |
| 401 | + dq_rule = alpha_DQRule.column_level_rule_creator( |
| 402 | + client=mock_client, |
| 403 | + rule_type=ALPHA_DQ_RULE_TYPE_COLUMN, |
| 404 | + asset=asset, |
| 405 | + column=column, |
| 406 | + threshold_value=ALPHA_DQ_RULE_THRESHOLD_VALUE, |
| 407 | + alert_priority=alpha_DQRuleAlertPriority.NORMAL, |
| 408 | + row_scope_filtering_enabled=True, |
| 409 | + ) |
| 410 | + |
| 411 | + assert dq_rule.alpha_dq_rule_alert_priority == alpha_DQRuleAlertPriority.NORMAL |
| 412 | + assert dq_rule.alpha_dq_rule_status == alpha_DQRuleStatus.ACTIVE |
| 413 | + assert dq_rule.alpha_dq_rule_row_scope_filtering_enabled is True |
| 414 | + assert ( |
| 415 | + dq_rule.alpha_dq_rule_base_column_qualified_name |
| 416 | + == ALPHA_DQ_COLUMN_QUALIFIED_NAME |
| 417 | + ) |
| 418 | + |
| 419 | + |
| 420 | +def test_column_level_rule_creator_with_rule_conditions(mock_client): |
| 421 | + asset = Table.ref_by_qualified_name(qualified_name=ALPHA_DQ_TABLE_QUALIFIED_NAME) |
| 422 | + column = Column.ref_by_qualified_name(qualified_name=ALPHA_DQ_COLUMN_QUALIFIED_NAME) |
| 423 | + |
| 424 | + rule_conditions = ( |
| 425 | + DQRuleConditionsBuilder() |
| 426 | + .add_condition( |
| 427 | + type=alpha_dqRuleTemplateConfigRuleConditions.STRING_LENGTH_BETWEEN, |
| 428 | + min_value=5, |
| 429 | + max_value=50, |
| 430 | + ) |
| 431 | + .build() |
| 432 | + ) |
| 433 | + |
| 434 | + dq_rule = alpha_DQRule.column_level_rule_creator( |
| 435 | + client=mock_client, |
| 436 | + rule_type=ALPHA_DQ_RULE_TYPE_COLUMN, |
| 437 | + asset=asset, |
| 438 | + column=column, |
| 439 | + threshold_value=ALPHA_DQ_RULE_THRESHOLD_VALUE, |
| 440 | + alert_priority=alpha_DQRuleAlertPriority.NORMAL, |
| 441 | + rule_conditions=rule_conditions, |
| 442 | + ) |
| 443 | + |
| 444 | + assert dq_rule.alpha_dq_rule_alert_priority == alpha_DQRuleAlertPriority.NORMAL |
| 445 | + assert dq_rule.alpha_dq_rule_status == alpha_DQRuleStatus.ACTIVE |
| 446 | + assert ( |
| 447 | + dq_rule.alpha_dq_rule_config_arguments.alpha_dq_rule_config_rule_conditions |
| 448 | + == rule_conditions |
| 449 | + ) |
| 450 | + assert ( |
| 451 | + dq_rule.alpha_dq_rule_base_column_qualified_name |
| 452 | + == ALPHA_DQ_COLUMN_QUALIFIED_NAME |
| 453 | + ) |
| 454 | + |
| 455 | + |
| 456 | +def test_validate_template_features_rule_conditions_not_supported(mock_client): |
| 457 | + from pyatlan.errors import InvalidRequestError |
| 458 | + |
| 459 | + config = Mock() |
| 460 | + config.alpha_dq_rule_template_config_rule_conditions = None |
| 461 | + config.alpha_dq_rule_template_advanced_settings = json.dumps({}) |
| 462 | + |
| 463 | + template_config = { |
| 464 | + "name": "Test Template", |
| 465 | + "qualified_name": "test/template/123", |
| 466 | + "config": config, |
| 467 | + } |
| 468 | + |
| 469 | + mock_client.dq_template_config_cache.get_template_config.return_value = ( |
| 470 | + template_config |
| 471 | + ) |
| 472 | + |
| 473 | + rule_conditions = ( |
| 474 | + DQRuleConditionsBuilder() |
| 475 | + .add_condition( |
| 476 | + type=alpha_dqRuleTemplateConfigRuleConditions.STRING_LENGTH_BETWEEN, |
| 477 | + min_value=5, |
| 478 | + max_value=50, |
| 479 | + ) |
| 480 | + .build() |
| 481 | + ) |
| 482 | + |
| 483 | + with pytest.raises( |
| 484 | + InvalidRequestError, |
| 485 | + match="Rule type 'Blank Count' does not support rule conditions", |
| 486 | + ): |
| 487 | + alpha_DQRule.Attributes._validate_template_features( |
| 488 | + rule_type="Blank Count", |
| 489 | + rule_conditions=rule_conditions, |
| 490 | + row_scope_filtering_enabled=False, |
| 491 | + template_config=template_config, |
| 492 | + threshold_compare_operator=alpha_DQRuleThresholdCompareOperator.EQUAL, |
| 493 | + ) |
| 494 | + |
| 495 | + |
| 496 | +def test_validate_template_features_row_scope_filtering_not_supported(mock_client): |
| 497 | + from pyatlan.errors import InvalidRequestError |
| 498 | + |
| 499 | + config = Mock() |
| 500 | + config.alpha_dq_rule_template_config_rule_conditions = json.dumps( |
| 501 | + {"enum": ["STRING_LENGTH_BETWEEN"]} |
| 502 | + ) |
| 503 | + config.alpha_dq_rule_template_advanced_settings = json.dumps({}) |
| 504 | + |
| 505 | + template_config = { |
| 506 | + "name": "Test Template", |
| 507 | + "qualified_name": "test/template/123", |
| 508 | + "config": config, |
| 509 | + } |
| 510 | + |
| 511 | + mock_client.dq_template_config_cache.get_template_config.return_value = ( |
| 512 | + template_config |
| 513 | + ) |
| 514 | + |
| 515 | + with pytest.raises( |
| 516 | + InvalidRequestError, |
| 517 | + match="Rule type 'Blank Count' does not support row scope filtering", |
| 518 | + ): |
| 519 | + alpha_DQRule.Attributes._validate_template_features( |
| 520 | + rule_type="Blank Count", |
| 521 | + rule_conditions=None, |
| 522 | + row_scope_filtering_enabled=True, |
| 523 | + template_config=template_config, |
| 524 | + threshold_compare_operator=alpha_DQRuleThresholdCompareOperator.EQUAL, |
| 525 | + ) |
| 526 | + |
| 527 | + |
386 | 528 | @pytest.mark.parametrize( |
387 | 529 | "qualified_name, message", |
388 | 530 | [ |
|
0 commit comments