|
66 | 66 | _TEST_FG1_F1_DESCRIPTION, |
67 | 67 | _TEST_FG1_F1_LABELS, |
68 | 68 | _TEST_FG1_F1_POINT_OF_CONTACT, |
| 69 | + _TEST_FG1_F2, |
| 70 | + _TEST_FG1_F2_ID, |
| 71 | + _TEST_FG1_F2_PATH, |
| 72 | + _TEST_FG1_F2_DESCRIPTION, |
| 73 | + _TEST_FG1_F2_LABELS, |
| 74 | + _TEST_FG1_F2_POINT_OF_CONTACT, |
| 75 | + _TEST_FG1_F2_VERSION_COLUMN_NAME, |
69 | 76 | ) |
70 | 77 | from test_feature import feature_eq |
71 | 78 |
|
@@ -138,6 +145,18 @@ def create_feature_mock(): |
138 | 145 | yield create_feature_mock |
139 | 146 |
|
140 | 147 |
|
| 148 | +@pytest.fixture |
| 149 | +def create_feature_with_version_column_mock(): |
| 150 | + with patch.object( |
| 151 | + feature_registry_service_client.FeatureRegistryServiceClient, |
| 152 | + "create_feature", |
| 153 | + ) as create_feature_mock: |
| 154 | + create_feature_lro_mock = mock.Mock(ga_operation.Operation) |
| 155 | + create_feature_lro_mock.result.return_value = _TEST_FG1_F2 |
| 156 | + create_feature_mock.return_value = create_feature_lro_mock |
| 157 | + yield create_feature_mock |
| 158 | + |
| 159 | + |
141 | 160 | def fg_eq( |
142 | 161 | fg_to_check: FeatureGroup, |
143 | 162 | name: str, |
@@ -442,3 +461,72 @@ def test_create_feature( |
442 | 461 | ), |
443 | 462 | ] |
444 | 463 | ) |
| 464 | + |
| 465 | + |
| 466 | +@pytest.mark.parametrize("create_request_timeout", [None, 1.0]) |
| 467 | +@pytest.mark.parametrize("sync", [True, False]) |
| 468 | +def test_create_feature_with_version_feature_column( |
| 469 | + get_fg_mock, |
| 470 | + create_feature_with_version_column_mock, |
| 471 | + get_feature_with_version_column_mock, |
| 472 | + fg_logger_mock, |
| 473 | + create_request_timeout, |
| 474 | + sync, |
| 475 | +): |
| 476 | + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) |
| 477 | + |
| 478 | + fg = FeatureGroup(_TEST_FG1_ID) |
| 479 | + feature = fg.create_feature( |
| 480 | + _TEST_FG1_F2_ID, |
| 481 | + version_column_name=_TEST_FG1_F2_VERSION_COLUMN_NAME, |
| 482 | + description=_TEST_FG1_F2_DESCRIPTION, |
| 483 | + labels=_TEST_FG1_F2_LABELS, |
| 484 | + point_of_contact=_TEST_FG1_F2_POINT_OF_CONTACT, |
| 485 | + create_request_timeout=create_request_timeout, |
| 486 | + sync=sync, |
| 487 | + ) |
| 488 | + |
| 489 | + if not sync: |
| 490 | + feature.wait() |
| 491 | + |
| 492 | + expected_feature = types.feature.Feature( |
| 493 | + version_column_name=_TEST_FG1_F2_VERSION_COLUMN_NAME, |
| 494 | + description=_TEST_FG1_F2_DESCRIPTION, |
| 495 | + labels=_TEST_FG1_F2_LABELS, |
| 496 | + point_of_contact=_TEST_FG1_F2_POINT_OF_CONTACT, |
| 497 | + ) |
| 498 | + create_feature_with_version_column_mock.assert_called_once_with( |
| 499 | + parent=_TEST_FG1_PATH, |
| 500 | + feature=expected_feature, |
| 501 | + feature_id=_TEST_FG1_F2_ID, |
| 502 | + metadata=(), |
| 503 | + timeout=create_request_timeout, |
| 504 | + ) |
| 505 | + |
| 506 | + feature_eq( |
| 507 | + feature, |
| 508 | + name=_TEST_FG1_F2_ID, |
| 509 | + resource_name=_TEST_FG1_F2_PATH, |
| 510 | + project=_TEST_PROJECT, |
| 511 | + location=_TEST_LOCATION, |
| 512 | + description=_TEST_FG1_F2_DESCRIPTION, |
| 513 | + labels=_TEST_FG1_F2_LABELS, |
| 514 | + point_of_contact=_TEST_FG1_F2_POINT_OF_CONTACT, |
| 515 | + version_column_name=_TEST_FG1_F2_VERSION_COLUMN_NAME, |
| 516 | + ) |
| 517 | + |
| 518 | + fg_logger_mock.assert_has_calls( |
| 519 | + [ |
| 520 | + call("Creating Feature"), |
| 521 | + call( |
| 522 | + f"Create Feature backing LRO: {create_feature_with_version_column_mock.return_value.operation.name}" |
| 523 | + ), |
| 524 | + call( |
| 525 | + "Feature created. Resource name: projects/test-project/locations/us-central1/featureGroups/my_fg1/features/my_fg1_f2" |
| 526 | + ), |
| 527 | + call("To use this Feature in another session:"), |
| 528 | + call( |
| 529 | + "feature = aiplatform.Feature('projects/test-project/locations/us-central1/featureGroups/my_fg1/features/my_fg1_f2')" |
| 530 | + ), |
| 531 | + ] |
| 532 | + ) |
0 commit comments