Skip to content

Commit 59542e6

Browse files
committed
chores: fix unit tests by change fixture scope to "function"
1 parent 8a3e034 commit 59542e6

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

tests/unit/conftest.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
import pytest
1616

17+
from tests.unit.oauth_test_utils import SERVER_ADDRESS
1718

18-
@pytest.fixture(scope="session")
19+
20+
@pytest.fixture
1921
def sample_post_response_data():
2022
"""
2123
This is the response to the first HTTP request (a POST) from an actual
@@ -38,10 +40,10 @@ def sample_post_response_data():
3840
"""
3941

4042
yield {
41-
"nextUri": "https://coordinator:8080/v1/statement/20210817_140827_00000_arvdv/1",
43+
"nextUri": f"{SERVER_ADDRESS}:8080/v1/statement/20210817_140827_00000_arvdv/1",
4244
"id": "20210817_140827_00000_arvdv",
4345
"taskDownloadUris": [],
44-
"infoUri": "https://coordinator:8080/query.html?20210817_140827_00000_arvdv",
46+
"infoUri": f"{SERVER_ADDRESS}:8080/query.html?20210817_140827_00000_arvdv",
4547
"stats": {
4648
"scheduled": False,
4749
"runningSplits": 0,
@@ -60,7 +62,7 @@ def sample_post_response_data():
6062
}
6163

6264

63-
@pytest.fixture(scope="session")
65+
@pytest.fixture
6466
def sample_get_response_data():
6567
"""
6668
This is the response to the second HTTP request (a GET) from an actual
@@ -73,7 +75,7 @@ def sample_get_response_data():
7375
"""
7476
yield {
7577
"id": "20210817_140827_00000_arvdv",
76-
"nextUri": "coordinator:8080/v1/statement/20210817_140827_00000_arvdv/2",
78+
"nextUri": f"{SERVER_ADDRESS}:8080/v1/statement/20210817_140827_00000_arvdv/2",
7779
"data": [
7880
["UUID-0", "http://worker0:8080", "0.157", False, "active"],
7981
["UUID-1", "http://worker1:8080", "0.157", False, "active"],
@@ -132,7 +134,7 @@ def sample_get_response_data():
132134
},
133135
],
134136
"taskDownloadUris": [],
135-
"partialCancelUri": "http://localhost:8080/v1/stage/20210817_140827_00000_arvdv.0", # NOQA: E501
137+
"partialCancelUri": f"{SERVER_ADDRESS}:8080/v1/stage/20210817_140827_00000_arvdv.0", # NOQA: E501
136138
"stats": {
137139
"nodes": 2,
138140
"processedBytes": 880,
@@ -181,11 +183,11 @@ def sample_get_response_data():
181183
"queuedSplits": 0,
182184
"wallTimeMillis": 36,
183185
},
184-
"infoUri": "http://coordinator:8080/query.html?20210817_140827_00000_arvdv", # NOQA: E501
186+
"infoUri": f"{SERVER_ADDRESS}:8080/query.html?20210817_140827_00000_arvdv", # NOQA: E501
185187
}
186188

187189

188-
@pytest.fixture(scope="session")
190+
@pytest.fixture
189191
def sample_get_error_response_data():
190192
yield {
191193
"error": {
@@ -195,8 +197,7 @@ def sample_get_error_response_data():
195197
"errorType": "USER_ERROR",
196198
"failureInfo": {
197199
"errorLocation": {"columnNumber": 15, "lineNumber": 1},
198-
"message": "line 1:15: Schema must be specified "
199-
"when session schema is not set",
200+
"message": "line 1:15: Schema must be specified when session schema is not set",
200201
"stack": [
201202
"io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:48)",
202203
"io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:43)",
@@ -241,7 +242,7 @@ def sample_get_error_response_data():
241242
"message": "line 1:15: Schema must be specified when session schema is not set",
242243
},
243244
"id": "20210817_140827_00000_arvdv",
244-
"infoUri": "http://localhost:8080/query.html?20210817_140827_00000_arvdv",
245+
"infoUri": f"{SERVER_ADDRESS}:8080/query.html?20210817_140827_00000_arvdv",
245246
"stats": {
246247
"completedSplits": 0,
247248
"cpuTimeMillis": 0,

tests/unit/test_dbapi.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from unittest.mock import patch
1515

1616
import httpretty
17-
from httpretty import httprettified
1817
from requests import Session
1918

2019
from tests.unit.oauth_test_utils import (
@@ -58,7 +57,7 @@ def test_http_session_is_defaulted_when_not_specified(mock_client):
5857
assert mock_client.TrinoRequest.http.Session.return_value in request_args
5958

6059

61-
@httprettified
60+
@httpretty.activate
6261
def test_token_retrieved_once_per_auth_instance(sample_post_response_data, sample_get_response_data):
6362
token = str(uuid.uuid4())
6463
challenge_id = str(uuid.uuid4())
@@ -73,13 +72,15 @@ def test_token_retrieved_once_per_auth_instance(sample_post_response_data, sampl
7372
httpretty.register_uri(
7473
method=httpretty.POST,
7574
uri=f"{SERVER_ADDRESS}:8080{constants.URL_STATEMENT_PATH}",
76-
body=post_statement_callback)
75+
body=post_statement_callback
76+
)
7777

7878
# bind get statement for result retrieval
7979
httpretty.register_uri(
8080
method=httpretty.GET,
8181
uri=f"{SERVER_ADDRESS}:8080{constants.URL_STATEMENT_PATH}/20210817_140827_00000_arvdv/1",
82-
body=get_statement_callback)
82+
body=get_statement_callback
83+
)
8384

8485
# bind get token
8586
get_token_callback = GetTokenCallback(token_server, token)
@@ -122,7 +123,7 @@ def test_token_retrieved_once_per_auth_instance(sample_post_response_data, sampl
122123
assert len(_get_token_requests(challenge_id)) == 2
123124

124125

125-
@httprettified
126+
@httpretty.activate
126127
def test_token_retrieved_once_when_authentication_instance_is_shared(sample_post_response_data,
127128
sample_get_response_data):
128129
token = str(uuid.uuid4())
@@ -188,7 +189,7 @@ def test_token_retrieved_once_when_authentication_instance_is_shared(sample_post
188189
assert len(_get_token_requests(challenge_id)) == 1
189190

190191

191-
@httprettified
192+
@httpretty.activate
192193
def test_token_retrieved_once_when_multithreaded(sample_post_response_data, sample_get_response_data):
193194
token = str(uuid.uuid4())
194195
challenge_id = str(uuid.uuid4())

trino/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def _determine_host(url: Optional[str]) -> Any:
395395

396396

397397
class OAuth2Authentication(Authentication):
398-
def __init__(self, redirect_auth_url_handler: CompositeRedirectHandler = CompositeRedirectHandler([
398+
def __init__(self, redirect_auth_url_handler: RedirectHandler = CompositeRedirectHandler([
399399
WebBrowserRedirectHandler(),
400400
ConsoleRedirectHandler()
401401
])):

0 commit comments

Comments
 (0)