rusackas commented on code in PR #41250:
URL: https://github.com/apache/superset/pull/41250#discussion_r3444026450
##########
tests/unit_tests/utils/csv_tests.py:
##########
@@ -75,19 +78,19 @@ def test_escape_value():
assert result == "'\rfoo"
-def fake_get_chart_csv_data_none(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_none(chart_url, auth_cookies=None, timeout=None):
Review Comment:
Typed this helper (and the sibling `fake_get_chart_csv_data_*` ones) with
`-> bytes | None`.
##########
tests/unit_tests/utils/csv_tests.py:
##########
@@ -75,19 +78,19 @@ def test_escape_value():
assert result == "'\rfoo"
-def fake_get_chart_csv_data_none(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_none(chart_url, auth_cookies=None, timeout=None):
return None
-def fake_get_chart_csv_data_empty(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_empty(chart_url, auth_cookies=None, timeout=None):
Review Comment:
Annotated this helper too.
##########
tests/unit_tests/utils/csv_tests.py:
##########
@@ -75,19 +78,19 @@ def test_escape_value():
assert result == "'\rfoo"
-def fake_get_chart_csv_data_none(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_none(chart_url, auth_cookies=None, timeout=None):
return None
-def fake_get_chart_csv_data_empty(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_empty(chart_url, auth_cookies=None, timeout=None):
# Return JSON with empty data so that the resulting DataFrame is empty
fake_result = {
"result": [{"data": {}, "coltypes": [], "colnames": [], "indexnames":
[]}]
}
return json.dumps(fake_result).encode("utf-8")
-def fake_get_chart_csv_data_valid(chart_url, auth_cookies=None):
+def fake_get_chart_csv_data_valid(chart_url, auth_cookies=None, timeout=None):
Review Comment:
Typed.
##########
tests/unit_tests/utils/csv_tests.py:
##########
@@ -380,3 +383,35 @@ def test_get_chart_dataframe_preserves_na_string_values(
last_name_values = df[("last_name",)].values
assert last_name_values[0] == "Smith"
assert last_name_values[1] == "NA"
+
+
+def test_get_chart_csv_data_passes_timeout_to_opener(
+ monkeypatch: pytest.MonkeyPatch,
+):
Review Comment:
Added a docstring (and `-> None`) on this test.
##########
tests/unit_tests/utils/csv_tests.py:
##########
@@ -380,3 +383,35 @@ def test_get_chart_dataframe_preserves_na_string_values(
last_name_values = df[("last_name",)].values
assert last_name_values[0] == "Smith"
assert last_name_values[1] == "NA"
+
+
+def test_get_chart_csv_data_passes_timeout_to_opener(
+ monkeypatch: pytest.MonkeyPatch,
+):
+ # Without a timeout the request blocks forever when the webserver is
+ # unreachable, wedging the report schedule in WORKING (issue #40047).
+ mock_response = mock.Mock()
+ mock_response.read.return_value = b"data"
+ mock_response.getcode.return_value = 200
+ mock_opener = mock.Mock()
+ mock_opener.open.return_value = mock_response
+ mock_opener.addheaders = []
+ monkeypatch.setattr(
+ "urllib.request.build_opener", mock.Mock(return_value=mock_opener)
+ )
+
+ get_chart_csv_data("http://dummy-url", auth_cookies={"session": "x"},
timeout=42)
+
+ mock_opener.open.assert_called_once_with("http://dummy-url", timeout=42)
+
+
+def test_get_chart_dataframe_forwards_timeout(monkeypatch: pytest.MonkeyPatch):
+ captured = {}
+
+ def fake(chart_url, auth_cookies=None, timeout=None):
Review Comment:
Typed the nested `fake` helper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]