Improve test coverage

This commit is contained in:
Adrian Chaves 2026-07-31 01:37:40 +02:00
parent c3178ad694
commit 95928a2f26
3 changed files with 22 additions and 0 deletions

View File

@ -38,6 +38,10 @@ class TestFetchCommand:
)
assert out.strip() == "Works"
def test_invalid_url(self) -> None:
code, _, _ = proc("fetch", "not-a-url")
assert code != 0
def test_curl(self, mockserver: MockServer) -> None:
url = mockserver.url("/echo")
_, out, _ = proc("fetch", "--curl", f"curl -d a=1 -H 'X-Test: foo' {url}")

View File

@ -225,6 +225,12 @@ ITEM_PIPELINES = {{'{self.project_name}.pipelines.MyPipeline': 1}}
)
assert "DEBUG: It Works!" in stderr
def test_invalid_url(self, proj_path: Path) -> None:
code, _, _ = proc(
"parse", "--spider", self.spider_name, "not-a-url", cwd=proj_path
)
assert code != 0
def test_curl(self, proj_path: Path, mockserver: MockServer) -> None:
_, _, stderr = proc(
"parse",

View File

@ -52,6 +52,18 @@ class TestShellCommand:
)
assert "('POST', b'a=1')" in out
def test_curl_no_redirect(self, mockserver: MockServer) -> None:
url = mockserver.url("/redirect-no-meta-refresh")
_, out, _ = proc(
"shell",
"--no-redirect",
"--curl",
f"curl {url}",
"-c",
"response.status",
)
assert out.strip().endswith("302")
def test_curl_with_url(self, mockserver: MockServer) -> None:
url = mockserver.url("/echo")
code, _, _ = proc("shell", "--curl", f"curl {url}", url, "-c", "url")