From f3459847f14cd059342cd74d6f316da556e6d5a1 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Sat, 16 Jan 2016 10:59:16 +0000 Subject: [PATCH] Move view function into own file, add test --- app/main/__init__.py | 2 +- app/main/views/api_keys.py | 9 +++++++++ app/main/views/index.py | 6 ------ app/templates/main_nav.html | 2 +- tests/app/main/views/test_api_keys.py | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 app/main/views/api_keys.py create mode 100644 tests/app/main/views/test_api_keys.py diff --git a/app/main/__init__.py b/app/main/__init__.py index ff64f5c69..7ce30ff8a 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -5,5 +5,5 @@ main = Blueprint('main', __name__) from app.main.views import ( index, sign_in, sign_out, register, two_factor, verify, sms, add_service, code_not_received, jobs, dashboard, templates, service_settings, forgot_password, - new_password, styleguide, user_profile, choose_service + new_password, styleguide, user_profile, choose_service, api_keys ) diff --git a/app/main/views/api_keys.py b/app/main/views/api_keys.py new file mode 100644 index 000000000..0241346a8 --- /dev/null +++ b/app/main/views/api_keys.py @@ -0,0 +1,9 @@ +from flask import render_template +from flask_login import login_required +from app.main import main + + +@main.route("/services//api-keys") +@login_required +def api_keys(service_id): + return render_template('views/api-keys.html', service_id=service_id) diff --git a/app/main/views/index.py b/app/main/views/index.py index 0dba1e396..81dad8693 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -36,9 +36,3 @@ def checkemail(service_id): @login_required def manageusers(service_id): return render_template('views/manage-users.html', service_id=service_id) - - -@main.route("/services//api-keys") -@login_required -def apikeys(service_id): - return render_template('views/api-keys.html', service_id=service_id) diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index 9594c8596..6cda2b50e 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -9,7 +9,7 @@
  • Templates
    • Manage users
    • diff --git a/tests/app/main/views/test_api_keys.py b/tests/app/main/views/test_api_keys.py new file mode 100644 index 000000000..b32feb64b --- /dev/null +++ b/tests/app/main/views/test_api_keys.py @@ -0,0 +1,14 @@ +from tests.app.main import create_test_user +from flask import url_for + + +def test_should_show_api_keys_and_documentation_page(notifications_admin, + notifications_admin_db, + notify_db_session): + with notifications_admin.test_request_context(): + with notifications_admin.test_client() as client: + user = create_test_user('active') + client.login(user) + response = client.get(url_for('.api_keys', service_id=123)) + + assert response.status_code == 200