|
1 | | -import unittest |
2 | 1 | import tableauserverclient as TSC |
3 | 2 | import tableauserverclient.server.request_factory as TSC_RF |
4 | 3 | from tableauserverclient.helpers.strings import redact_xml |
5 | 4 | import pytest |
6 | 5 | import sys |
7 | 6 |
|
8 | 7 |
|
9 | | -class WorkbookRequestTests(unittest.TestCase): |
10 | | - def test_embedded_extract_req(self): |
11 | | - include_all = True |
12 | | - embedded_datasources = None |
13 | | - xml_result = TSC_RF.RequestFactory.Workbook.embedded_extract_req(include_all, embedded_datasources) |
14 | | - |
15 | | - def test_generate_xml(self): |
16 | | - workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
17 | | - TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item) |
18 | | - |
19 | | - def test_generate_xml_invalid_connection(self): |
20 | | - workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
21 | | - conn = TSC.ConnectionItem() |
22 | | - with self.assertRaises(ValueError): |
23 | | - request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
24 | | - |
25 | | - def test_generate_xml_invalid_connection_credentials(self): |
26 | | - workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
27 | | - conn = TSC.ConnectionItem() |
28 | | - conn.server_address = "address" |
29 | | - creds = TSC.ConnectionCredentials("username", "password") |
30 | | - creds.name = None |
31 | | - conn.connection_credentials = creds |
32 | | - with self.assertRaises(ValueError): |
33 | | - request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
34 | | - |
35 | | - def test_generate_xml_valid_connection_credentials(self): |
36 | | - workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
37 | | - conn = TSC.ConnectionItem() |
38 | | - conn.server_address = "address" |
39 | | - creds = TSC.ConnectionCredentials("username", "DELETEME") |
40 | | - conn.connection_credentials = creds |
| 8 | +def test_embedded_extract_req() -> None: |
| 9 | + include_all = True |
| 10 | + embedded_datasources = None |
| 11 | + xml_result = TSC_RF.RequestFactory.Workbook.embedded_extract_req(include_all, embedded_datasources) |
| 12 | + |
| 13 | + |
| 14 | +def test_generate_xml() -> None: |
| 15 | + workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
| 16 | + TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item) |
| 17 | + |
| 18 | + |
| 19 | +def test_generate_xml_invalid_connection() -> None: |
| 20 | + workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
| 21 | + conn = TSC.ConnectionItem() |
| 22 | + with pytest.raises(ValueError): |
41 | 23 | request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
42 | | - assert request.find(b"DELETEME") > 0 |
43 | | - |
44 | | - def test_redact_passwords_in_xml(self): |
45 | | - if sys.version_info < (3, 7): |
46 | | - pytest.skip("Redaction is only implemented for 3.7+.") |
47 | | - workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
48 | | - conn = TSC.ConnectionItem() |
49 | | - conn.server_address = "address" |
50 | | - creds = TSC.ConnectionCredentials("username", "DELETEME") |
51 | | - conn.connection_credentials = creds |
| 24 | + |
| 25 | + |
| 26 | +def test_generate_xml_invalid_connection_credentials() -> None: |
| 27 | + workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
| 28 | + conn = TSC.ConnectionItem() |
| 29 | + conn.server_address = "address" |
| 30 | + creds = TSC.ConnectionCredentials("username", "password") |
| 31 | + creds.name = None |
| 32 | + conn.connection_credentials = creds |
| 33 | + with pytest.raises(ValueError): |
52 | 34 | request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
53 | | - redacted = redact_xml(request) |
54 | | - assert request.find(b"DELETEME") > 0, request |
55 | | - assert redacted.find(b"DELETEME") == -1, redacted |
| 35 | + |
| 36 | + |
| 37 | +def test_generate_xml_valid_connection_credentials() -> None: |
| 38 | + workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
| 39 | + conn = TSC.ConnectionItem() |
| 40 | + conn.server_address = "address" |
| 41 | + creds = TSC.ConnectionCredentials("username", "DELETEME") |
| 42 | + conn.connection_credentials = creds |
| 43 | + request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
| 44 | + assert request.find(b"DELETEME") > 0 |
| 45 | + |
| 46 | + |
| 47 | +def test_redact_passwords_in_xml() -> None: |
| 48 | + if sys.version_info < (3, 7): |
| 49 | + pytest.skip("Redaction is only implemented for 3.7+.") |
| 50 | + workbook_item: TSC.WorkbookItem = TSC.WorkbookItem("name", "project_id") |
| 51 | + conn = TSC.ConnectionItem() |
| 52 | + conn.server_address = "address" |
| 53 | + creds = TSC.ConnectionCredentials("username", "DELETEME") |
| 54 | + conn.connection_credentials = creds |
| 55 | + request = TSC_RF.RequestFactory.Workbook._generate_xml(workbook_item, connections=[conn]) |
| 56 | + redacted = redact_xml(request) |
| 57 | + assert request.find(b"DELETEME") > 0, request |
| 58 | + assert redacted.find(b"DELETEME") == -1, redacted |
0 commit comments