Skip to content

Commit 915f1af

Browse files
authored
chore: convert workbook tests to pytest (#1645)
* chore: workook tests converted to pytest * chore: convert all assets to Paths * chore: convert tests to pytest * style: black * chore: remove asset and read_assets references * chore: narrow download_revision return type * chore: add type hints to fixture --------- Co-authored-by: Jordan Woods <[email protected]>
1 parent a196281 commit 915f1af

File tree

2 files changed

+1088
-1014
lines changed

2 files changed

+1088
-1014
lines changed

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
from tableauserverclient.server import RequestFactory
3131

3232
from typing import (
33+
Literal,
3334
Optional,
3435
TYPE_CHECKING,
36+
TypeVar,
3537
Union,
38+
overload,
3639
)
3740
from collections.abc import Iterable, Sequence
3841

@@ -383,16 +386,34 @@ def update_connections(
383386
logger.info(f"Updated connections for workbook {workbook_item.id}: {', '.join(updated_ids)}")
384387
return connection_items
385388

389+
T = TypeVar("T", bound=FileObjectW)
390+
391+
@overload
392+
def download(
393+
self,
394+
workbook_id: str,
395+
filepath: T,
396+
include_extract: bool = True,
397+
) -> T: ...
398+
399+
@overload
400+
def download(
401+
self,
402+
workbook_id: str,
403+
filepath: Optional[FilePath] = None,
404+
include_extract: bool = True,
405+
) -> str: ...
406+
386407
# Download workbook contents with option of passing in filepath
387408
@api(version="2.0")
388409
@parameter_added_in(no_extract="2.5")
389410
@parameter_added_in(include_extract="2.5")
390411
def download(
391412
self,
392-
workbook_id: str,
393-
filepath: Optional[PathOrFileW] = None,
394-
include_extract: bool = True,
395-
) -> PathOrFileW:
413+
workbook_id,
414+
filepath=None,
415+
include_extract=True,
416+
):
396417
"""
397418
Downloads a workbook to the specified directory (optional).
398419
@@ -741,6 +762,30 @@ def delete_permission(self, item: WorkbookItem, capability_item: PermissionsRule
741762
"""
742763
return self._permissions.delete(item, capability_item)
743764

765+
@overload
766+
def publish(
767+
self,
768+
workbook_item: WorkbookItem,
769+
file: PathOrFileR,
770+
mode: str,
771+
connections: Optional[Sequence[ConnectionItem]],
772+
as_job: Literal[False],
773+
skip_connection_check: bool,
774+
parameters=None,
775+
) -> WorkbookItem: ...
776+
777+
@overload
778+
def publish(
779+
self,
780+
workbook_item: WorkbookItem,
781+
file: PathOrFileR,
782+
mode: str,
783+
connections: Optional[Sequence[ConnectionItem]],
784+
as_job: Literal[True],
785+
skip_connection_check: bool,
786+
parameters=None,
787+
) -> JobItem: ...
788+
744789
@api(version="2.0")
745790
@parameter_added_in(as_job="3.0")
746791
@parameter_added_in(connections="2.8")
@@ -977,15 +1022,27 @@ def _get_workbook_revisions(
9771022
revisions = RevisionItem.from_response(server_response.content, self.parent_srv.namespace, workbook_item)
9781023
return revisions
9791024

1025+
T = TypeVar("T", bound=FileObjectW)
1026+
1027+
@overload
1028+
def download_revision(
1029+
self, workbook_id: str, revision_number: Optional[str], filepath: T, include_extract: bool
1030+
) -> T: ...
1031+
1032+
@overload
1033+
def download_revision(
1034+
self, workbook_id: str, revision_number: Optional[str], filepath: Optional[FilePath], include_extract: bool
1035+
) -> str: ...
1036+
9801037
# Download 1 workbook revision by revision number
9811038
@api(version="2.3")
9821039
def download_revision(
9831040
self,
984-
workbook_id: str,
985-
revision_number: Optional[str],
986-
filepath: Optional[PathOrFileW] = None,
987-
include_extract: bool = True,
988-
) -> PathOrFileW:
1041+
workbook_id,
1042+
revision_number,
1043+
filepath,
1044+
include_extract=True,
1045+
):
9891046
"""
9901047
Downloads a workbook revision to the specified directory (optional).
9911048

0 commit comments

Comments
 (0)