Skip to content
Snippets Groups Projects
Commit 77b9346e authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature testing-utils-routes.

parents 61ed86ff 9ef44a54
No related branches found
No related tags found
No related merge requests found
......@@ -26,3 +26,4 @@
derive active router list from junosspace
cache ix public & vpn rr peers
use external logging config file
added utilities for the test environment
......@@ -14,6 +14,10 @@ def create_app():
:return: a new flask app instance
"""
if "SETTINGS_FILENAME" not in os.environ:
assert False, \
"environment variable SETTINGS_FILENAME' must be defined"
app = Flask(__name__)
app.secret_key = "super secret session key"
......@@ -35,9 +39,10 @@ def create_app():
from inventory_provider.routes import poller
app.register_blueprint(poller.routes, url_prefix='/poller')
if "SETTINGS_FILENAME" not in os.environ:
assert False, \
"environment variable SETTINGS_FILENAME' must be defined"
if "ENABLE_TESTING_ROUTES" in os.environ:
from inventory_provider.routes import testing
app.register_blueprint(testing.routes, url_prefix='/testing')
logging.warning('DANGER!!! testing routes enabled')
logging.info("initializing Flask with config from: %r"
% os.environ["SETTINGS_FILENAME"])
......
from flask import Blueprint, Response
from inventory_provider.routes import common
routes = Blueprint("inventory-data-testing-support-routes", __name__)
@routes.route("/flushdb", methods=['GET', 'POST'])
def flushdb():
common.get_redis().flushdb()
return Response('OK')
......@@ -115,6 +115,10 @@ class MockedRedis(object):
k.encode("utf-8") for k in MockedRedis.db.keys()
if k.startswith(m.group(1))])
def flushdb(self):
# only called from testing routes (hopefully)
pass
@pytest.fixture
def data_config():
......@@ -149,6 +153,7 @@ def client(app_config, mocker):
MockedRedis)
os.environ["SETTINGS_FILENAME"] = app_config
os.environ["ENABLE_TESTING_ROUTES"] = "1"
with inventory_provider.create_app().test_client() as c:
yield c
......
def test_flushdb(client):
rv = client.post("/testing/flushdb")
assert rv.status_code == 200
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment