|
29 | 29 | ) |
30 | 30 | from trino import constants |
31 | 31 | from trino.auth import OAuth2Authentication |
32 | | -from trino.dbapi import connect |
| 32 | +from trino.dbapi import Connection, connect |
33 | 33 |
|
34 | 34 |
|
35 | 35 | @patch("trino.dbapi.trino.client") |
@@ -272,3 +272,40 @@ def test_role_is_set_when_specified(mock_client): |
272 | 272 |
|
273 | 273 | _, passed_role = mock_client.ClientSession.call_args |
274 | 274 | assert passed_role["roles"] == roles |
| 275 | + |
| 276 | + |
| 277 | +def test_hostname_parsing(): |
| 278 | + https_server_with_port = Connection("https://mytrinoserver.domain:9999") |
| 279 | + assert https_server_with_port.host == "mytrinoserver.domain" |
| 280 | + assert https_server_with_port.port == 9999 |
| 281 | + assert https_server_with_port.http_scheme == constants.HTTPS |
| 282 | + |
| 283 | + https_server_without_port = Connection("https://mytrinoserver.domain") |
| 284 | + assert https_server_without_port.host == "mytrinoserver.domain" |
| 285 | + assert https_server_without_port.port == 8080 |
| 286 | + assert https_server_without_port.http_scheme == constants.HTTPS |
| 287 | + |
| 288 | + http_server_with_port = Connection("http://mytrinoserver.domain:9999") |
| 289 | + assert http_server_with_port.host == "mytrinoserver.domain" |
| 290 | + assert http_server_with_port.port == 9999 |
| 291 | + assert http_server_with_port.http_scheme == constants.HTTP |
| 292 | + |
| 293 | + http_server_without_port = Connection("http://mytrinoserver.domain") |
| 294 | + assert http_server_without_port.host == "mytrinoserver.domain" |
| 295 | + assert http_server_without_port.port == 8080 |
| 296 | + assert http_server_without_port.http_scheme == constants.HTTP |
| 297 | + |
| 298 | + http_server_with_path = Connection("http://mytrinoserver.domain/some_path") |
| 299 | + assert http_server_with_path.host == "mytrinoserver.domain/some_path" |
| 300 | + assert http_server_with_path.port == 8080 |
| 301 | + assert http_server_with_path.http_scheme == constants.HTTP |
| 302 | + |
| 303 | + only_hostname = Connection("mytrinoserver.domain") |
| 304 | + assert only_hostname.host == "mytrinoserver.domain" |
| 305 | + assert only_hostname.port == 8080 |
| 306 | + assert only_hostname.http_scheme == constants.HTTP |
| 307 | + |
| 308 | + only_hostname_with_path = Connection("mytrinoserver.domain/some_path") |
| 309 | + assert only_hostname_with_path.host == "mytrinoserver.domain/some_path" |
| 310 | + assert only_hostname_with_path.port == 8080 |
| 311 | + assert only_hostname_with_path.http_scheme == constants.HTTP |
0 commit comments