mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
initial (failing) version of tests file for CLI, changes to CLI to get it minimally working
This commit is contained in:
parent
8f5232ac73
commit
a57b4484d3
@ -20,6 +20,7 @@ limitations under the License.
|
||||
import os, sys
|
||||
import argparse
|
||||
import doublethink
|
||||
import logging
|
||||
|
||||
def purge_stale_services(argv=None):
|
||||
"""Command-line utility to periodically purge stale entries from the "services" table.
|
||||
@ -32,10 +33,11 @@ def purge_stale_services(argv=None):
|
||||
description='purge-stale-services: utility to periodically purge stale entries from the "services" table.')
|
||||
|
||||
arg_parser.add_argument("-d", "--rethinkdb-db", required=True,
|
||||
dest="database",
|
||||
help="A RethinkDB database containing a 'services' table")
|
||||
|
||||
arg_parser.add_argument("-s", "--rethinkdb-servers",
|
||||
metavar="SERVERS", dest="servers", required=True,
|
||||
metavar="SERVERS", dest="servers", default='localhost',
|
||||
help="rethinkdb servers, e.g. db0.foo.org,db0.foo.org:38015,db1.foo.org")
|
||||
|
||||
arg_parser.add_argument(
|
||||
@ -50,6 +52,6 @@ def purge_stale_services(argv=None):
|
||||
|
||||
args.servers = [srv.strip() for srv in args.servers.split(",")]
|
||||
|
||||
rethinker = doublethink.Rethinker(servers=args.servers, db=args)
|
||||
rethinker = doublethink.Rethinker(servers=args.servers, db=args.database)
|
||||
registry = doublethink.services.ServiceRegistry(rethinker)
|
||||
registry.purge_stale_services()
|
42
tests/test_cli.py
Normal file
42
tests/test_cli.py
Normal file
@ -0,0 +1,42 @@
|
||||
'''
|
||||
test_cli.py - unit tests for doublethink CLI
|
||||
|
||||
Copyright (C) 2015-2017 Internet Archive
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
'''
|
||||
|
||||
import doublethink
|
||||
import logging
|
||||
import sys
|
||||
import pytest
|
||||
import rethinkdb as r
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO,
|
||||
format="%(asctime)s %(process)d %(levelname)s %(threadName)s %(name)s.%(funcName)s(%(filename)s:%(lineno)d) %(message)s")
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def rr():
|
||||
rr = RethinkerForTesting()
|
||||
try:
|
||||
rr.db_drop("doublethink_test_db").run()
|
||||
except r.errors.ReqlOpFailedError:
|
||||
pass
|
||||
result = rr.db_create("doublethink_test_db").run()
|
||||
assert not rr.last_conn.is_open()
|
||||
assert result["dbs_created"] == 1
|
||||
return RethinkerForTesting(db="doublethink_test_db")
|
||||
|
||||
def test_cli(rr):
|
||||
print(rr)
|
||||
doublethink.cli.purge_stale_services(['test'])
|
Loading…
x
Reference in New Issue
Block a user