diff --git a/brozzler/cli.py b/brozzler/cli.py index 414ab60..87bfa5d 100644 --- a/brozzler/cli.py +++ b/brozzler/cli.py @@ -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() diff --git a/setup.py b/setup.py index 227bf00..8fad7fa 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tests/test_cli.py b/tests/test_cli.py index 5eec62a..473d16e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 == ''