# Path: productporter/app.py
# def create_app(config=None):
#     """
#     Creates the app.
#     """
#     static_url_path = ''
#     instance_path = None
#     if config is None:
#         static_url_path = DefaultConfig.ROOT_URL_PREFIX + '/static'
#         instance_path = DefaultConfig.INSTANCE_PATH
#     else:
#         static_url_path = config.ROOT_URL_PREFIX + '/static'
#         instance_path = config.INSTANCE_PATH
#     # Initialize the app
#     app = Flask("productporter",
#         static_url_path=static_url_path,
#         instance_path=instance_path)
# 
#     # Use the default config and override it afterwards
#     app.config.from_object('productporter.configs.default.DefaultConfig')
#     # Update the config
#     app.config.from_object(config)
# 
#     configure_blueprints(app)
#     configure_extensions(app)
#     configure_template_filters(app)
#     configure_context_processors(app)
#     configure_before_handlers(app)
#     configure_errorhandlers(app)
#     configure_logging(app)
# 
#     return app
# 
# Path: productporter/extensions.py

# 
# Path: productporter/configs/testing.py
# class TestingConfig(Config):
# 
#     # Indicates that it is a testing environment
#     DEBUG = False
#     TESTING = True
# 
#     SERVER_NAME = "localhost:5000"
# 
#     # Get the app root path
#     #            <_basedir>
#     # ../../ -->  productporter/productporter/configs/base.py
#     _basedir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(
#                             os.path.dirname(__file__)))))
# 
#     # a database named productporter.sqlite.
#     #SQLALCHEMY_DATABASE_URI = "mysql://root@localhost"
#     SQLALCHEMY_DATABASE_URI = 'sqlite:///' + _basedir + '/' + \
#                               'productporter.sqlite'
# 
#     # This will print all SQL statements
#     SQLALCHEMY_ECHO = False
# 
#     # Security
#     SECRET_KEY = "SecretKeyForSessionSigning"
#     WTF_CSRF_ENABLED = False
#     WTF_CSRF_SECRET_KEY = "reallyhardtoguess"
# 
# Path: productporter/utils/helper.py
# def create_default_groups():
#     """
#     This will create the 5 default groups
#     """
#     from productporter.fixtures.groups import fixture
#     result = []
#     for key, value in fixture.items():
#         group = Group(name=key)
# 
#         for k, v in value.items():
#             setattr(group, k, v)
# 
#         group.save()
#         result.append(group)
#     return result


import pytest
import os
from productporter import create_app
from productporter.extensions import db
from productporter.configs.testing import TestingConfig as Config
from productporter.utils.helper import create_default_groups
# -*- coding: utf-8 -*-
"""
    productporter unit test
    ~~~~~~~~~~~~~~~~~

    :copyright: (c) 2014 by the ProductPorter Team.
    :license: BSD, see LICENSE for more details.
"""


@pytest.yield_fixture(autouse=True)
def app():
    """application with context."""
    app = create_app(Config)
    ctx = app.app_context()
    ctx.push()
    yield app
    ctx.pop()

@pytest.fixture()
def test_client(app):
    """test client"""
    return app.test_client()

@pytest.yield_fixture()
def database():
    """database setup."""
    db.create_all()  # Maybe use migration instead?
    yield db

# Path: productporter/app.py
# def create_app(config=None):
#     """
#     Creates the app.
#     """
#     static_url_path = ''
#     instance_path = None
#     if config is None:
#         static_url_path = DefaultConfig.ROOT_URL_PREFIX + '/static'
#         instance_path = DefaultConfig.INSTANCE_PATH
#     else:
#         static_url_path = config.ROOT_URL_PREFIX + '/static'
#         instance_path = config.INSTANCE_PATH
#     # Initialize the app
#     app = Flask("productporter",
#         static_url_path=static_url_path,
#         instance_path=instance_path)
# 
#     # Use the default config and override it afterwards
#     app.config.from_object('productporter.configs.default.DefaultConfig')
#     # Update the config
#     app.config.from_object(config)
# 
#     configure_blueprints(app)
#     configure_extensions(app)
#     configure_template_filters(app)
#     configure_context_processors(app)
#     configure_before_handlers(app)
#     configure_errorhandlers(app)
#     configure_logging(app)
# 
#     return app
# 
# Path: productporter/extensions.py

# 
# Path: productporter/configs/testing.py
# class TestingConfig(Config):
# 
#     # Indicates that it is a testing environment
#     DEBUG = False
#     TESTING = True
# 
#     SERVER_NAME = "localhost:5000"
# 
#     # Get the app root path
#     #            <_basedir>
#     # ../../ -->  productporter/productporter/configs/base.py
#     _basedir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(
#                             os.path.dirname(__file__)))))
# 
#     # a database named productporter.sqlite.
#     #SQLALCHEMY_DATABASE_URI = "mysql://root@localhost"
#     SQLALCHEMY_DATABASE_URI = 'sqlite:///' + _basedir + '/' + \
#                               'productporter.sqlite'
# 
#     # This will print all SQL statements
#     SQLALCHEMY_ECHO = False
# 
#     # Security
#     SECRET_KEY = "SecretKeyForSessionSigning"
#     WTF_CSRF_ENABLED = False
#     WTF_CSRF_SECRET_KEY = "reallyhardtoguess"
# 
# Path: productporter/utils/helper.py
# def create_default_groups():
#     """
#     This will create the 5 default groups
#     """
#     from productporter.fixtures.groups import fixture
#     result = []
#     for key, value in fixture.items():
#         group = Group(name=key)
# 
#         for k, v in value.items():
#             setattr(group, k, v)
# 
#         group.save()
#         result.append(group)
#     return result


# Path: tests/fixtures/app.py
import pytest
import os
from productporter import create_app
from productporter.extensions import db
from productporter.configs.testing import TestingConfig as Config
from productporter.utils.helper import create_default_groups

# -*- coding: utf-8 -*-
"""
    productporter unit test
    ~~~~~~~~~~~~~~~~~

    :copyright: (c) 2014 by the ProductPorter Team.
    :license: BSD, see LICENSE for more details.
"""


@pytest.yield_fixture(autouse=True)
def app():
    """application with context."""
    app = create_app(Config)
    ctx = app.app_context()
    ctx.push()
    yield app
    ctx.pop()

@pytest.fixture()
def test_client(app):
    """test client"""
    return app.test_client()

@pytest.yield_fixture()
def database():
    """database setup."""
    db.create_all()  # Maybe use migration instead?
    yield db

    db.drop_all()