-
Notifications
You must be signed in to change notification settings - Fork 445
test(e2e): add e2e tests for workbooks, datasources, views, pagination, jobs, tagging, projects, favorites, metadata, site-admin #1823
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
Open
jacalata
wants to merge
10
commits into
development
Choose a base branch
from
jac/e2e-tests
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9ec3cf9
test: add e2e tests for 10 TSC endpoints
jacalata eed1bd2
test: consolidate e2e project lookup into conftest fixtures
jacalata 966ca5e
test: add WorldIndicators.tdsx asset for datasource e2e tests
jacalata 182e16d
test: fix e2e test failures found during live server run
jacalata 1acb3db
test(e2e): merge favorites, metadata, site-admin tests and extract wo…
jacalata 31a9136
fix(e2e): use WorldIndicators.tdsx instead of SampleDS.tds for dataso…
jacalata 424c7b4
Merge origin/development into jac/e2e-tests
jacalata 3a4fe13
test(e2e): address review feedback from bcantoni on #1823
jacalata 4279ccb
test(e2e): unique per-run names, guarded delete_permission cleanup
jacalata 866049f
test(e2e): address remaining fresh-eyes findings on #1823
jacalata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """ | ||
| E2E tests for datasource CRUD operations against a real Tableau server. | ||
|
|
||
| Run with: | ||
| TABLEAU_SERVER=https://... TABLEAU_SITE=mysite TABLEAU_TOKEN=... TABLEAU_TOKEN_NAME=... \ | ||
| pytest test_e2e/test_datasources_crud.py -v | ||
| """ | ||
|
|
||
| import os | ||
| import warnings | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import tableauserverclient as TSC | ||
| from tableauserverclient.server.endpoint.exceptions import ServerResponseError | ||
|
|
||
| ASSETS_DIR = Path(__file__).parent / "assets" | ||
| SAMPLE_DATASOURCE = ASSETS_DIR / "WorldIndicators.tdsx" | ||
|
|
||
| pytestmark = pytest.mark.e2e | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def datasource(server, project_id): | ||
| """Publish a datasource for CRUD tests; clean up after.""" | ||
| ds_item = TSC.DatasourceItem(project_id=project_id, name="tsc-e2e-datasource-crud") | ||
| ds_item = server.datasources.publish(ds_item, SAMPLE_DATASOURCE, TSC.Server.PublishMode.Overwrite) | ||
| yield ds_item | ||
| server.datasources.delete(ds_item.id) | ||
|
|
||
|
|
||
| def test_datasource_publish(server, datasource): | ||
| """datasources.publish() returns a DatasourceItem with an id.""" | ||
| assert datasource.id is not None | ||
| assert datasource.name == "tsc-e2e-datasource-crud" | ||
|
|
||
|
|
||
| def test_datasources_get(server, datasource): | ||
| """datasources.get() with a name filter returns the published datasource.""" | ||
| opts = TSC.RequestOptions() | ||
| opts.filter.add( | ||
| TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, "tsc-e2e-datasource-crud") | ||
| ) | ||
| results, pagination = server.datasources.get(opts) | ||
| assert len(results) >= 1 | ||
| assert any(ds.id == datasource.id for ds in results) | ||
|
|
||
|
|
||
| def test_datasources_get_by_id(server, datasource): | ||
| """datasources.get_by_id() returns the correct DatasourceItem.""" | ||
| fetched = server.datasources.get_by_id(datasource.id) | ||
| assert fetched.id == datasource.id | ||
| assert fetched.name == datasource.name | ||
|
|
||
|
|
||
| def test_datasources_update_description(server, datasource): | ||
| """datasources.update() persists a description change.""" | ||
| original_description = datasource.description | ||
| datasource.description = "e2e-test description" | ||
| server.datasources.update(datasource) | ||
| fetched = server.datasources.get_by_id(datasource.id) | ||
| try: | ||
| assert fetched.description == "e2e-test description" | ||
| finally: | ||
| datasource.description = original_description | ||
| server.datasources.update(datasource) | ||
|
|
||
|
|
||
| def test_datasources_populate_connections(server, datasource): | ||
| """datasources.populate_connections() populates the connections list without error.""" | ||
| fetched = server.datasources.get_by_id(datasource.id) | ||
| server.datasources.populate_connections(fetched) | ||
| connections = fetched.connections | ||
| assert isinstance(connections, list) | ||
|
|
||
|
|
||
| def test_datasources_add_tags(server, datasource): | ||
| """datasources.add_tags() adds a tag that is visible via get_by_id().""" | ||
| server.datasources.add_tags(datasource, ["e2e-test"]) | ||
| try: | ||
| fetched = server.datasources.get_by_id(datasource.id) | ||
| assert "e2e-test" in fetched.tags | ||
| finally: | ||
| server.datasources.delete_tags(datasource, ["e2e-test"]) | ||
|
|
||
|
|
||
| def test_datasources_delete_tags(server, datasource): | ||
| """datasources.delete_tags() removes a previously added tag.""" | ||
| server.datasources.add_tags(datasource, ["e2e-test-delete"]) | ||
| server.datasources.delete_tags(datasource, ["e2e-test-delete"]) | ||
| fetched = server.datasources.get_by_id(datasource.id) | ||
| assert "e2e-test-delete" not in fetched.tags | ||
|
|
||
|
|
||
| def test_datasources_download(server, datasource, tmp_path): | ||
| """datasources.download() writes a non-empty file.""" | ||
| result_path = server.datasources.download(datasource.id, filepath=str(tmp_path)) | ||
| assert os.path.isfile(result_path) | ||
| assert os.path.getsize(result_path) > 0 | ||
|
|
||
|
|
||
| def test_datasources_delete(server, project_id): | ||
| """datasources.delete() removes a datasource; subsequent get_by_id raises ServerResponseError.""" | ||
| ds_item = TSC.DatasourceItem(project_id=project_id, name="tsc-e2e-datasource-delete") | ||
| published = server.datasources.publish(ds_item, SAMPLE_DATASOURCE, TSC.Server.PublishMode.Overwrite) | ||
| ds_id = published.id | ||
| try: | ||
| server.datasources.delete(ds_id) | ||
| with pytest.raises(ServerResponseError): | ||
| server.datasources.get_by_id(ds_id) | ||
| finally: | ||
| try: | ||
| server.datasources.delete(ds_id) | ||
| except Exception as exc: | ||
| warnings.warn(f"Failed to delete datasource: {exc}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """ | ||
| E2E tests for favorites operations against a real Tableau server. | ||
|
|
||
| Run with: | ||
| TABLEAU_SERVER=https://... TABLEAU_SITE=mysite TABLEAU_TOKEN=... TABLEAU_TOKEN_NAME=... \ | ||
| pytest test_e2e/test_favorites.py -v | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import tableauserverclient as TSC | ||
| from tableauserverclient.models import Resource | ||
|
|
||
| ASSETS_DIR = Path(__file__).parent / "assets" | ||
| SAMPLE_WORKBOOK = ASSETS_DIR / "WorkbookWithoutExtract.twbx" | ||
| SAMPLE_DATASOURCE = ASSETS_DIR / "WorldIndicators.tdsx" | ||
|
|
||
| pytestmark = pytest.mark.e2e | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def workbook(server, project_id): | ||
| wb = TSC.WorkbookItem(name="tsc-e2e-favorites-wb", project_id=project_id) | ||
| wb = server.workbooks.publish(wb, SAMPLE_WORKBOOK, TSC.Server.PublishMode.Overwrite) | ||
| try: | ||
| yield wb | ||
| finally: | ||
| server.workbooks.delete(wb.id) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def datasource(server, project_id): | ||
| ds = TSC.DatasourceItem(project_id=project_id, name="tsc-e2e-favorites-ds") | ||
| ds = server.datasources.publish(ds, SAMPLE_DATASOURCE, TSC.Server.PublishMode.Overwrite) | ||
| try: | ||
| yield ds | ||
| finally: | ||
| server.datasources.delete(ds.id) | ||
|
|
||
|
|
||
| def test_favorites_workbook(server, workbook): | ||
| """A workbook can be added to and removed from favorites.""" | ||
| user = TSC.UserItem() | ||
| user.id = server.user_id | ||
| server.favorites.add_favorite(user, Resource.Workbook, workbook) | ||
| server.favorites.get(user) | ||
| try: | ||
| assert any(f.id == workbook.id for f in user.favorites.get("workbooks", [])) | ||
| finally: | ||
| server.favorites.delete_favorite_workbook(user, workbook) | ||
|
|
||
|
|
||
| def test_favorites_view(server, workbook): | ||
| """A view can be added to and removed from favorites.""" | ||
| server.workbooks.populate_views(workbook) | ||
| if not workbook.views: | ||
| pytest.skip(f"Published workbook {workbook.name!r} has no views") | ||
| view = workbook.views[0] | ||
| user = TSC.UserItem() | ||
| user.id = server.user_id | ||
| server.favorites.add_favorite_view(user, view) | ||
| server.favorites.get(user) | ||
| try: | ||
| assert any(f.id == view.id for f in user.favorites.get("views", [])) | ||
| finally: | ||
| server.favorites.delete_favorite_view(user, view) | ||
|
|
||
|
|
||
| def test_favorites_datasource(server, datasource): | ||
| """A datasource can be added to and removed from favorites.""" | ||
| user = TSC.UserItem() | ||
| user.id = server.user_id | ||
| server.favorites.add_favorite_datasource(user, datasource) | ||
| server.favorites.get(user) | ||
| try: | ||
| assert any(f.id == datasource.id for f in user.favorites.get("datasources", [])) | ||
| finally: | ||
| server.favorites.delete_favorite_datasource(user, datasource) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.