예제 #1
0
class TestDB(object):
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import main_engine
        engine = main_engine()
        # Set up test database
        self.session = InboxSession(engine)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()

    def populate(self):
        """ Populates database with data from the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')
        user = self.config.get('MYSQL_USER')
        password = self.config.get('MYSQL_PASSWORD')
        hostname = self.config.get('MYSQL_HOSTNAME')
        port = self.config.get('MYSQL_PORT')

        cmd = 'mysql {0} -h{1} -P{2} -u{3} -p{4} < {5}'. \
            format(database, hostname, port, user, password, self.dumpfile)
        subprocess.check_call(cmd, shell=True)

    def teardown(self):
        """
        Closes the session. We need to explicitly do this to prevent certain
        tests from hanging. Note that we don't need to actually destroy or
        rolback the database because we create it anew on each test.

        """
        self.session.close()
예제 #2
0
파일: base.py 프로젝트: bsorin/inbox
class TestDB(object):
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import main_engine
        engine = main_engine()
        # Set up test database
        self.session = InboxSession(engine, versioned=False)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()

    def populate(self):
        """ Populates database with data from the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')
        user = self.config.get('MYSQL_USER')
        password = self.config.get('MYSQL_PASSWORD')
        hostname = self.config.get('MYSQL_HOSTNAME')
        port = self.config.get('MYSQL_PORT')

        cmd = 'mysql {0} -h{1} -P{2} -u{3} -p{4} < {5}'. \
            format(database, hostname, port, user, password, self.dumpfile)
        subprocess.check_call(cmd, shell=True)

    def teardown(self):
        """
        Closes the session. We need to explicitly do this to prevent certain
        tests from hanging. Note that we don't need to actually destroy or
        rolback the database because we create it anew on each test.

        """
        self.session.close()
예제 #3
0
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import main_engine
        engine = main_engine()
        # Set up test database
        self.session = InboxSession(engine)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()
예제 #4
0
class TestDB(object):
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import main_engine
        engine = main_engine()
        # Set up test database
        self.session = InboxSession(engine, versioned=False)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()

    def populate(self):
        """ Populates database with data from the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')
        user = self.config.get('MYSQL_USER')
        password = self.config.get('MYSQL_PASSWORD')

        cmd = 'mysql {0} -u{1} -p{2} < {3}'.format(database, user, password,
                                                   self.dumpfile)
        subprocess.check_call(cmd, shell=True)

    def new_session(self, ignore_soft_deletes=True):
        from inbox.models.session import InboxSession
        self.session.close()
        self.session = InboxSession(self.engine,
                                    versioned=False,
                                    ignore_soft_deletes=ignore_soft_deletes)

    def teardown(self):
        """Closes the session. We need to explicitly do this to prevent certain
        tests from hanging. Note that we don't need to actually destroy or
        rolback the database because we create it anew on each test."""
        self.session.close()

    def save(self):
        """ Updates the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')

        cmd = 'mysqldump {0} > {1}'.format(database, self.dumpfile)
        subprocess.check_call(cmd, shell=True)
예제 #5
0
파일: base.py 프로젝트: AmyWeiner/inbox
class TestDB(object):
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import engine
        # Set up test database
        self.session = InboxSession(engine, versioned=False)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()

    def populate(self):
        """ Populates database with data from the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')
        user = self.config.get('MYSQL_USER')
        password = self.config.get('MYSQL_PASSWORD')

        cmd = 'mysql {0} -u{1} -p{2} < {3}'.format(database, user, password,
                                                   self.dumpfile)
        subprocess.check_call(cmd, shell=True)

    def new_session(self, ignore_soft_deletes=True):
        from inbox.models.session import InboxSession
        self.session.close()
        self.session = InboxSession(self.engine,
                                    versioned=False,
                                    ignore_soft_deletes=ignore_soft_deletes)

    def teardown(self):
        """Closes the session. We need to explicitly do this to prevent certain
        tests from hanging. Note that we don't need to actually destroy or
        rolback the database because we create it anew on each test."""
        self.session.close()

    def save(self):
        """ Updates the test dumpfile. """
        database = self.config.get('MYSQL_DATABASE')

        cmd = 'mysqldump {0} > {1}'.format(database, self.dumpfile)
        subprocess.check_call(cmd, shell=True)
예제 #6
0
파일: base.py 프로젝트: AmyWeiner/inbox
    def __init__(self, config, dumpfile):
        from inbox.models.session import InboxSession
        from inbox.ignition import engine
        # Set up test database
        self.session = InboxSession(engine, versioned=False)
        self.engine = engine
        self.config = config
        self.dumpfile = dumpfile

        # Populate with test data
        self.populate()
예제 #7
0
def real_db():
    """A fixture to get access to the real mysql db. We need this
    to log in to providers like gmail to check that events changes
    are synced back."""
    engine = main_engine()
    session = InboxSession(engine)
    yield session
    session.rollback()
    session.close()
예제 #8
0
def start():
    g.db_session = InboxSession(engine)

    g.log = get_logger()
    try:
        g.namespace = g.db_session.query(Namespace) \
            .filter(Namespace.public_id == g.namespace_public_id).one()

        g.encoder = APIEncoder(g.namespace.public_id)
    except NoResultFound:
        return err(404, "Couldn't find namespace with id `{0}` ".format(
            g.namespace_public_id))

    g.parser = reqparse.RequestParser(argument_class=ValidatableArgument)
    g.parser.add_argument('limit', default=DEFAULT_LIMIT, type=limit,
                          location='args')
    g.parser.add_argument('offset', default=0, type=int, location='args')
예제 #9
0
파일: base.py 프로젝트: AmyWeiner/inbox
 def new_session(self, ignore_soft_deletes=True):
     from inbox.models.session import InboxSession
     self.session.close()
     self.session = InboxSession(self.engine,
                                 versioned=False,
                                 ignore_soft_deletes=ignore_soft_deletes)
예제 #10
0
파일: app.py 프로젝트: Inanny/inbox
def start():
    g.db_session = InboxSession(engine, ignore_soft_deletes=False)
예제 #11
0
파일: base.py 프로젝트: htk/sync-engine
def db(dbloader):
    from inbox.models.session import InboxSession
    dbloader.session = InboxSession(dbloader.engine)
    yield dbloader
    dbloader.session.close()
예제 #12
0
 def new_session(self, ignore_soft_deletes=True):
     from inbox.models.session import InboxSession
     self.session.close()
     self.session = InboxSession(self.engine,
                                 versioned=False,
                                 ignore_soft_deletes=ignore_soft_deletes)