コード例 #1
0
    def test_find_honors_limit(self):
        query = {'foo': 'bar'}
        documents = [
            (1, {
                'foo': 'bar',
                'baz': 'qux'
            }),  # Will match
            (2, {
                'foo': 'bar',
                'bar': 'baz'
            }),  # Will match
            (2, {
                'foo': 'baz',
                'bar': 'baz'
            }),  # Will not match
            (3, {
                'baz': 'qux'
            }),  # Will not match
        ]

        collection = nosqlite.Collection(Mock(), 'foo', create=False)
        collection.db.execute.return_value = collection.db
        collection.db.fetchall.return_value = documents
        collection._load = lambda id, data: data

        ret = collection.find(query, limit=1)
        assert len(ret) == 1
コード例 #2
0
    def test_rename(self):
        self.collection.create()
        assert self.collection.exists()

        self.collection.rename('bar')
        assert self.collection.name == 'bar'
        assert self.collection.exists()

        assert not nosqlite.Collection(self.db, 'foo', create=False).exists()
コード例 #3
0
 def test_create(self):
     collection = nosqlite.Collection(Mock(), 'foo', create=False)
     collection.create()
     collection.db.execute.assert_any_call("""
         create table if not exists foo (
             id integer primary key autoincrement,
             data text not null
         )
     """)
コード例 #4
0
    def test_rename_raises_for_collision(self):
        nosqlite.Collection(self.db, 'bar')  # Create a collision point
        self.collection.create()

        with raises(AssertionError):
            self.collection.rename('bar')
コード例 #5
0
 def test_clear(self):
     collection = nosqlite.Collection(Mock(), 'foo')
     collection.clear()
     collection.db.execute.assert_any_call('delete from foo')
コード例 #6
0
 def setup(self):
     self.db = sqlite3.connect(':memory:')
     self.collection = nosqlite.Collection(self.db, 'foo', create=False)
コード例 #7
0
def collection(db, request):
    return nosqlite.Collection(db, 'foo', create=False)