コード例 #1
0
def register(request: HttpRequest):
    if request.method == 'POST':
        content_type = request.META.get('CONTENT_TYPE')  # CONTENT_TYPE:application/json
        try:
            if 'json' in content_type:
                payload = simplejson.loads(request.body)
                username = payload['name']
                password = payload['password']
                email = payload['email']
            if 'form-data' in content_type:
                username = request.POST.get('name')
                password = request.POST.get('password')
                email = request.POST.get('email')
        except Exception as e:
            print(e)
            return HttpResponseBadRequest('Error')
        password = tools.pwd_bcrypt(password)
        res = models.User.objects.filter(email=email).first()

        if res:
            return HttpResponseBadRequest('email is exists')
        user = models.User(name=username, password=password, email=email)
        try:
            user.save()
            token = tools.get_token(user.id)
            return JsonResponse({
                'user': user.id,
                'name': user.name,
                'email': user.email,
                'token': token
            })
        except:
            raise
コード例 #2
0
    def test_sellset(self, case):
        # 拼接url
        url = conf.get("env", "fscurl") + case.url
        self.row = case.case_id + 1

        # 获取token
        token = get_token(phone=eval(case.token_data)["phone"],
                          pwd=eval(case.token_data)["code"])

        # headers = {"fsp_token": token}
        headers = {
            "Authorization": case.request_header.replace("#token", token),
            "Content-Type": "application/json;charset=UTF-8",
            "User-Agent":
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
            "Referer":
            "https://fsc-test.manshang.com/app/invoice/ApplyDetail/Apply",
            "Origin": "https://fsc-test.manshang.com",
            "Accept-Encoding": "gzip, deflate, br"
        }

        # 发送请求,请求参数为字典类型
        response = self.request.request(method=case.method,
                                        url=url,
                                        data=eval(case.request_data),
                                        headers=headers)

        # 以下打印内容会显示在html报告中
        print()
        print("请求地址--> {}".format(url))
        print("请求数据--> {}".format(case.request_data))
        print("期望结果--> {}".format(case.expected_data))
        print("服务器响应数据--> {}".format(response.json()))

        res = response.json()

        try:
            self.assertEqual(res, eval(case.expected_data))
        except AssertionError as e:
            result = "FAIL"
            logging.exception(e)
            raise e

        else:
            result = "PASS"
            logging.info("预期结果是:{},实际结果是:{},测试通过".format(
                case.expected_data, res))

        finally:
            self.wb.write_data(self.row, 11, str(res))
            self.wb.write_data(self.row, 12, result)
コード例 #3
0
    def test_isfollow(self, case):
        # 拼接url
        url = conf.get("env", "url") + case.url
        self.row = case.case_id + 1

        # 获取token
        token = get_token(pwd=eval(case.token_data)["code"], phone=eval(case.token_data)["mobilePhone"])

        headers = case.request_header.replace("#token", token)

        # 发送请求前获取是否关注
        isfollow = get_isfollow()

        # 将True和False转换,获取期望结果
        if isfollow:
            case.expected_data = case.expected_data.replace("#isfollow", "False")
コード例 #4
0
ファイル: test_purset.py プロジェクト: yangli1179/api_fsctest
    def test_purset(self, case):
        # 拼接url
        url = conf.get("env", "fscurl") + case.url
        self.row = case.case_id + 1

        # 获取token
        token = get_token(phone=eval(case.token_data)["phone"],
                          pwd=eval(case.token_data)["code"])

        # headers = {"fsp_token": token}
        headers = case.request_header.replace("#token", token)

        case.request_data = case.request_data.replace("#name", rand_name())

        # 发送请求,请求参数为字典类型
        response = self.request.request(method=case.method,
                                        url=url,
                                        data=eval(case.request_data),
                                        headers=eval(headers))

        # 以下打印内容会显示在html报告中
        print()
        print("请求地址--> {}".format(url))
        print("请求数据--> {}".format(case.request_data))
        print("期望结果--> {}".format(case.expected_data))
        print("服务器响应数据--> {}".format(response.json()))

        res = response.json()

        try:
            self.assertEqual(res, eval(case.expected_data))
        except AssertionError as e:
            result = "FAIL"
            logging.exception(e)
            raise e

        else:
            result = "PASS"
            logging.info("预期结果是:{},实际结果是:{},测试通过".format(
                case.expected_data, res))

        finally:
            self.wb.write_data(self.row, 11, str(res))
            self.wb.write_data(self.row, 12, result)
