def login_brand(url, store_id): test_url1 = environmental() '''登录测试环境会员系统''' url = test_url1 + "/api/permission/user/login" data = { "username": "******", "password": "******", "store_id": store_id } header = { 'Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36', 'Content-Type': 'application/json' } r = requests.request("POST", url, data=data, headers=header) result = r.text print(result) assert json.loads(result)["code"] == 1 return json.loads(result)["data"]["token"]
def test_07export(self): """导出""" url = test_url + "/api/admin/activity/export" data = { "store_id": store_id, "operator": "sunny_hong", "token": self.token, "name": "", "act_type": "", "start_time": "", "end_time": "", "lastDate": ["", ""] } r = requests.post(url=url, data=data) result = r.text # print(result) self.assertEqual(json.loads(result)["code"], 1) url2 = environmental() + json.loads(result)["data"]["url"] # print(url2) r2 = requests.get(url=url2) results = r2.text # print(results) if len(results) > 4: print("导出成功")
#coding=utf-8 import requests, json, random from config.config import environmental test_url = environmental() #中奖列表 def search(api_url, store_id, token): # 1.1.获取中奖列表 邮箱 奖品名称 国家 url = test_url + api_url data = { "page_size": 10, "page": 1, "store_id": store_id, "operator": "sunny_hong", "token": token } r = requests.post(url=url, data=data) result = r.text # print(result) # 获取list中邮箱 account = json.loads(result)["data"]["data"] # print(account) list1 = [] list2 = [] list3 = [] for i in account: list1.append(i["account"]) list2.append(i["name"])
#coding=utf-8 import unittest import json,random,requests from public.login_test_brand import login_test_brand from config.config import environmental from public.reader_csv import reader_text store_id = reader_text(r"\data\store_id.txt") # 测试环境地址 test_url = environmental("test") class ActivityList(unittest.TestCase): @classmethod def setUpClass(cls): # 1.登录会员系统获取token cls.token = login_test_brand(store_id) def test_01search(self): """查询""" num = random.randrange(1,7) # print(num) url = test_url+ "/api/admin/activity/product/actProductList" if num == 1: # 1.查询全部 data = {"page_size":10,"page":1,"store_id":store_id,"operator":"sunny_hong","token":self.token} elif num == 2: # 2.活动名称查询 data = {"page_size":10,"page":1,"store_id":store_id,"operator":"sunny_hong","token":self.token,