

from __future__ import unicode_literals

import os

import pytest

from fossir.web.flask.app import make_app


@pytest.fixture(scope='session')
def app(request):
    """Creates the flask app"""
    config_override = {
        'BASE_URL': 'http://localhost',
        'SMTP_SERVER': ('localhost', 0),  # invalid port - just in case so we NEVER send emails!
        'CACHE_BACKEND': 'null',
        'TEMP_DIR': request.config.fossir_temp_dir.strpath,
        'CACHE_DIR': request.config.fossir_temp_dir.strpath,
        'STORAGE_BACKENDS': {'default': 'mem:'},
        'PLUGINS': request.config.fossir_plugins,
        'ENABLE_ROOMBOOKING': True,
        'SECRET_KEY': os.urandom(16),
        'SMTP_USE_CELERY': False,
    }
    return make_app(set_path=True, testing=True, config_override=config_override)


@pytest.fixture(autouse=True)
def app_context(app):
    """Creates a flask app context"""
    with app.app_context():
        yield app


@pytest.fixture
def request_context(app_context):
    """Creates a flask request context"""
    with app_context.test_request_context():
        yield
