improve messaging when brozzler-stop-crawl is passed nonexistent seed/job id

This commit is contained in:
Noah Levitt 2017-04-20 18:04:17 -07:00
parent b3fa7a4e39
commit ba519d7288
3 changed files with 27 additions and 2 deletions

View File

@ -660,6 +660,9 @@ def brozzler_stop_crawl(argv=None):
except ValueError:
job_id = args.job_id
job = brozzler.Job.load(rr, job_id)
if not job:
logging.fatal('job not found with id=%s', repr(job_id))
sys.exit(1)
job.stop_requested = doublethink.utcnow()
job.save()
elif args.site_id:
@ -668,6 +671,9 @@ def brozzler_stop_crawl(argv=None):
except ValueError:
site_id = args.site_id
site = brozzler.Site.load(rr, site_id)
if not site:
logging.fatal('site not found with id=%s', repr(site_id))
sys.exit(1)
site.stop_requested = doublethink.utcnow()
site.save()

View File

@ -32,7 +32,7 @@ def find_package_data(package):
setuptools.setup(
name='brozzler',
version='1.1b11.dev237',
version='1.1b11.dev238',
description='Distributed web crawling with browsers',
url='https://github.com/internetarchive/brozzler',
author='Noah Levitt',

View File

@ -21,6 +21,7 @@ import brozzler.cli
import pkg_resources
import pytest
import subprocess
import doublethink
def cli_commands():
commands = set(pkg_resources.get_entry_map(
@ -36,7 +37,6 @@ def cli_commands():
commands.remove('brozzler-easy')
return commands
@pytest.mark.parametrize('cmd', cli_commands())
def test_call_entrypoint(capsys, cmd):
entrypoint = pkg_resources.get_entry_map(
@ -57,3 +57,22 @@ def test_run_command(capsys, cmd):
brozzler.__version__, cmd)).encode('ascii')
assert err == b''
def test_rethinkdb_up():
'''Check that rethinkdb is up and running.'''
# check that rethinkdb is listening and looks sane
rr = doublethink.Rethinker(db='rethinkdb') # built-in db
tbls = rr.table_list().run()
assert len(tbls) > 10
def test_stop_nonexistent_crawl(capsys):
with pytest.raises(SystemExit):
brozzler.cli.brozzler_stop_crawl(['brozzler-stop-crawl', '--site=123'])
out, err = capsys.readouterr()
assert err.endswith('site not found with id=123\n')
assert out == ''
with pytest.raises(SystemExit):
brozzler.cli.brozzler_stop_crawl(['brozzler-stop-crawl', '--job=abc'])
out, err = capsys.readouterr()
assert err.endswith('''job not found with id='abc'\n''')
assert out == ''