Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] update_datasource returns the updated datasource #10170

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
43 changes: 43 additions & 0 deletions tests/datasource/fluent/test_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -180,6 +183,46 @@ def test_delete_asset_with_cloud_data_context(
assert asset_name not in asset_names


@pytest.mark.cloud
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(
Expand Down
Loading