From d269ddd03bd6072b5a30c75f6e2dd57f182a3374 Mon Sep 17 00:00:00 2001 From: Tyler Hoffman Date: Fri, 2 Aug 2024 13:56:31 -0400 Subject: [PATCH 1/2] Return the updated fluent datasource --- .../data_context/abstract_data_context.py | 6 +-- tests/datasource/fluent/test_contexts.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/great_expectations/data_context/data_context/abstract_data_context.py b/great_expectations/data_context/data_context/abstract_data_context.py index e2cc75005af2..fd2916ee9e97 100644 --- a/great_expectations/data_context/data_context/abstract_data_context.py +++ b/great_expectations/data_context/data_context/abstract_data_context.py @@ -727,11 +727,7 @@ def update_datasource( Returns: The updated Datasource. """ - if isinstance(datasource, FluentDatasource): - self._update_fluent_datasource(datasource=datasource) - else: - raise DataContextError("Datasource is not a FluentDatasource") # noqa: TRY003 - return datasource + return self._update_fluent_datasource(datasource=datasource) @overload def add_or_update_datasource( diff --git a/tests/datasource/fluent/test_contexts.py b/tests/datasource/fluent/test_contexts.py index a0ca6541ae4c..5d0a58e73960 100644 --- a/tests/datasource/fluent/test_contexts.py +++ b/tests/datasource/fluent/test_contexts.py @@ -24,6 +24,9 @@ from great_expectations.datasource.fluent.constants import ( DEFAULT_PANDAS_DATA_ASSET_NAME, ) +from great_expectations.datasource.fluent.pandas_filesystem_datasource import ( + PandasFilesystemDatasource, +) from tests.datasource.fluent._fake_cloud_api import ( DEFAULT_HEADERS, FAKE_ORG_ID, @@ -180,6 +183,47 @@ def test_delete_asset_with_cloud_data_context( assert asset_name not in asset_names +# This test is parameterized by the fixture `empty_context`. This fixture will mark the test as +# cloud or filesystem as appropriate +def test_context_update_datasource( + cloud_api_fake: RequestsMock, + empty_cloud_context_fluent: CloudDataContext, + # db_file: pathlib.Path, TODO: sqlite deser broken + taxi_data_samples_dir: pathlib.Path, +): + context = empty_cloud_context_fluent + + datasource = context.data_sources.add_pandas_filesystem( + name="save_ds_test", base_directory=taxi_data_samples_dir + ) + datasource.add_csv_asset(name="my_asset") + + # TODO: adjust call counts as needed + datasources_url = urllib.parse.urljoin( + GX_CLOUD_MOCK_BASE_URL, f"api/v1/organizations/{FAKE_ORG_ID}/datasources" + ) + cloud_api_fake.assert_call_count( + datasources_url, + 2, + ) + cloud_api_fake.assert_call_count( + f"{datasources_url}/{datasource.id}?name={datasource.name}", + 2, + ) + + response = requests.get(f"{datasources_url}/{datasource.id}") + response.raise_for_status() + assert response.json()["data"].get("assets") + + # update an arbitrary field + datasource.base_directory = taxi_data_samples_dir / "foo" + + updated_datasource = context.update_datasource(datasource) + assert isinstance(updated_datasource, PandasFilesystemDatasource) + assert updated_datasource.base_directory == datasource.base_directory + assert updated_datasource is not datasource # we should return the new one + + # This test is parameterized by the fixture `empty_context`. This fixture will mark the test as # cloud or filesystem as appropriate def test_context_add_or_update_datasource( From af25e8911221804d2c1342a3b26448153efc2f80 Mon Sep 17 00:00:00 2001 From: Tyler Hoffman Date: Fri, 2 Aug 2024 14:09:52 -0400 Subject: [PATCH 2/2] Oh hi mark --- tests/datasource/fluent/test_contexts.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/datasource/fluent/test_contexts.py b/tests/datasource/fluent/test_contexts.py index 5d0a58e73960..f3a20663f06e 100644 --- a/tests/datasource/fluent/test_contexts.py +++ b/tests/datasource/fluent/test_contexts.py @@ -183,8 +183,7 @@ def test_delete_asset_with_cloud_data_context( assert asset_name not in asset_names -# This test is parameterized by the fixture `empty_context`. This fixture will mark the test as -# cloud or filesystem as appropriate +@pytest.mark.cloud def test_context_update_datasource( cloud_api_fake: RequestsMock, empty_cloud_context_fluent: CloudDataContext,