Example #1
0
def app():
    config_path = get_config_file_path()
    config = load_config(config_path)
    app = server.get_app(config)
    app.config["TESTING"] = True
    app.config["WTF_CSRF_ENABLED"] = False
    return app
Example #2
0
def geonature_app():
    """ set the application context """
    config_path = get_config_file_path()
    config = load_config(config_path)
    app = server.get_app(config)
    ctx = app.app_context()
    ctx.push()
    yield app
    ctx.pop()
Example #3
0
def execute_script(file_name):
    """ 
        Execute a script to set or delete sample data before test
    """
    config_path = get_config_file_path()
    config = load_config(config_path)
    conn = psycopg2.connect(config["SQLALCHEMY_DATABASE_URI"])
    cur = conn.cursor()
    sql_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), file_name)
    cur.execute(open(sql_file, "r").read())
    conn.commit()
    cur.close()
    conn.close()
Example #4
0
def pytest_sessionstart(session):
    """ before session.main() is called. """
    config_path = get_config_file_path()
    config = load_config(config_path)
    app = server.get_app(config)
    app.config['TESTING'] = True
    # push the app_context
    ctx = app.app_context()
    ctx.push()
    
    # setup test data
    execute_script('delete_sample_data.sql')
    execute_script('sample_data.sql')
Example #5
0
def execute_script(file_name):
    """ 
        Execute a script to set or delete sample data before test
    """
    config_path = get_config_file_path()
    config = load_config(config_path)
    conn = psycopg2.connect(config['SQLALCHEMY_DATABASE_URI'])
    cur = conn.cursor()
    sql_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), file_name)
    cur.execute(open(sql_file, 'r').read())
    conn.commit()
    cur.close()
    conn.close()
Example #6
0
def pytest_sessionstart(session):
    """ before session.main() is called. """
    config_path = get_config_file_path()
    config = load_config(config_path)
    app = server.get_app(config)
    app.config["TESTING"] = True
    # push the app_context
    ctx = app.app_context()
    ctx.push()
    logging.disable(logging.DEBUG)

    # setup test data
    execute_script("delete_sample_data.sql")
    execute_script("sample_data.sql")
Example #7
0
def frontend_routes_templating(app=None):
    if not app:
        app = get_app_for_cmd(with_external_mods=False)

    log.info("Generating frontend routing")
    # recuperation de la configuration
    configs_gn = load_config(get_config_file_path())

    from geonature.utils.env import list_frontend_enabled_modules

    with open(
            str(ROOT_DIR /
                "frontend/src/app/routing/app-routing.module.ts.sample"),
            "r") as input_file:
        template = Template(input_file.read())
        routes = []
        for url_path, module_code in list_frontend_enabled_modules(app):
            location = Path(GN_EXTERNAL_MODULE / module_code.lower())

            # test if module have frontend
            if (location / "frontend").is_dir():
                path = url_path.lstrip("/")
                location = "{}/{}#GeonatureModule".format(
                    location, GN_MODULE_FE_FILE)
                routes.append({
                    "path": path,
                    "location": location,
                    "module_code": module_code
                })

            # TODO test if two modules with the same name is okay for Angular

        route_template = template.render(
            routes=routes,
            enable_user_management=configs_gn["ACCOUNT_MANAGEMENT"].get(
                "ENABLE_USER_MANAGEMENT"),
            enable_sign_up=configs_gn["ACCOUNT_MANAGEMENT"].get(
                "ENABLE_SIGN_UP"),
        )

        with open(
                str(ROOT_DIR /
                    "frontend/src/app/routing/app-routing.module.ts"),
                "w") as output_file:
            output_file.write(route_template)

    log.info("...%s\n", MSG_OK)
Example #8
0
"""
    Give a unique entry point for gunicorn
"""

from geonature.utils.env import load_config, get_config_file_path
from server import get_app

# get the app config file
config_path = get_config_file_path()
config = load_config(config_path)

#give the app context from server.py in a app object
app = get_app(config)
Example #9
0
import json
from flask import url_for
from cookies import Cookie
import pytest

import server
from geonature.utils.env import load_config, get_config_file_path

# TODO: fixture pour mettre des données test dans la base a chaque test
# https://github.com/pytest-dev/pytest-flask/issues/70

CONF_PATH = get_config_file_path()
APP_CONF = load_config(CONF_PATH)
APP_ID = APP_CONF.get('ID_APPLICATION_GEONATURE')


@pytest.fixture
def app():
    app = server.get_app(APP_CONF)
    app.config['TESTING'] = True
    return app


def post_json(client, url, json_dict):
    """Send dictionary json_dict as a json to the specified url """
    return client.post(url,
                       data=json.dumps(json_dict),
                       content_type='application/json')


def json_of_response(response):
Example #10
0
def app():
    config_path = get_config_file_path()
    config = load_config(config_path)
    app = server.get_app(config)
    app.config['TESTING'] = True
    return app