Example #1
0
    def test_08_delete_binlog(self):
        db = Database(self._db_name)
        db.binlog(True)
        self.generate_data(db, self._tb_name)
        self.assertEqual(db.tables_all,
                         ['__binlog__', '__metadata__', 'demo1'])
        db.close()

        db = Database(self._db_name)
        db.drop(self._tb_name)
        db.drop('__binlog__')
        self.assertEqual(db.tables_all, ['__metadata__'])
        with self.assertRaises(xTableMissing):
            db.drop('fred')
Example #2
0
    def test_29_with_txn(self):

        db = Database(self._db_name)
        table = db.table(self._tb_name)
        self.generate_data1(db, self._tb_name)
        self.generate_data2(db, self._tb_name)
        with db.begin():
            with self.assertRaises(xIndexMissing):
                next(table.find('123'))
        with db.begin():
            idx = table.index('by_name', '{name}', duplicates=True)
            idx.empty(db.transaction.txn)

        self.generate_data1(db, self._tb_name)
        with db.begin():
            table.drop_index('by_name')
            table.index('by_name', '{name}', duplicates=True)
            docs = list(table.find())
            doc = docs[0]
            table.delete(doc)
            doc = docs[1]
            doc['age'] += 1
            table.save(doc)
            docs = list(table.find())
            doc = docs[0]
            self.assertEqual(doc['age'], 3001)
            all = db.tables_all
            cmp = ['__binlog__', '__metadata__', '_demo1_by_name', 'demo1']
            all.sort()
            cmp.sort()
            self.assertEqual(all, cmp)
            db.binlog(False)
            all = db.tables_all
            all.sort()
            cmp = ['__metadata__', '_demo1_by_name', 'demo1']
            cmp.sort()
            self.assertEqual(all, cmp)
            db.drop('demo1')

        with self.assertRaises(Exception):
            with db.begin():
                raise Exception('catch this')

        self.assertEqual(db.tables_all, ['__metadata__'])
        db.binlog(False)
        db.sync(True)

        db = Database(self._db_name, binlog=False)
        db.binlog()
        db.binlog(False)