|
24 | 24 | GET_EMPTY_XML = TEST_ASSET_DIR / "datasource_get_empty.xml" |
25 | 25 | GET_BY_ID_XML = TEST_ASSET_DIR / "datasource_get_by_id.xml" |
26 | 26 | GET_XML_ALL_FIELDS = TEST_ASSET_DIR / "datasource_get_all_fields.xml" |
| 27 | +GET_NO_OWNER = TEST_ASSET_DIR / "datasource_get_no_owner.xml" |
27 | 28 | POPULATE_CONNECTIONS_XML = TEST_ASSET_DIR / "datasource_populate_connections.xml" |
28 | 29 | POPULATE_PERMISSIONS_XML = TEST_ASSET_DIR / "datasource_populate_permissions.xml" |
29 | 30 | PUBLISH_XML = TEST_ASSET_DIR / "datasource_publish.xml" |
@@ -850,3 +851,57 @@ def test_get_datasource_all_fields(server) -> None: |
850 | 851 | assert datasources[0].owner.last_login == parse_datetime("2025-02-04T06:39:20Z") |
851 | 852 | assert datasources[ 0]. owner. name == "[email protected]" |
852 | 853 | assert datasources[0].owner.site_role == "SiteAdministratorCreator" |
| 854 | + |
| 855 | + |
| 856 | +def test_update_description(server: TSC.Server) -> None: |
| 857 | + response_xml = UPDATE_XML.read_text() |
| 858 | + with requests_mock.mock() as m: |
| 859 | + m.put(server.datasources.baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", text=response_xml) |
| 860 | + single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource") |
| 861 | + single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794" |
| 862 | + single_datasource._content_url = "Sampledatasource" |
| 863 | + single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb" |
| 864 | + single_datasource.certified = True |
| 865 | + single_datasource.certification_note = "Warning, here be dragons." |
| 866 | + single_datasource.description = "Sample description" |
| 867 | + _ = server.datasources.update(single_datasource) |
| 868 | + |
| 869 | + history = m.request_history[0] |
| 870 | + body = fromstring(history.body) |
| 871 | + ds_elem = body.find(".//datasource") |
| 872 | + assert ds_elem is not None |
| 873 | + assert ds_elem.attrib["description"] == "Sample description" |
| 874 | + |
| 875 | + |
| 876 | +def test_publish_description(server: TSC.Server) -> None: |
| 877 | + response_xml = PUBLISH_XML.read_text() |
| 878 | + with requests_mock.mock() as m: |
| 879 | + m.post(server.datasources.baseurl, text=response_xml) |
| 880 | + single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource") |
| 881 | + single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794" |
| 882 | + single_datasource._content_url = "Sampledatasource" |
| 883 | + single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb" |
| 884 | + single_datasource.certified = True |
| 885 | + single_datasource.certification_note = "Warning, here be dragons." |
| 886 | + single_datasource.description = "Sample description" |
| 887 | + _ = server.datasources.publish(single_datasource, TEST_ASSET_DIR / "SampleDS.tds", server.PublishMode.CreateNew) |
| 888 | + |
| 889 | + history = m.request_history[0] |
| 890 | + boundary = history.body[: history.body.index(b"\r\n")].strip() |
| 891 | + parts = history.body.split(boundary) |
| 892 | + request_payload = next(part for part in parts if b"request_payload" in part) |
| 893 | + xml_payload = request_payload.strip().split(b"\r\n")[-1] |
| 894 | + body = fromstring(xml_payload) |
| 895 | + ds_elem = body.find(".//datasource") |
| 896 | + assert ds_elem is not None |
| 897 | + assert ds_elem.attrib["description"] == "Sample description" |
| 898 | + |
| 899 | + |
| 900 | +def test_get_datasource_no_owner(server: TSC.Server) -> None: |
| 901 | + with requests_mock.mock() as m: |
| 902 | + m.get(server.datasources.baseurl, text=GET_NO_OWNER.read_text()) |
| 903 | + datasources, _ = server.datasources.get() |
| 904 | + |
| 905 | + datasource = datasources[0] |
| 906 | + assert datasource.owner is None |
| 907 | + assert datasource.project is None |
0 commit comments