Beispiel #1
0
def assert_query_count(num, ignore_txn=False):
    qh = QueryLogHandler()
    logger.setLevel(logging.DEBUG)
    logger.addHandler(qh)
    try:
        qc0 = len(qh.queries(ignore_txn=ignore_txn))
        yield qh
    finally:
        logger.removeHandler(qh)
        qc1 = len(qh.queries(ignore_txn=ignore_txn))
        assert (qc1 - qc0) == num
Beispiel #2
0
 def setUp(self):
     self.qh = QueryLogHandler()
     logger.setLevel(logging.DEBUG)
     logger.addHandler(self.qh)
Beispiel #3
0
    ulit = lambda s: codecs.unicode_escape_decode(s)[0]
    binary_construct = buffer
    binary_types = buffer
else:
    ulit = lambda s: s
    binary_construct = lambda s: bytes(s.encode('raw_unicode_escape'))
    binary_types = (bytes, memoryview)

TEST_BACKEND = os.environ.get('PEEWEE_TEST_BACKEND') or 'sqlite'
TEST_DATABASE = os.environ.get('PEEWEE_TEST_DATABASE') or 'peewee_test'
TEST_VERBOSITY = int(os.environ.get('PEEWEE_TEST_VERBOSITY') or 1)

if TEST_VERBOSITY > 1:
    handler = logging.StreamHandler()
    handler.setLevel(logging.ERROR)
    logger.addHandler(handler)


class TestPostgresqlDatabase(PostgresqlDatabase):
    insert_returning = False


class DatabaseInitializer(object):
    def __init__(self, backend, database_name):
        self.backend = self.normalize(backend)
        self.database_name = database_name

    def normalize(self, backend):
        backend = backend.lower().strip()
        mapping = {
            'postgres': ('postgresql', 'pg', 'psycopg2'),
Beispiel #4
0
# -*- coding: utf-8 -*-
try:
    from peewee import logger
    from playhouse.proxy import Proxy
    try:
        from playhouse.gfk import Model
    except ImportError:
        print('[Phial][WARN] playhouse.gfk not found. Generic ForeignKey not supported!')
        from peewee import Model
except ImportError:
    BaseModel = None
    gl_database_type = -1
    gl_database = None
else:
    import logging

    # Inhib peewee log
    logger.addHandler(logging.NullHandler())

    # Database type
    gl_database      = Proxy()
    gl_database_type = -1

    class   BaseModel(Model):
        class       Meta:
            database = gl_database
Beispiel #5
0
 def setUp(self):
     self.qh = QueryLogHandler()
     logger.setLevel(logging.DEBUG)
     logger.addHandler(self.qh)
Beispiel #6
0
    binary_construct = buffer
    binary_types = buffer
else:
    ulit = lambda s: s
    binary_construct = lambda s: bytes(s.encode('raw_unicode_escape'))
    binary_types = (bytes, memoryview)


TEST_BACKEND = os.environ.get('PEEWEE_TEST_BACKEND') or 'sqlite'
TEST_DATABASE = os.environ.get('PEEWEE_TEST_DATABASE') or 'peewee_test'
TEST_VERBOSITY = int(os.environ.get('PEEWEE_TEST_VERBOSITY') or 1)

if TEST_VERBOSITY > 1:
    handler = logging.StreamHandler()
    handler.setLevel(logging.ERROR)
    logger.addHandler(handler)


class DatabaseInitializer(object):
    def __init__(self, backend, database_name):
        self.backend = self.normalize(backend)
        self.database_name = database_name

    def normalize(self, backend):
        backend = backend.lower().strip()
        mapping = {
            'postgres': ('postgresql', 'pg', 'psycopg2'),
            'sqlite': ('sqlite3', 'pysqlite'),
            'berkeleydb': ('bdb', 'berkeley'),
        }
        for key, alias_list in mapping.items():