|
| 1 | +from contextlib import ExitStack |
1 | 2 | import re
|
2 | 3 | from typing import Iterable
|
3 | 4 | import uuid
|
|
6 | 7 | import pytest
|
7 | 8 | import requests_mock
|
8 | 9 | import tableauserverclient as TSC
|
9 |
| -from tableauserverclient.server.endpoint.resource_tagger import content |
10 | 10 |
|
11 | 11 |
|
12 | 12 | @pytest.fixture
|
@@ -153,6 +153,42 @@ def test_delete_tags(get_server, endpoint_type, item, tags) -> None:
|
153 | 153 | urls = {r.url.split("/")[-1] for r in history}
|
154 | 154 | assert urls == tag_set
|
155 | 155 |
|
| 156 | +@pytest.mark.parametrize("endpoint_type, item", *sample_taggable_items) |
| 157 | +@pytest.mark.parametrize("tags", sample_tags) |
| 158 | +def test_update_tags(get_server, endpoint_type, item, tags) -> None: |
| 159 | + if isinstance(item, str): |
| 160 | + return |
| 161 | + endpoint = getattr(get_server, endpoint_type) |
| 162 | + id_ = getattr(item, "id", item) |
| 163 | + tags = set([tags] if isinstance(tags, str) else tags) |
| 164 | + with ExitStack() as stack: |
| 165 | + if hasattr(item, "_initial_tags"): |
| 166 | + initial_tags = set(['x','y','z']) |
| 167 | + item._initial_tags = initial_tags |
| 168 | + add_tags_xml = add_tag_xml_response_factory(tags - initial_tags) |
| 169 | + delete_tags_xml = add_tag_xml_response_factory(initial_tags - tags) |
| 170 | + m = stack.enter_context(requests_mock.mock()) |
| 171 | + m.put( |
| 172 | + f"{endpoint.baseurl}/{id_}/tags", |
| 173 | + status_code=200, |
| 174 | + text=add_tags_xml, |
| 175 | + ) |
| 176 | + |
| 177 | + tag_paths = "|".join(initial_tags - tags) |
| 178 | + tag_paths = f"({tag_paths})" |
| 179 | + matcher = re.compile(rf"{endpoint.baseurl}\/{id_}\/tags\/{tag_paths}") |
| 180 | + m.delete( |
| 181 | + matcher, |
| 182 | + status_code=200, |
| 183 | + text=delete_tags_xml, |
| 184 | + ) |
| 185 | + |
| 186 | + else: |
| 187 | + stack.enter_context(pytest.raises(NotImplementedError)) |
| 188 | + |
| 189 | + |
| 190 | + endpoint.update_tags(item) |
| 191 | + |
156 | 192 |
|
157 | 193 | def test_tags_batch_add(get_server) -> None:
|
158 | 194 | server = get_server
|
|
0 commit comments