|
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 |
|
| 6 | +import pytest |
6 | 7 | from gooddata_api_client.exceptions import NotFoundException |
7 | 8 | from gooddata_sdk import ( |
8 | 9 | CatalogCspDirective, |
|
14 | 15 | CatalogWebhook, |
15 | 16 | GoodDataSdk, |
16 | 17 | ) |
| 18 | +from gooddata_sdk.catalog.organization.entity_model.organization import CatalogOrganizationAttributes |
17 | 19 | from tests_support.vcrpy_utils import get_vcr |
18 | 20 |
|
19 | 21 | from .conftest import safe_delete |
@@ -563,3 +565,89 @@ def test_layout_notification_channels(test_config, snapshot_notification_channel |
563 | 565 | # sdk.catalog_organization.put_declarative_identity_providers([]) |
564 | 566 | # idps = sdk.catalog_organization.get_declarative_identity_providers() |
565 | 567 | # assert len(idps) == 0 |
| 568 | + |
| 569 | + |
| 570 | +# Unit tests for deployment diagnostic fields (no cassettes needed) |
| 571 | + |
| 572 | + |
| 573 | +@pytest.mark.parametrize( |
| 574 | + "scenario, data_center, region", |
| 575 | + [ |
| 576 | + ("both_set", "us-east-1", "prod-cluster"), |
| 577 | + ("only_data_center", "eu-west-1", None), |
| 578 | + ("only_region", None, "staging"), |
| 579 | + ("both_none", None, None), |
| 580 | + ], |
| 581 | +) |
| 582 | +def test_organization_attributes_diagnostic_fields(scenario, data_center, region): |
| 583 | + """data_center and region are stored on CatalogOrganizationAttributes.""" |
| 584 | + attrs = CatalogOrganizationAttributes( |
| 585 | + name="TestOrg", |
| 586 | + hostname="test.gooddata.com", |
| 587 | + data_center=data_center, |
| 588 | + region=region, |
| 589 | + ) |
| 590 | + assert attrs.data_center == data_center |
| 591 | + assert attrs.region == region |
| 592 | + |
| 593 | + |
| 594 | +@pytest.mark.parametrize( |
| 595 | + "scenario, data_center, region", |
| 596 | + [ |
| 597 | + ("both_set", "us-east-1", "prod-cluster"), |
| 598 | + ("only_data_center", "eu-west-1", None), |
| 599 | + ("only_region", None, "staging"), |
| 600 | + ("both_none", None, None), |
| 601 | + ], |
| 602 | +) |
| 603 | +def test_organization_attributes_to_api_excludes_diagnostic_fields(scenario, data_center, region): |
| 604 | + """to_api() must not forward read-only diagnostic fields to the write model.""" |
| 605 | + attrs = CatalogOrganizationAttributes( |
| 606 | + name="TestOrg", |
| 607 | + hostname="test.gooddata.com", |
| 608 | + data_center=data_center, |
| 609 | + region=region, |
| 610 | + ) |
| 611 | + api_model = attrs.to_api() |
| 612 | + api_dict = api_model.to_dict() |
| 613 | + assert "dataCenter" not in api_dict |
| 614 | + assert "data_center" not in api_dict |
| 615 | + assert "region" not in api_dict |
| 616 | + |
| 617 | + |
| 618 | +def test_catalog_organization_from_api_reads_diagnostic_fields(): |
| 619 | + """CatalogOrganization.from_api() populates data_center and region from the response. |
| 620 | +
|
| 621 | + The keys use snake_case as exposed by the OpenApiModel __getitem__ accessor |
| 622 | + (camelCase keys are normalised to snake_case by the generated client). |
| 623 | + """ |
| 624 | + entity = { |
| 625 | + "id": "default", |
| 626 | + "type": "organization", |
| 627 | + "attributes": { |
| 628 | + "name": "TestOrg", |
| 629 | + "hostname": "test.gooddata.com", |
| 630 | + "data_center": "us-east-1", |
| 631 | + "region": "prod-cluster", |
| 632 | + }, |
| 633 | + "relationships": {}, |
| 634 | + } |
| 635 | + org = CatalogOrganization.from_api(entity) |
| 636 | + assert org.attributes.data_center == "us-east-1" |
| 637 | + assert org.attributes.region == "prod-cluster" |
| 638 | + |
| 639 | + |
| 640 | +def test_catalog_organization_from_api_handles_missing_diagnostic_fields(): |
| 641 | + """from_api() gracefully handles responses that lack data_center/region.""" |
| 642 | + entity = { |
| 643 | + "id": "default", |
| 644 | + "type": "organization", |
| 645 | + "attributes": { |
| 646 | + "name": "TestOrg", |
| 647 | + "hostname": "test.gooddata.com", |
| 648 | + }, |
| 649 | + "relationships": {}, |
| 650 | + } |
| 651 | + org = CatalogOrganization.from_api(entity) |
| 652 | + assert org.attributes.data_center is None |
| 653 | + assert org.attributes.region is None |
0 commit comments