Exemplo n.º 1
0
    def test_change(self):
        conn = Database.conn
        Database.change(mysql_db)
        assert Database.conn is conn

        Database.config(db=mysql_db)
        Database.execute('insert into user set user.name="test"')
        assert Database.conn_is_up()
        assert Database.conn is not conn
Exemplo n.º 2
0
def channel_set(request, param):
    if request.method == "GET":
        query_filter = {}
        try:
            query_filter['channel'] = request.GET.get('channel', '')
            query_filter['start_time'] = request.GET.get('start_time', '')
            query_filter['end_time'] = request.GET.get('end_time', '')
        except Exception as e:
            raise
        res = A_channel_set.get_list(query_filter)
        print(type(res))
        option = {'is_public': global_conf.is_public,
        }
        res_1 = utils.prepare_table_data(res, option)
        return JsonResponse(res_1 if res_1 else res, safe = False)

    elif request.method == "POST":
        try:
            keys = ['channel', 'parent_id', 'weight', 'remark', 'channel_type', 'is_public']
            par = utils.get_post_parameter(request, keys)
            par['admin'] = request.user.username
            par['status'] = 1
        except Exception as e:
            print(traceback.format_exc())
            return JsonResponse({"status": 1, "message":"参数错误"})
        a_channel_set = A_channel_set()
        a_channel_set = utils.model_set(a_channel_set, par)
        try:
            a_channel_set.save()
        except Exception as e:
            return JsonResponse({"status": 1, "message":"渠道名相同"})
        return JsonResponse({"status": 0, "message":"添加成功"})
    elif request.method == "PUT":
        id = int(param)
        try:
            keys = ['channel', 'parent_id', 'weight', 'remark', 'channel_type', 'is_public']
            par = utils.get_post_parameter(request, keys)
            par['admin'] = request.user.username
        except Exception as e:
            print(traceback.format_exc())
            return JsonResponse({"status": 1, "message":"参数错误"})
        a_channel_set = A_channel_set.where(id=id).select().execute.one()
        a_channel_set = utils.model_set(a_channel_set, par)
        try:
            a_channel_set.save()
        except Exception as e:
            return JsonResponse({"status": 1, "message":"渠道名相同"})
        return JsonResponse({"status": 0, "message":"编辑成功"})
    elif request.method == "DELETE":
        id = int(param)
        sql = "UPDATE a_channel_set SET status = 0 WHERE id = %s" % (id)
        Database.execute(sql)
        return JsonResponse({"status": 0, "message":"删除成功"})
Exemplo n.º 3
0
 def test_execute(self):
     cursor = Database.execute('insert into user set user.name="test"')
     assert cursor