コード例 #5
0
def login(request):
    if request.method == 'GET':
        return render(request, 'login.html')
    if request.method == 'POST':
        try:
            payload = simplejson.loads(request.body)
            email = payload['email']
            user = models.User.objects.get(email=email)
            print(user)
            # 验证密码
            if tools.check_password(payload['password'], user.password):
                return JsonResponse({
                    'user': user.id,
                    'name': user.name,
                    'email': user.email,
                    'token': tools.get_token(user.id)
                })
            else:
                return HttpResponseBadRequest('Error')
        except Exception as e:
            print(e)
            return HttpResponseBadRequest('Error')
コード例 #6
0
def cmdCommand(command):
    if command == 'exit':
        return
    elif command == 'set cookie':
        headers = getContext("headers")
        cookie = input(input_cookie_ask).strip()
        if cookie:
            token = get_token(cookie)
            if token:
                headers['x-csrf-token'] = token
                headers['Cookie'] = cookie
                print(cookie_success)
            else:
                print(cookie_warning)
        else:
            headers['Cookie'] = ''  # 清除cookie
            getHeader()  # 重新获取游客token
            print(cookie_purge_success)
        setContext('headers', headers)
        saveEnv()
    else:
        print(input_warning)
    cmdMode()
コード例 #7
0
def api_my_order_book(login_phone, login_pwd, page, terminal_name, terminal_id,
                      time_start, time_end, type_source, store_name, store_id,
                      order_status):
    """
    data = {"page": 1, "terminalName": "全部终端", "time_start": "2019-11-18 23:59", "time_end": "2019-12-18 23:59",
             "type_source": "weixin", "token": token, "storeName": "全部门店", "status": "", store_id: ""}
    全部门店 不传store_id   storeName 全部门店
    指定门店 storeName 指定门店  传对应门店的store_id
    全部终端 terminalName 全部终端
    指定终端 terminalName 指定终端  terminal 设备前缀:终端id  前缀如下
    扫码王/扫码盒子 sl51:终端id
    收款码 qr_pay:终端id
    POS机 n910:终端id
    倾蜻蜓刷脸设备 qt-f4:终端id
    微收银插件 qwx:终端id
    易锐插件 inspiry:终端id
    支付方式 全部 "" weixin alipay pos auth other
    支付状态 全部 status ""  支付成功1 已退款3

    """

    # url = "https://api.hczypay.com/api/merchant/myOrderBook"
    url = conf.get("env").get("url") + "/api/merchant/billList"

    # 调用登录方法获取
    token = get_token(
        phone=login_phone,
        pwd=login_pwd,
        imei="919dc52afd82279be4f9ff04288be30a9de665ff8fd68b437dbe93953b8e07c9"
    )

    request = HTTPRequest()

    data = {
        "page": page,
        "terminalName": terminal_name,
        "terminal": terminal_id,
        "time_start": time_start,
        "time_end": time_end,
        "type_source": type_source,
        "token": token,
        "storeName": store_name,
        "store_id": store_id,
        "status": order_status
    }

    response = request.request(method="post", url=url, data=data)

    result = response.json()
    logging.info("======================================")
    logging.info("账单筛选请求地址--> {}".format(url))
    logging.info("账单筛选请求参数--> {}".format(data))
    logging.info("账单筛选返回结果--> {}".format(result))
    logging.info("======================================")

    # # 收款人 全部收款人
    # api_merchant_name = res["data"]["inquire"]["merchantName"]
    #
    # # 支付状态 全部
    # api_order_status = res["data"]["inquire"]["orderStatus"]
    #
    # # 门店选择 全部门店
    # api_store_name = res["data"]["inquire"]["storeName"]
    #
    # # 收银终端 全部终端
    # api_terminal_name = res["data"]["inquire"]["terminalName"]
    #
    # # 支付方式 微信
    # api_type_source = res["data"]["inquire"]["typeSource"]
    #
    # # 收款笔数
    # api_success_count = res["data"]["inquire"]["success_count"]
    #
    # # 开始时间 去掉秒钟
    # api_time_start = res["data"]["inquire"]["timeStart"][0:-3]
    #
    # # 结束时间 去掉秒钟
    # api_time_end = res["data"]["inquire"]["timeEnd"][0:-3]
    #
    # # 收款金额
    # api_success_amount = res["data"]["inquire"]["success_amount"]
    #
    # # 退款笔数
    # api_refund_count = res["data"]["inquire"]["refund_count"]
    #
    # # 退款金额
    # api_refund_amount = res["data"]["inquire"]["refund_amount"]

    return result["data"]["inquire"]