接口测试中token的传递方式

import requests
import json
def login():    
    loginUrl = "https://trybindo.com/api/v2/login"
    head = {
                'Accept': 'application/json, text/plain, */*',
                'Accept-Encoding': 'gzip, deflate, br',
                'Accept-Language': 'zh-CN,zh;q=0.9',
                'Connection': 'keep-alive',
                'Content-Length': '139',
                'Content-Type': 'application/json',
                'Host': 'trybindo.com',
                'Origin': 'https://dashboard.trybindo.com',
                'Referer': 'https://dashboard.trybindo.com/login',
                'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
                'X-Application': 'dashboard.trybindo.com'
            }
    body = {
             
                "password":"w111111",
                "username":"paul.wang@bindo.com"
                }
    r = requests.post(loginUrl,json=body,headers=head,verify=False)
    print('================login api :======================== ')
    print(r.status_code)
    print(r.text)
    print(type(r))
    print(r.json()['user']['access_token'])
    print(type(r.json()['user']['access_token']))
    token=r.json()['user']['access_token']
    return token

def getcustomers():
    host='https://trybindo.com'
    url=host+'/api/v2/stores/6889/customers?order_asc=desc&order_by=updated_at&page=1&per_page=25'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    r = requests.get(url,headers=headx)
    print("===============customers api=================")
    print(r.status_code)
    print(r.text) 
    assert r.status_code==200 
    assert 'store_id' in r.text

def getmyinvoice():
    host='https://gateway.trybindo.com'
    url=host+'/v2/order_correspondences?store_ids=6272&order_asc=desc&order_by=updated_at&page=1&per_page=25'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    body={
           'store_ids':'6272',
           'order_asc':'desc',
           'order_by':'updated_at',
           'page':'1',
           'per_page':'25'

    }
    r = requests.get(url,headers=headx,json=body,verify=False)
    print("===============get my invoice id and order number api=================")
    print(r.status_code)
    # print(r.text)
    myOrder=r.json()['order_correspondences'][0]
    print('my order id is: %d' %myOrder['id'])
    print(myOrder['number'])
    print(myOrder)
    # assert r.status_code==200

 
 

def getinvoicecheck():
    # host='https://gateway.trybindo.com'
    url='https://gateway.trybindo.com/v2/stores/6865/invoices/201809261232227763170019/check'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.get(url,headers=headx,verify=False)
    print("===============get test api3=================")
    print(r.status_code)
    print(r.text)

def  getlistingsupplier():
    url='https://trybindo.com/api/v2/stores/7090/listings/25102690/with_suppliers'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    # print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.get(url,headers=headx,verify=False)
    print("===============get test api4=================")
    print(r.status_code)
    print(r.text)

def  getlistingmembers():
    url='https://trybindo.com/api/v2/stores/7090/listings/25102690/with_members'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    # print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.get(url,headers=headx,verify=False)
    print("===============get test api5=================")
    print(r.status_code)
    print(r.text)

def getlistingsearch():
    url='https://trybindo.com/api/v2/listings/search'
    body={"search":{"filter":{"store_id":[7090]},"sort":[{"created_at":"desc"}]},"per_page":25,"page":1}
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    # print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.post(url,headers=headx,json=body,verify=False)
    print("===============get test api6=================")
    print(r.status_code)
    print(r.text)

def  editlisting():
    url='https://trybindo.com/api/v2/stores/7090/listings/25102786'
    body={"listing":{"name":"abc","kitchen_department_id":"","modifier_set_ids":[],"tax_option_ids":[],"product_translations":[],"price_options":[],"custom_field_values":[],"variants":[],"suppliers":[],"serial_numbers":[],"listing_reference_codes":[{"id":'66277',"listing_id":"25102786","code":"11111111111111","created_by_id":'13298',"error":'null'}],"procurement_methods":{"dine_in":'false',"pickup":'false',"delivery":'false',"dine_in_unassigned":'false'},"_product_translation_map":{},"quantity":'0',"modifier_group_ids":[]}}
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    # print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.put(url,headers=headx,json=body,verify=False)
    print("===============get test api7=================")
    print(r.status_code)
    print(r.text)

def deletelisting():
    url='https://trybindo.com/api/v2/stores/7090/listings/25102783'
    headx={}
    headx['X-USER-ACCESS-TOKEN']=login()
    # print(headx['X-USER-ACCESS-TOKEN'])
 
    r = requests.delete(url,headers=headx,verify=False)
    print("===============get test api8=================")
    print(r.status_code)
    print(r.text)


def  main():
      # getcustomers()
      getmyinvoice()
      # getinvoicecheck()
      # getlistingsupplier()
      # getlistingmembers()
      # getlistingsearch()
      # editlisting()
      # deletelisting()

if __name__=='__main__':
    main()
  

 

转载于:https://www.cnblogs.com/paul-wang/p/9851304.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值