Ejemplo n.º 1
0
 def test012_basicoperand(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     c = d.test
     c.save({'value': 2, 'value2': 150})
     r = c.find_one({'value': {'$gt': 1, '$lte': 2}})
     self.assertTrue(r, msg='BasicOperand failed')
     r = c.find_one({
         'value': {
             '$gt': 1,
             '$lte': 2
         },
         'value2': {
             '$gte': 150,
             '$lt': 2000
         }
     })
     self.assertTrue(r, msg='BasicOperand failed')
     r = c.find_one({
         'value': {
             '$gt': 3,
             '$lte': 2
         },
         'value2': {
             '$gte': 150,
             '$lt': 2000
         }
     })
     self.assertFalse(r, msg='BasicOperand failed')
     if mode == "single":
         d.sync()
Ejemplo n.º 2
0
 def test004_addenreg(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     c = d['test']
     post = {"artist": "Jambon", "music": "I love jambon"}
     c.save(post)
     if mode == "single":
         d.sync()
Ejemplo n.º 3
0
 def test009_removeenreg(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     c = d.test
     r = c.find_one({"artist": "Jambon"})['_id']
     c.remove(r)
     r = c.find_one({"artist": "Jambon"})
     self.assertFalse(r, msg='Enreg not removed')
     d.sync()
     _db = _serializer.load()
Ejemplo n.º 4
0
 def test002_new_collection(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     d.test.save({'key': 'value'})
     self.assertIn('test',
                   d.collection_names(),
                   msg='Collection not created')
     d.sync()
     _db = _serializer.load()
     self.assertFalse(_db['_infos']['total_entries'] > 1,
                      msg='Ids index is not empty')
Ejemplo n.º 5
0
 def test019_renameviacollection(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     c = d.test19
     c.save({'test123': 123})
     c.rename('test19_')
     r = c.find_one({'test123': 123})
     self.assertTrue(r, msg='Save lost after rename')
     self.assertEqual(c.name, 'test19_', msg='Name not valid')
     if mode == "single":
         d.sync()
Ejemplo n.º 6
0
 def test013_alloperand(self):
     d = Database(db_path, mode=mode, serializer=serializer)
     c = d.test
     c.save({'test013': [1, 2, 3]})
     r = c.find_one({'test013': {"$all": [2, 3, 4]}})
     self.assertFalse(r, msg='AllOperand failed')
     r = c.find_one({'test013': {"$all": [2, 3]}})
     self.assertTrue(r, msg='AllOperand failed')
     if mode == "single":
         d.sync()
Ejemplo n.º 7
0
    def test001_newdb(self):
        print('=> %s::%s' % (mode, serializer))
        d = Database(db_path, mode=mode, serializer=serializer)
        d.drop_collection('test')
        d.drop_collection('test2')
        self.assertNotIn('test',
                         d.collection_names(),
                         msg='Database not empty (drop failure)')
        self.assertNotIn('test2',
                         d.collection_names(),
                         msg='Database not empty (drop failure)')
        d.sync()

        _db = _serializer.load()
        self.assertNotIn('test', _db)
        self.assertNotIn('test2', _db)
        self.assertFalse(_db['_infos']['total_entries'] > 0,
                         msg='Ids index is not empty')