Skip to content

Commit

Permalink
feat: scrapyd-client errors if no Scrapy project is found, closes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 11, 2024
1 parent 934480b commit c6a1c3a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changed
- **BREAKING CHANGE:** Move exceptions from ``scrapyd_client.utils`` to ``scrapyd_client.exceptions``.
- **BREAKING CHANGE:** Move ``HEADERS`` from ``scrapyd_client.utils`` to ``scrapyd_client.pyclient``.
- **BREAKING CHANGE:** Merge ``scrapyd_client.commands`` and ``scrapyd_client.cli`` into ``scrapyd_client.__main__``.
- **BREAKING CHANGE:** ``scrapyd-client`` raises an error if no Scrapy project is found, like ``scrapyd-deploy``, instead of assuming a target at ``http://localhost:6800``.
- The ``scrapyd-client schedule`` subcommand accepts multiple ``--arg setting=...`` arguments. (@mxdev88)
- The ``scrapyd_client.ScrapyClient.schedule`` methods accept ``args`` as a list, instead of as a dict.
- The ``scrapyd-deploy --debug`` option prints the subprocess' standard output and standard error, instead of writing to ``stdout`` and ``stderr`` files.
Expand Down
8 changes: 4 additions & 4 deletions scrapyd_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def deploy(args): # noqa: ARG001

def targets(args): # noqa: ARG001
"""List all targets."""
if not inside_project():
print("Error: no Scrapy project found in this location", file=sys.stderr)
sys.exit(1)

for name, target in _get_targets().items():
print("%-20s %s" % (name, target["url"]))

Expand Down Expand Up @@ -154,6 +150,10 @@ def parse_cli_args(args):


def main():
if not inside_project():
print("Error: no Scrapy project found in this location", file=sys.stderr)
sys.exit(1)

max_response_length = 120
try:
args = parse_cli_args(sys.argv[1:])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests


def test_decode_error(mocker, script_runner):
def test_decode_error(mocker, script_runner, project):
mock_response = mocker.Mock()
mock_response.json.side_effect = json.decoder.JSONDecodeError("", "", 0)
mock_get = mocker.patch("scrapyd_client.pyclient.requests.get", autospec=True)
Expand All @@ -14,7 +14,7 @@ def test_decode_error(mocker, script_runner):
assert result.stdout.startswith("Received a malformed response:\n")


def test_projects(mocker, script_runner):
def test_projects(mocker, script_runner, project):
mock_response = mocker.Mock()
mock_response.json.return_value = {
"status": "error",
Expand All @@ -28,7 +28,7 @@ def test_projects(mocker, script_runner):
assert result.stdout == "Scrapyd responded with an error:\nSomething went wrong.\n"


def test_connection_error(mocker, script_runner):
def test_connection_error(mocker, script_runner, project):
mock_get = mocker.patch("scrapyd_client.pyclient.requests.get", autospec=True)
mock_get.side_effect = requests.ConnectionError()
result = script_runner.run(["scrapyd-client", "projects"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_projects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_projects(mocker, script_runner):
def test_projects(mocker, script_runner, project):
projects = ["foo", "bar"]
mock_response = mocker.Mock()
mock_response.json.return_value = {"projects": ["foo", "bar"], "status": "ok"}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schedule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from itertools import chain


def test_schedule(mocker, script_runner):
def test_schedule(mocker, script_runner, project):
get_responses = [
{"projects": ["foo"]},
{"spiders": ["bar"]},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_spiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
response["status"] = "ok"


def test_spiders(mocker, script_runner):
def test_spiders(mocker, script_runner, project):
mock_response = mocker.Mock()
mock_response.json.side_effect = responses
mock_get = mocker.patch("scrapyd_client.pyclient.requests.get", autospec=True)
Expand All @@ -33,7 +33,7 @@ def test_spiders(mocker, script_runner):
)


def test_spiders_verbose(mocker, script_runner):
def test_spiders_verbose(mocker, script_runner, project):
mock_response = mocker.Mock()
mock_response.json.side_effect = responses
mock_get = mocker.patch("scrapyd_client.pyclient.requests.get", autospec=True)
Expand Down

0 comments on commit c6a1c3a

Please sign in to comment.