def test_id_operations(self):
        db = DBOp()
        table = db.unit_test
        table.remove()

        _id1 = db.new_id(table)
        self.assertTrue(_id1 is not None)
        self.assertTrue(isinstance(_id1, str))
        print 'new generated id: %s' % _id1

        _id2 = db.save(table, _id1, {'data': 'test data'})
        self.assertTrue(_id2 is not None)
        self.assertTrue(isinstance(_id2, str))
        print 'new updated id: %s' % _id2

        self.assertEqual(db.load(table, _id1)['data'], 'test data')

        _id3 = db.delete(table, _id1)
        self.assertTrue(_id3 is not None)
        print 'deleted id: %s' % _id3

        try:
            db.load(table, _id1)
            self.assertFalse('unreachable for exception')
        except Exception, e:
            self.assertIn('''Couldn't load''', e.message)
            self.assertIn('''it doesn't exist or deleted''', e.message)
Beispiel #2
0
                return ''
            elif action == 'get_all_activity':
                data = db.get_all_activity()
                return data_template(data)

            elif action == 'get_all_picture_info':
                data = db.get_all_picture_info()
                return data_template(data)
            else:
                return result_template('''Illegal parameters: "action=%s"''' % action)
        except Exception, e:
            web.debug(str(e))
            set_status_code(web, 500)
            return exception_template(e)
            """


if __name__ == '__main__':
    db = DBOp()
    urls = (
        '/login', 'Login',
        '/newid', 'NewId',
        '/saveid', 'SaveId',
        '/loadid', 'LoadId',
        '/db', 'DB',
    )
    db.set_web(web)
    app = web.application(urls, globals())
    app.run()
#    db.remove_user_message('5456478e1ef08c418fc9f726', ['{"action":"invite","type":"activity","activity_name":"war3 2v2","from":{"imgUrl":"","sex":"male","name":"kimi"}}'])
    def test_queue_operations(self):
        db = DBOp()
        table = db.unit_test
        table.remove()

        _id1 = db.new_id(table)
        _id2 = db.new_id(table)
        _id3 = db.new_id(table)

        db.push(table, _id1, 'notify', 'a')
        db.push(table, _id1, 'notify', 'b')
        db.push(table, _id1, 'notify', ['c', 'd'])
        db.push(table, [_id1, _id2, _id3], 'notify', ['a', 'e'])

        data = db.load(table, _id1, fields={'_id': False, 'notify': True})
        print data
        self.assertEqual(data['notify'], ['a', 'b', 'c', 'd', 'e'])

        db.pop(table, _id1, 'notify', ['a', 'b'])
        db.pop(table, _id1, 'notify', 'c')

        data = db.load(table, _id1, fields={'_id': False, 'notify': True})
        self.assertEqual(data['notify'], ['d', 'e'])

        db.pop(table, [_id1, _id2, _id3], 'notify', 'e')

        data = db.load(table, _id1, fields={'_id': False, 'notify': True})
        self.assertEqual(data['notify'], ['d'])
        data = db.load(table, _id2, fields={'_id': False, 'notify': True})
        self.assertEqual(data['notify'], ['a'])
        data = db.load(table, _id3, fields={'_id': False, 'notify': True})
        self.assertEqual(data['notify'], ['a'])

        db.close()