Exemplo n.º 1
0
def test_sqlite_aggregate():
    setupClass(SQLiteFactoryTest)

    if not SQLiteFactoryTest._connection.using_sqlite2:
        pytest.skip("These tests require SQLite v2+")

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            def __init__(self, *args, **kwargs):
                super(MyConnection, self).__init__(*args, **kwargs)
                self.create_aggregate("group_concat", 1, self.group_concat)

            class group_concat:
                def __init__(self):
                    self.acc = []

                def step(self, value):
                    if isinstance(value, string_type):
                        self.acc.append(value)
                    else:
                        self.acc.append(str(value))

                def finalize(self):
                    self.acc.sort()
                    return ", ".join(self.acc)

        return MyConnection

    setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

    SQLiteFactoryTest(name='sqlobject')
    SQLiteFactoryTest(name='sqlbuilder')
    assert SQLiteFactoryTest.select(orderBy="name").\
        accumulateOne("group_concat", "name") == \
        "sqlbuilder, sqlobject"
Exemplo n.º 2
0
def test_sqlite_aggregate():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName == "sqlite":
        if not SQLiteFactoryTest._connection.using_sqlite2:
            return

        def SQLiteConnectionFactory(sqlite):
            class MyConnection(sqlite.Connection):
                def __init__(self, *args, **kwargs):
                    super(MyConnection, self).__init__(*args, **kwargs)
                    self.create_aggregate("group_concat", 1, self.group_concat)

                class group_concat:
                    def __init__(self):
                        self.acc = []
                    def step(self, value):
                        if isinstance(value, basestring):
                            self.acc.append(value)
                        else:
                            self.acc.append(str(value))
                    def finalize(self):
                        self.acc.sort()
                        return ", ".join(self.acc)

            return MyConnection

        setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

        SQLiteFactoryTest(name='sqlobject')
        SQLiteFactoryTest(name='sqlbuilder')
        assert SQLiteFactoryTest.select(orderBy="name").accumulateOne("group_concat", "name") == \
            "sqlbuilder, sqlobject"
Exemplo n.º 3
0
def test_sqlite_factory_str():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName != "sqlite":
        py.test.skip("These tests require SQLite")
    if not SQLiteFactoryTest._connection.using_sqlite2:
        py.test.skip("These tests require SQLite v2+")

    factory = [None]

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            pass

        factory[0] = MyConnection
        return MyConnection

    from sqlobject.sqlite import sqliteconnection
    sqliteconnection.SQLiteConnectionFactory = SQLiteConnectionFactory

    setSQLiteConnectionFactory(SQLiteFactoryTest, "SQLiteConnectionFactory")

    conn = SQLiteFactoryTest._connection.makeConnection()
    assert factory[0]
    assert isinstance(conn, factory[0])
    del sqliteconnection.SQLiteConnectionFactory
Exemplo n.º 4
0
def test_sqlite_factory_str():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName != "sqlite":
        py.test.skip("These tests require SQLite")
    if not SQLiteFactoryTest._connection.using_sqlite2:
        py.test.skip("These tests require SQLite v2+")

    factory = [None]

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            pass

        factory[0] = MyConnection
        return MyConnection

    from sqlobject.sqlite import sqliteconnection

    sqliteconnection.SQLiteConnectionFactory = SQLiteConnectionFactory

    setSQLiteConnectionFactory(SQLiteFactoryTest, "SQLiteConnectionFactory")

    conn = SQLiteFactoryTest._connection.makeConnection()
    assert factory[0]
    assert isinstance(conn, factory[0])
    del sqliteconnection.SQLiteConnectionFactory
Exemplo n.º 5
0
def test_sqlite_factory():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName == "sqlite":
        if not SQLiteFactoryTest._connection.using_sqlite2:
            return

        factory = [None]
        def SQLiteConnectionFactory(sqlite):
            class MyConnection(sqlite.Connection):
                pass
            factory[0] = MyConnection
            return MyConnection

        setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

        conn = SQLiteFactoryTest._connection.makeConnection()
        assert factory[0]
        assert isinstance(conn, factory[0])
Exemplo n.º 6
0
def test_sqlite_factory():
    setupClass(SQLiteFactoryTest)

    if not SQLiteFactoryTest._connection.using_sqlite2:
        pytest.skip("These tests require SQLite v2+")

    factory = [None]

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            pass
        factory[0] = MyConnection
        return MyConnection

    setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

    conn = SQLiteFactoryTest._connection.makeConnection()
    assert factory[0]
    assert isinstance(conn, factory[0])
Exemplo n.º 7
0
def test_sqlite_factory():
    setupClass(SQLiteFactoryTest)

    if not SQLiteFactoryTest._connection.using_sqlite2:
        pytest.skip("These tests require SQLite v2+")

    factory = [None]

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            pass

        factory[0] = MyConnection
        return MyConnection

    setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

    conn = SQLiteFactoryTest._connection.makeConnection()
    assert factory[0]
    assert isinstance(conn, factory[0])
Exemplo n.º 8
0
def test_truediv():
    setupClass(SQLiteTruedivTest)

    if SQLiteTruedivTest._connection.dbName == "sqlite":
        if not SQLiteTruedivTest._connection.using_sqlite2:
            pytest.skip("These tests require SQLite v2+")

        def SQLiteConnectionFactory(sqlite):
            class MyConnection(sqlite.Connection):
                def __init__(self, *args, **kwargs):
                    super(MyConnection, self).__init__(*args, **kwargs)
                    self.create_function("floor", 1, math.floor)
            return MyConnection

        setSQLiteConnectionFactory(SQLiteTruedivTest, SQLiteConnectionFactory)

    SQLiteTruedivTest(value=-5.0)
    assert SQLiteTruedivTest._connection.queryAll(
        SQLiteTruedivTest._connection.sqlrepr(
            Select(SQLiteTruedivTest.q.value // 4)))[0][0] == -2
Exemplo n.º 9
0
def test_truediv():
    setupClass(SQLiteTruedivTest)

    if SQLiteTruedivTest._connection.dbName == "sqlite":
        if not SQLiteTruedivTest._connection.using_sqlite2:
            pytest.skip("These tests require SQLite v2+")

        def SQLiteConnectionFactory(sqlite):
            class MyConnection(sqlite.Connection):
                def __init__(self, *args, **kwargs):
                    super(MyConnection, self).__init__(*args, **kwargs)
                    self.create_function("floor", 1, math.floor)

            return MyConnection

        setSQLiteConnectionFactory(SQLiteTruedivTest, SQLiteConnectionFactory)

    SQLiteTruedivTest(value=-5.0)
    assert SQLiteTruedivTest._connection.queryAll(
        SQLiteTruedivTest._connection.sqlrepr(
            Select(SQLiteTruedivTest.q.value // 4)))[0][0] == -2
Exemplo n.º 10
0
def test_sqlite_factory():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName == "sqlite":
        if not SQLiteFactoryTest._connection.using_sqlite2:
            return

        factory = [None]

        def SQLiteConnectionFactory(sqlite):
            class MyConnection(sqlite.Connection):
                pass

            factory[0] = MyConnection
            return MyConnection

        setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

        conn = SQLiteFactoryTest._connection.makeConnection()
        assert factory[0]
        assert isinstance(conn, factory[0])