Ejemplo n.º 1
0
def db_session(make_migrations, request):
    app_cfg = chaps.Container().get_object('config')
    engine = create_engine(app_cfg.DATABASE_URL, poolclass=NullPool)
    connection = engine.connect()
    transaction = connection.begin()
    Session = sessionmaker(bind=connection, autoflush=True)
    session = Session()
    session.begin(subtransactions=True)

    class DbTestSession(DbSession):
        def __init__(self):
            self._session = session

        @property
        def session(self):
            return session

        def __getattr__(self, item):
            return getattr(session, item)

    yield DbTestSession

    # Code below executes only when pytest goes out of scope.
    # Here - when test function ends.
    transaction.rollback()
    connection.close()
Ejemplo n.º 2
0
    def do(self):
        payment = chaps.Container().get_object('payments')
        data = payment.get_payment_data(
            amount=self.payload['amount'],
            description=self.payload['description']
        )

        return {
            'results': payment.build_payment_url(data)
        }
Ejemplo n.º 3
0
def configure_chaps(db_session, push_service_mock_factory):
    chaps.Container._reset()

    chaps.Container.configure({
        'app': HopeIT,
        'db_session': db_session,
        'config': Config,
        'push_service': push_service_mock_factory,
        'payments': lambda x: None
    })
    chaps.Container().register_scope(REQUEST_SCOPE, ThreadScope)
Ejemplo n.º 4
0
def configure_chaps():
    from hopeit.core.database import DbSessionMaker, DbSession

    chaps.Container.configure({
        'app': HopeIT,
        'db_session_maker': DbSessionMaker,
        'db_session': DbSession,
        'config': Config,
        'push_service': fcm_factory,
        'payments': Dotpay,
    })
    chaps.Container().register_scope(REQUEST_SCOPE, RequestScope)
Ejemplo n.º 5
0
 def __call__(self, env, start_response):
     with RequestScope.scope:
         db_session = chaps.Container().get_object('db_session')
         try:
             resp = super().__call__(env, start_response)
         except Exception:
             db_session.close(rollback=True)
             raise
         finally:
             db_session.commit()
             db_session.close()
     return resp
Ejemplo n.º 6
0
def fcm_factory():
    config = chaps.Container().get_object('config')
    return FCMNotification(api_key=config.GOOGLE_API_KEY)
Ejemplo n.º 7
0
from __future__ import with_statement

from logging.config import fileConfig

import chaps
from alembic import context
from sqlalchemy import engine_from_config, pool

from hopeit.core.database import Base

app_cfg = chaps.Container().get_object('config')

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
config.set_main_option('sqlalchemy.url', app_cfg.DATABASE_URL)

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.