def test_CORS(): from cortical_voluba import create_app app = create_app({'TESTING': True, 'CORS_ORIGINS': None}) with app.test_client() as client: response = client.get('/') assert 'Access-Control-Allow-Origin' not in response.headers app = create_app({'TESTING': True, 'CORS_ORIGINS': '*'}) with app.test_client() as client: response = client.get('/') assert 'Access-Control-Allow-Origin' in response.headers assert response.headers['Access-Control-Allow-Origin'] == '*' app = create_app({'TESTING': True, 'CORS_ORIGINS': '*'}) with app.test_client() as client: response = client.options('/', headers={ 'Origin': 'https://h.test', 'Access-Control-Request-Method': 'GET', }) assert 'Access-Control-Allow-Origin' in response.headers assert 'Access-Control-Max-Age' in response.headers app = create_app({'TESTING': True, 'CORS_ORIGINS': '*', 'CORS_MAX_AGE': datetime.timedelta(seconds=42)}) with app.test_client() as client: response = client.options('/', headers={ 'Origin': 'https://h.test', 'Access-Control-Request-Method': 'GET', }) assert 'Access-Control-Max-Age' in response.headers assert response.headers['Access-Control-Max-Age'] == '42'
def test_echo_route(): from cortical_voluba import create_app app = create_app({'TESTING': True, 'ENABLE_ECHO': False}) with app.test_client() as client: response = client.get('/echo') assert response.status_code == 404 app = create_app({'TESTING': True, 'ENABLE_ECHO': True}) with app.test_client() as client: response = client.get('/echo') assert response.status_code == 200
def test_proxy_fix(): app = cortical_voluba.create_app(test_config={ 'TESTING': True, 'PROXY_FIX': { 'x_for': 1, 'x_proto': 1, 'x_host': 1, 'x_port': 1, 'x_prefix': 1, }, }) called = False @app.route('/test') def test(): nonlocal called from flask import request assert request.url == 'https://h.test:1234/toto/test' assert request.access_route[0] == '1.2.3.4' called = True return '' client = app.test_client() client.get('/test', headers={ 'X-Forwarded-For': '1.2.3.4', 'X-Forwarded-Proto': 'https', 'X-Forwarded-Host': 'h.test', 'X-Forwarded-Port': '1234', 'X-Forwarded-Prefix': '/toto', }) assert called
def flask_app(): app = cortical_voluba.create_app( test_config={ 'TESTING': True, 'CELERY_BROKER_URL': 'disabled://', 'CELERY_RESULT_BACKEND': 'disabled://', }) return app
def test_config(): assert not cortical_voluba.create_app().testing assert cortical_voluba.create_app(test_config={'TESTING': True}).testing
def test_openapi_spec_development_mode(): from cortical_voluba import create_app app = create_app({'TESTING': True, 'ENV': 'development'}) with app.test_client() as client: response = client.get('/openapi.json') assert response.json['servers'][0]['url'] == '/'
# Copyright 2019 CEA # Author: Yann Leprince <*****@*****.**> # # This file is part of cortical-voluba. # # cortical-voluba is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # cortical-voluba is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License # for more details. # # You should have received a copy of the GNU Affero General Public License # along with cortical-voluba. If not, see <https://www.gnu.org/licenses/>. """Module containing a Flask application singleton for use by a WSGI server.""" import cortical_voluba application = cortical_voluba.create_app()