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 @@ ...@@ -26,3 +26,4 @@
derive active router list from junosspace derive active router list from junosspace
cache ix public & vpn rr peers cache ix public & vpn rr peers
use external logging config file use external logging config file
added utilities for the test environment
...@@ -14,6 +14,10 @@ def create_app(): ...@@ -14,6 +14,10 @@ def create_app():
:return: a new flask app instance :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 = Flask(__name__)
app.secret_key = "super secret session key" app.secret_key = "super secret session key"
...@@ -35,9 +39,10 @@ def create_app(): ...@@ -35,9 +39,10 @@ def create_app():
from inventory_provider.routes import poller from inventory_provider.routes import poller
app.register_blueprint(poller.routes, url_prefix='/poller') app.register_blueprint(poller.routes, url_prefix='/poller')
if "SETTINGS_FILENAME" not in os.environ: if "ENABLE_TESTING_ROUTES" in os.environ:
assert False, \ from inventory_provider.routes import testing
"environment variable SETTINGS_FILENAME' must be defined" app.register_blueprint(testing.routes, url_prefix='/testing')
logging.warning('DANGER!!! testing routes enabled')
logging.info("initializing Flask with config from: %r" logging.info("initializing Flask with config from: %r"
% os.environ["SETTINGS_FILENAME"]) % 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): ...@@ -115,6 +115,10 @@ class MockedRedis(object):
k.encode("utf-8") for k in MockedRedis.db.keys() k.encode("utf-8") for k in MockedRedis.db.keys()
if k.startswith(m.group(1))]) if k.startswith(m.group(1))])
def flushdb(self):
# only called from testing routes (hopefully)
pass
@pytest.fixture @pytest.fixture
def data_config(): def data_config():
...@@ -149,6 +153,7 @@ def client(app_config, mocker): ...@@ -149,6 +153,7 @@ def client(app_config, mocker):
MockedRedis) MockedRedis)
os.environ["SETTINGS_FILENAME"] = app_config os.environ["SETTINGS_FILENAME"] = app_config
os.environ["ENABLE_TESTING_ROUTES"] = "1"
with inventory_provider.create_app().test_client() as c: with inventory_provider.create_app().test_client() as c:
yield 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