From 5db1ed3c2bc2bfcfe8f00bb71f6ce27a6ddfd7e3 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:32:21 -0400 Subject: [PATCH] test: Remove requests timeout --- integration_tests/__init__.py | 4 ++-- integration_tests/test_webservice.py | 3 --- pyproject.toml | 1 + tests/test_endpoints.py | 18 +++++++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/integration_tests/__init__.py b/integration_tests/__init__.py index d4f799e5..0a5b4778 100644 --- a/integration_tests/__init__.py +++ b/integration_tests/__init__.py @@ -7,12 +7,12 @@ def req(method, path, auth=None, status=200, **kwargs): url = urljoin("http://127.0.0.1:6800", path) for badauth in (None, ("baduser", "badpass")): - response = getattr(requests, method)(url, timeout=2, auth=badauth, **kwargs) + response = getattr(requests, method)(url, auth=badauth, **kwargs) assert response.status_code == 401, f"401 != {response.status_code}" assert response.text == "Unauthorized" - response = getattr(requests, method)(url, timeout=2, auth=("hello12345", "67890world"), **kwargs) + response = getattr(requests, method)(url, auth=("hello12345", "67890world"), **kwargs) assert response.status_code == status, f"{status} != {response.status_code}" diff --git a/integration_tests/test_webservice.py b/integration_tests/test_webservice.py index 308a15b5..28da2ba8 100644 --- a/integration_tests/test_webservice.py +++ b/integration_tests/test_webservice.py @@ -38,7 +38,6 @@ def assert_webservice(method, path, expected, **kwargs): def test_options(webservice, method): response = requests.options( f"http://127.0.0.1:6800/{webservice}.json", - timeout=2, auth=("hello12345", "67890world"), ) @@ -62,7 +61,6 @@ def test_options(webservice, method): def test_project_directory_traversal(webservice, method, params): response = getattr(requests, method)( f"http://127.0.0.1:6800/{webservice}.json", - timeout=2, auth=("hello12345", "67890world"), **{"params" if method == "get" else "data": {"project": "../p", **params}}, ) @@ -84,7 +82,6 @@ def test_project_directory_traversal(webservice, method, params): def test_project_directory_traversal_runner(webservice, method, params): response = getattr(requests, method)( f"http://127.0.0.1:6800/{webservice}.json", - timeout=2, auth=("hello12345", "67890world"), **{"params" if method == "get" else "data": {"project": "../p", **params}}, ) diff --git a/pyproject.toml b/pyproject.toml index c59470c7..583ce628 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ builtins-ignorelist = ["copyright"] "{tests,integration_tests}/*" = [ "D", # docstring "S101", # assert + "S113", # requests timeout "PLR2004", # magic value "ARG001", "ARG002", "ARG005", # mocks "PT009", "PT027", # Scrapyd mixes unittest with pytest diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 34299b48..ccb1d100 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -34,7 +34,7 @@ def test_urljoin(self, mock_scrapyd): assert mock_scrapyd.urljoin("foo") == mock_scrapyd.url + "foo" def test_root(self, mock_scrapyd): - resp = requests.get(mock_scrapyd.url, timeout=2) + resp = requests.get(mock_scrapyd.url) assert resp.status_code == 200 assert re.search("To schedule a spider you need to use the API", resp.text) @@ -43,25 +43,25 @@ def test_auth(self): username, password = "Leonardo", "hunter2" with MockScrapydServer(authentication=username + ":" + password) as server: - assert requests.get(server.url, timeout=2).status_code == 401 + assert requests.get(server.url).status_code == 401 - res = requests.get(server.url, timeout=2, auth=(username, password)) + res = requests.get(server.url, auth=(username, password)) assert res.status_code == 200 assert re.search("To schedule a spider", res.text) - res = requests.get(server.url, timeout=2, auth=(username, "trying to hack")) + res = requests.get(server.url, auth=(username, "trying to hack")) assert res.status_code == 401 def test_launch_spider_get(self, mock_scrapyd): - resp = requests.get(mock_scrapyd.urljoin("schedule.json"), timeout=2) + resp = requests.get(mock_scrapyd.urljoin("schedule.json")) assert resp.status_code == 200 assert resp.json()["status"] == "error" def test_spider_list_no_project(self, mock_scrapyd): - resp = requests.get(mock_scrapyd.urljoin("listspiders.json"), timeout=2) + resp = requests.get(mock_scrapyd.urljoin("listspiders.json")) data = resp.json() assert resp.status_code == 200 @@ -69,7 +69,7 @@ def test_spider_list_no_project(self, mock_scrapyd): assert data["message"] == "'project' parameter is required" def test_spider_list_project_no_egg(self, mock_scrapyd): - resp = requests.get(mock_scrapyd.urljoin("listprojects.json"), timeout=2) + resp = requests.get(mock_scrapyd.urljoin("listprojects.json")) data = resp.json() assert resp.status_code == 200 @@ -85,7 +85,7 @@ def test_addversion_and_delversion(self, mock_scrapyd, quotesbot_egg): assert data["project"] == "quotesbot" url = mock_scrapyd.urljoin("delversion.json") - res = requests.post(url, timeout=2, data={"project": "quotesbot", "version": "0.01"}) + res = requests.post(url, data={"project": "quotesbot", "version": "0.01"}) assert res.status_code == 200 assert res.json()["status"] == "ok" @@ -94,7 +94,7 @@ def _deploy(self, mock_scrapyd, quotesbot_egg) -> Response: url = mock_scrapyd.urljoin("addversion.json") data = {b"project": b"quotesbot", b"version": b"0.01"} files = {b"egg": quotesbot_egg} - return requests.post(url, timeout=2, data=data, files=files) + return requests.post(url, data=data, files=files) def test_failed_settings(self, mock_scrapyd, quotesbot_egg_asyncio): response = self._deploy(mock_scrapyd, quotesbot_egg_asyncio)