Skip to content

Commit

Permalink
test: Add more integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 15, 2024
1 parent 505fede commit 38367ba
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions integration_tests/test_webservice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scrapy

from integration_tests import req


Expand All @@ -9,11 +11,36 @@ def assert_webservice(method, path, expected, **kwargs):
assert json == expected


def test_listjobs():
def test_daemonstatus():
assert_webservice(
"get",
"/listjobs.json",
{"status": "ok", "pending": [], "running": [], "finished": []},
"/daemonstatus.json",
{"status": "ok", "running": 0, "pending": 0, "finished": 0}
)


def test_schedule():
assert_webservice(
"post",
"/schedule.json",
{
"status": "error",
"message": (
f'Scrapy {scrapy.__version__} - no active project\n\n'
'Unknown command: list\n\n'
'Use "scrapy" to see available commands\n'
),
},
data={"project": "nonexistent", "spider": "nospider"},
)


def test_cancel_nonexistent():
assert_webservice(
"post",
"/cancel.json",
{"status": "error", "message": "'nonexistent'"},
data={"project": "nonexistent", "job": "nojob"},
)


Expand All @@ -25,6 +52,48 @@ def test_listprojects():
)


def test_listversions():
assert_webservice(
"get",
"/listversions.json",
{"status": "ok", "versions": []},
params={"project": "sample"},
)


def test_listspiders_nonexistent():
assert_webservice(
"get",
"/listspiders.json",
{
"status": "error",
"message": (
f'Scrapy {scrapy.__version__} - no active project\n\n'
'Unknown command: list\n\n'
'Use "scrapy" to see available commands\n'
),
},
params={"project": "nonexistent"},
)


def test_listjobs():
assert_webservice(
"get",
"/listjobs.json",
{"status": "ok", "pending": [], "running": [], "finished": []},
)


def test_delversion_nonexistent():
assert_webservice(
"post",
"/delversion.json",
{"status": "error", "message": "[Errno 2] No such file or directory: 'eggs/nonexistent/noegg.egg'"},
data={"project": "nonexistent", "version": "noegg"},
)


def test_delproject_nonexistent():
assert_webservice(
"post",
Expand Down

0 comments on commit 38367ba

Please sign in to comment.