|
2 | 2 | from pathlib import Path
|
3 | 3 | import unittest
|
4 | 4 |
|
| 5 | +import pytest |
5 | 6 | import requests_mock
|
6 | 7 |
|
7 | 8 | import tableauserverclient as TSC
|
|
12 | 13 |
|
13 | 14 | VIRTUAL_CONNECTION_GET_XML = ASSET_DIR / "virtual_connections_get.xml"
|
14 | 15 | VIRTUAL_CONNECTION_POPULATE_CONNECTIONS = ASSET_DIR / "virtual_connection_populate_connections.xml"
|
| 16 | +VIRTUAL_CONNECTION_POPULATE_CONNECTIONS2 = ASSET_DIR / "virtual_connection_populate_connections2.xml" |
15 | 17 | VC_DB_CONN_UPDATE = ASSET_DIR / "virtual_connection_database_connection_update.xml"
|
16 | 18 | VIRTUAL_CONNECTION_DOWNLOAD = ASSET_DIR / "virtual_connections_download.xml"
|
17 | 19 | VIRTUAL_CONNECTION_UPDATE = ASSET_DIR / "virtual_connections_update.xml"
|
@@ -54,23 +56,27 @@ def test_virtual_connection_get(self):
|
54 | 56 | assert items[0].name == "vconn"
|
55 | 57 |
|
56 | 58 | def test_virtual_connection_populate_connections(self):
|
57 |
| - vconn = VirtualConnectionItem("vconn") |
58 |
| - vconn._id = "8fd7cc02-bb55-4d15-b8b1-9650239efe79" |
59 |
| - with requests_mock.mock() as m: |
60 |
| - m.get(f"{self.baseurl}/{vconn.id}/connections", text=VIRTUAL_CONNECTION_POPULATE_CONNECTIONS.read_text()) |
61 |
| - vc_out = self.server.virtual_connections.populate_connections(vconn) |
62 |
| - connection_list = list(vconn.connections) |
63 |
| - |
64 |
| - assert vc_out is vconn |
65 |
| - assert vc_out._connections is not None |
66 |
| - |
67 |
| - assert len(connection_list) == 1 |
68 |
| - connection = connection_list[0] |
69 |
| - assert connection.id == "37ca6ced-58d7-4dcf-99dc-f0a85223cbef" |
70 |
| - assert connection.connection_type == "postgres" |
71 |
| - assert connection.server_address == "localhost" |
72 |
| - assert connection.server_port == "5432" |
73 |
| - assert connection.username == "pgadmin" |
| 59 | + for i, populate_connections_xml in enumerate( |
| 60 | + (VIRTUAL_CONNECTION_POPULATE_CONNECTIONS, VIRTUAL_CONNECTION_POPULATE_CONNECTIONS2) |
| 61 | + ): |
| 62 | + with self.subTest(i): |
| 63 | + vconn = VirtualConnectionItem("vconn") |
| 64 | + vconn._id = "8fd7cc02-bb55-4d15-b8b1-9650239efe79" |
| 65 | + with requests_mock.mock() as m: |
| 66 | + m.get(f"{self.baseurl}/{vconn.id}/connections", text=populate_connections_xml.read_text()) |
| 67 | + vc_out = self.server.virtual_connections.populate_connections(vconn) |
| 68 | + connection_list = list(vconn.connections) |
| 69 | + |
| 70 | + assert vc_out is vconn |
| 71 | + assert vc_out._connections is not None |
| 72 | + |
| 73 | + assert len(connection_list) == 1 |
| 74 | + connection = connection_list[0] |
| 75 | + assert connection.id == "37ca6ced-58d7-4dcf-99dc-f0a85223cbef" |
| 76 | + assert connection.connection_type == "postgres" |
| 77 | + assert connection.server_address == "localhost" |
| 78 | + assert connection.server_port == "5432" |
| 79 | + assert connection.username == "pgadmin" |
74 | 80 |
|
75 | 81 | def test_virtual_connection_update_connection_db_connection(self):
|
76 | 82 | vconn = VirtualConnectionItem("vconn")
|
|
0 commit comments