|
18 | 18 |
|
19 | 19 | TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), "assets")
|
20 | 20 |
|
| 21 | +ADD_TAG_XML = os.path.join(TEST_ASSET_DIR, "workbook_add_tag.xml") |
21 | 22 | ADD_TAGS_XML = os.path.join(TEST_ASSET_DIR, "workbook_add_tags.xml")
|
22 | 23 | GET_BY_ID_XML = os.path.join(TEST_ASSET_DIR, "workbook_get_by_id.xml")
|
23 | 24 | GET_BY_ID_XML_PERSONAL = os.path.join(TEST_ASSET_DIR, "workbook_get_by_id_personal.xml")
|
@@ -894,3 +895,70 @@ def test_odata_connection(self) -> None:
|
894 | 895 |
|
895 | 896 | assert xml_connection is not None
|
896 | 897 | self.assertEqual(xml_connection.get("serverAddress"), url)
|
| 898 | + |
| 899 | + def test_add_tags(self) -> None: |
| 900 | + workbook = TSC.WorkbookItem("project", "test") |
| 901 | + workbook._id = "06b944d2-959d-4604-9305-12323c95e70e" |
| 902 | + tags = list("abcd") |
| 903 | + |
| 904 | + with requests_mock.mock() as m: |
| 905 | + m.put( |
| 906 | + f"{self.baseurl}/{workbook.id}/tags", |
| 907 | + status_code=200, |
| 908 | + text=Path(ADD_TAGS_XML).read_text(), |
| 909 | + ) |
| 910 | + tag_result = self.server.workbooks.add_tags(workbook, tags) |
| 911 | + |
| 912 | + for a, b in zip(sorted(tag_result), sorted(tags)): |
| 913 | + self.assertEqual(a, b) |
| 914 | + |
| 915 | + def test_add_tag(self) -> None: |
| 916 | + workbook = TSC.WorkbookItem("project", "test") |
| 917 | + workbook._id = "06b944d2-959d-4604-9305-12323c95e70e" |
| 918 | + tags = "a" |
| 919 | + |
| 920 | + with requests_mock.mock() as m: |
| 921 | + m.put( |
| 922 | + f"{self.baseurl}/{workbook.id}/tags", |
| 923 | + status_code=200, |
| 924 | + text=Path(ADD_TAG_XML).read_text(), |
| 925 | + ) |
| 926 | + tag_result = self.server.workbooks.add_tags(workbook, tags) |
| 927 | + |
| 928 | + for a, b in zip(sorted(tag_result), sorted(tags)): |
| 929 | + self.assertEqual(a, b) |
| 930 | + |
| 931 | + def test_add_tag_id(self) -> None: |
| 932 | + workbook = TSC.WorkbookItem("project", "test") |
| 933 | + workbook._id = "06b944d2-959d-4604-9305-12323c95e70e" |
| 934 | + tags = "a" |
| 935 | + |
| 936 | + with requests_mock.mock() as m: |
| 937 | + m.put( |
| 938 | + f"{self.baseurl}/{workbook.id}/tags", |
| 939 | + status_code=200, |
| 940 | + text=Path(ADD_TAG_XML).read_text(), |
| 941 | + ) |
| 942 | + tag_result = self.server.workbooks.add_tags(workbook.id, tags) |
| 943 | + |
| 944 | + for a, b in zip(sorted(tag_result), sorted(tags)): |
| 945 | + self.assertEqual(a, b) |
| 946 | + |
| 947 | + def test_delete_tags(self) -> None: |
| 948 | + workbook = TSC.WorkbookItem("project", "test") |
| 949 | + workbook._id = "06b944d2-959d-4604-9305-12323c95e70e" |
| 950 | + tags = list("abcd") |
| 951 | + |
| 952 | + matcher = re.compile(rf"{self.baseurl}\/{workbook.id}\/tags\/[abcd]") |
| 953 | + with requests_mock.mock() as m: |
| 954 | + m.delete( |
| 955 | + matcher, |
| 956 | + status_code=200, |
| 957 | + text="", |
| 958 | + ) |
| 959 | + self.server.workbooks.delete_tags(workbook, tags) |
| 960 | + history = m.request_history |
| 961 | + |
| 962 | + self.assertEqual(len(history), len(tags)) |
| 963 | + urls = sorted([r.url.split("/")[-1] for r in history]) |
| 964 | + self.assertEqual(urls, sorted(tags)) |
0 commit comments