Skip to content

Commit b481498

Browse files
jorwoodsjacalata
authored andcommitted
feat: support collections in favorites (#1647)
* feat: support collections in favorites The API schema shows collections can be returned with favorites. This change adds support for a `CollectionItem`, as well as making the bundled type returned by favorites more specific. * fix: change Self import to make compat with < 3.11 * fix: use parse_datetime --------- Co-authored-by: Jordan Woods <13803242+jorwoods@users.noreply.github.com>
1 parent 69e1024 commit b481498

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

test/test_favorites.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import tableauserverclient as TSC
77
from tableauserverclient.datetime_helpers import parse_datetime
8+
from ._utils import read_xml_asset
89

910
TEST_ASSET_DIR = Path(__file__).parent / "assets"
1011

@@ -44,12 +45,25 @@ def test_get(server: TSC.Server, user: TSC.UserItem) -> None:
4445
assert len(user.favorites["projects"]) == 1
4546
assert len(user.favorites["datasources"]) == 1
4647

47-
workbook = user.favorites["workbooks"][0]
48-
print("favorited: ")
49-
print(workbook)
50-
view = user.favorites["views"][0]
51-
datasource = user.favorites["datasources"][0]
52-
project = user.favorites["projects"][0]
48+
collection = self.user.favorites["collections"][0]
49+
50+
assert collection.id == "8c57cb8a-d65f-4a32-813e-5a3f86e8f94e"
51+
assert collection.name == "sample collection"
52+
assert collection.description == "description for sample collection"
53+
assert collection.total_item_count == 3
54+
assert collection.permissioned_item_count == 2
55+
assert collection.visibility == "Private"
56+
assert collection.created_at == parse_datetime("2016-08-11T21:22:40Z")
57+
assert collection.updated_at == parse_datetime("2016-08-11T21:34:17Z")
58+
59+
def test_add_favorite_workbook(self) -> None:
60+
response_xml = read_xml_asset(ADD_FAVORITE_WORKBOOK_XML)
61+
workbook = TSC.WorkbookItem("")
62+
workbook._id = "6d13b0ca-043d-4d42-8c9d-3f3313ea3a00"
63+
workbook.name = "Superstore"
64+
with requests_mock.mock() as m:
65+
m.put(f"{self.baseurl}/{self.user.id}", text=response_xml)
66+
self.server.favorites.add_favorite_workbook(self.user, workbook)
5367

5468
assert workbook.id == "6d13b0ca-043d-4d42-8c9d-3f3313ea3a00"
5569
assert view.id == "d79634e1-6063-4ec9-95ff-50acbf609ff5"

0 commit comments

Comments
 (0)