Skip to content

Commit

Permalink
test: Increase requests timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 18, 2024
1 parent 413bfe4 commit 09b79c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions integration_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=1, auth=badauth, **kwargs)
response = getattr(requests, method)(url, timeout=2, auth=badauth, **kwargs)

assert response.status_code == 401, f"401 != {response.status_code}"
assert response.text == "Unauthorized"

response = getattr(requests, method)(url, timeout=1, auth=("hello12345", "67890world"), **kwargs)
response = getattr(requests, method)(url, timeout=2, auth=("hello12345", "67890world"), **kwargs)

assert response.status_code == status, f"{status} != {response.status_code}"

Expand Down
6 changes: 3 additions & 3 deletions integration_tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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=1,
timeout=2,
auth=("hello12345", "67890world"),
)

Expand All @@ -62,7 +62,7 @@ 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=1,
timeout=2,
auth=("hello12345", "67890world"),
**{"params" if method == "get" else "data": {"project": "../p", **params}},
)
Expand All @@ -84,7 +84,7 @@ 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=1,
timeout=2,
auth=("hello12345", "67890world"),
**{"params" if method == "get" else "data": {"project": "../p", **params}},
)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=1)
resp = requests.get(mock_scrapyd.url, timeout=2)

assert resp.status_code == 200
assert re.search("To schedule a spider you need to use the API", resp.text)
Expand All @@ -43,33 +43,33 @@ def test_auth(self):
username, password = "Leonardo", "hunter2"

with MockScrapydServer(authentication=username + ":" + password) as server:
assert requests.get(server.url, timeout=1).status_code == 401
assert requests.get(server.url, timeout=2).status_code == 401

res = requests.get(server.url, timeout=1, auth=(username, password))
res = requests.get(server.url, timeout=2, auth=(username, password))

assert res.status_code == 200
assert re.search("To schedule a spider", res.text)

res = requests.get(server.url, timeout=1, auth=(username, "trying to hack"))
res = requests.get(server.url, timeout=2, 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=1)
resp = requests.get(mock_scrapyd.urljoin("schedule.json"), timeout=2)

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=1)
resp = requests.get(mock_scrapyd.urljoin("listspiders.json"), timeout=2)
data = resp.json()

assert resp.status_code == 200
assert data["status"] == "error"
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=1)
resp = requests.get(mock_scrapyd.urljoin("listprojects.json"), timeout=2)
data = resp.json()

assert resp.status_code == 200
Expand All @@ -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=1, data={"project": "quotesbot", "version": "0.01"})
res = requests.post(url, timeout=2, data={"project": "quotesbot", "version": "0.01"})

assert res.status_code == 200
assert res.json()["status"] == "ok"
Expand All @@ -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=1, data=data, files=files)
return requests.post(url, timeout=2, data=data, files=files)

def test_failed_settings(self, mock_scrapyd, quotesbot_egg_asyncio):
response = self._deploy(mock_scrapyd, quotesbot_egg_asyncio)
Expand Down

0 comments on commit 09b79c6

Please sign in to comment.