def setUpClass(self): """起始方法 #:return: cookies """ redis = MyRedis() env_flag = redis.str_get("uploadFile_env_flag") env_num = redis.str_get("uploadFile_env_num") userName = redis.str_get("username") pwd = redis.str_get("pwd") self.cookies = requests.cookies.RequestsCookieJar() self.cookies.set('env_flag', env_flag) #设置测试环境 self.cookies.set("env_num", env_num) #设置环境号 data = {"userName": userName, "pwd": pwd} self.url = "https://www.yunshuxie.com" + "/v5/web/account/login.htm" caseHeaders = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36", "Accept": "application/json, text/javascript, */*; q=0.01", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Host": "www.yunshuxie.com", "Upgrade-Insecure-Requests": "1" } self.resp = requests.post(self.url, data=data, headers=caseHeaders, cookies=self.cookies) #登录admin测试环境,记录cookies print self.resp.content #logging.info(self.url + lianjiefu + self.resp.text + fengefu) self.cookies.update(self.resp.cookies)
def setUpClass(self): redis = MyRedis() self.env_flag = redis.str_get("wacc_order_env_flag") self.env_num = redis.str_get("wacc_order_env_num") self.phonenum = redis.str_get("make_user_phones") self.session = requests.Session() request_retry = requests.adapters.HTTPAdapter(max_retries=3) self.session.mount("https://", request_retry) self.session.mount("http://", request_retry) header = { "Connection": "keep-alive", "Content-Type": "application/x-www-form-urlencoded", "Cache-Control": "no-cache", "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C92 Safari/601.1 wechatdevtools/1.02.1904090 MicroMessenger/6.7.3 Language/zh_CN webview/15578306374265793 webdebugger port/22562" } self.session.headers = header cookies = {"env_flag": self.env_flag, "env_num": self.env_num} self.session.cookies = requests.utils.cookiejar_from_dict(cookies) self.pattern = "{\"global.*}" self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 globals()["globals_values"] = ""
def setUpClass(self): redis = MyRedis() env_flag = redis.str_get("ysx_crm_env_flag") env_num = redis.str_get("ysx_crm_env_num") self.session = requests.Session() cookies = get_ysx_crm_cookie(env_flag,env_num) header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36","Accept": "application/json, text/javascript, */*; q=0.01","Accept-Encoding": "gzip, deflate, br","Accept-Language": "zh-CN,zh;q=0.9","Connection": "keep-alive","Upgrade-Insecure-Requests": "1"} self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 self.session.headers = header self.session.cookies = cookies
def setUpClass(self): redis = MyRedis() env_flag = redis.str_get("wacc_tortoise_env_flag") env_num = redis.str_get("wacc_tortoise_env_num") self.session = requests.Session() cookies = get_xsjz_cookie(env_flag, env_num) header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json, text/plain, */*", "Connection": "keep-alive" } self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 self.session.headers = header self.session.cookies = cookies
def setUpClass(self): #s = ReadConfig() redis = MyRedis() self.env_flag = redis.str_get("wacc_order_env_flag") self.env_num = redis.str_get("wacc_order_env_num") self.phonenum = redis.str_get("make_user_phones") self.session = requests.Session() request_retry = requests.adapters.HTTPAdapter(max_retries=3) self.session.mount("https://", request_retry) self.session.mount("http://", request_retry) header = {"Connection": "keep-alive","Content-Type": "application/x-www-form-urlencoded","Cache-Control": "no-cache", "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C92 Safari/601.1 wechatdevtools/1.02.1904090 MicroMessenger/6.7.3 Language/zh_CN webview/15578306374265793 webdebugger port/22562"} self.session.headers = header cookies = {"env_flag": self.env_flag, "env_num": self.env_num} self.session.cookies = requests.utils.cookiejar_from_dict(cookies) self.pattern = "{\"global.*}" self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 # self.redis_host = s.get_env("beta").split(":") if self.env_flag == "beta" else s.get_env("prod_stage").split(":") # r = red.Redis(host=self.redis_host[0], port=int(self.redis_host[1]), password="******") # r.set("021ZaJtG17hM310SblvG1NZutG1ZaJtQ",'o38sIv_7FQInsBKJEUExn7wYxoHc&21_bk4dQIEFnYz5w8zJwDqan84UFmV_XVKEO5MJf7fv1pGR8tRH2MAtxpk0Pc1SqDwe5S90CE6TQo1wd346qEA5FQ') globals()["globals_values"] = ""
class ProductType_Test(unittest.TestCase): """销售简章-类目相关协议""" @classmethod def setUpClass(self): self.redis = MyRedis() env_flag = self.redis.str_get("wacc_tortoise_env_flag") env_num = self.redis.str_get("wacc_tortoise_env_num") self.timestamp = "%d" % (time.time()) self.session = requests.Session() cookies = get_wacc_tortoise_cookie(env_flag, env_num) header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json, text/plain, */*", "Connection": "keep-alive" } self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 self.session.headers = header self.session.cookies = cookies def test_01_productType_save(self): """添加类目类目协议-父级节点新增<br/>http://adm.yunshuxie.com/api/productType/save.htm<br/>{"pTitle":"类目测试-pTitle-{timestamp}","pId":"","childTitle":"类目测试-childTitle-{timestamp}"} """ url = r"http://adm.yunshuxie.com" + "/api/productType/save.htm" params = { "pTitle": "类目测试-pTitle-{timestamp}".format(timestamp=self.timestamp), "pId": "", "childTitle": "类目测试-childTitle-{timestamp}".format(timestamp=self.timestamp) } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) self.redis.str_set("pTitle", params["pTitle"]) def test_02_productType_save(self): """添加类目类目协议-父级节点新增-下级类目未空<br/>http://adm.yunshuxie.com/api/productType/save.htm<br/>{"pTitle":"类目测试-pTitle-{timestamp}","pId":"","childTitle":""} """ url = r"http://adm.yunshuxie.com" + "/api/productType/save.htm" params = { "pTitle": "类目测试-pTitle-{timestamp}".format(timestamp=self.timestamp), "pId": "", "childTitle": "" } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_03_productType_save(self): """添加类目类目协议-父级节点非新增-存在下级类目<br/>http://adm.yunshuxie.com/api/productType/save.htm<br/>{"pTitle":"类目测试-pTitle-{timestamp}","pId":"","childTitle":""} """ url = r"http://adm.yunshuxie.com" + "/api/productType/save.htm" params = { "pTitle": "类目测试-pTitle-{timestamp}".format(timestamp=self.timestamp), "pId": "1", "childTitle": "类目测试-childTitle-{timestamp}".format(timestamp=self.timestamp) } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_04_productType_save(self): """添加类目类目协议-pTitle为空<br/>http://adm.yunshuxie.com/api/productType/save.htm<br/>{"pTitle":"","pId":"","childTitle":""} """ url = r"http://adm.yunshuxie.com" + "/api/productType/save.htm" params = { "pTitle": "", "pId": "1", "childTitle": "类目测试-childTitle-{timestamp}".format(timestamp=self.timestamp) } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "1"} if result["code"] == "1" or result["code"] == 1: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_05_productType_getList(self): """获取单条类目首级节点对应信息类目协议"title":"类目测试"<br/>http://adm.yunshuxie.com/api/productType/getList.htm<br/>{"pageIndex":0,"pageSize":1,"title":"类目测试"} """ pTitle = self.redis.str_get("pTitle") url = r"http://adm.yunshuxie.com" + "/api/productType/getList.htm" params = {"pageIndex": 0, "pageSize": 10, "title": pTitle} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) self.redis.str_set("productId", result["data"]["list"][0]["id"]) self.redis.str_set("delete_productId", result["data"]["list"][1]["id"]) def test_06_productType_getList(self): """获取单条类目首级节点对应信息类目协议"title":""<br/>http://adm.yunshuxie.com/api/productType/getList.htm<br/>{"pageIndex":1,"pageSize":2,"title":""} """ url = r"http://adm.yunshuxie.com" + "/api/productType/getList.htm" params = {"pageIndex": 1, "pageSize": 2, "title": ""} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_07_productType_getRow(self): """获取单条类目首级节点对应信息类目协议<br/>http://adm.yunshuxie.com/api/productType/getRow.htm<br/>{"id":} """ productId = self.redis.str_get("productId") url = r"http://adm.yunshuxie.com" + "/api/productType/getRow.htm" params = {"id": productId} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_08_productType_getTreeList(self): """商品类型树形结构类目协议<br/>http://adm.yunshuxie.com/api/productType/getTreeList.htm """ url = r"http://adm.yunshuxie.com" + "/api/productType/getTreeList.htm" self.resp = self.session.post(url=url) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_09_productType_update(self): """获取单条类目首级节点对应信息类目协议"title":""<br/>http://adm.yunshuxie.com/api/productType/update.htm<br/>{"id":112,"title":""} """ productId = self.redis.str_get("productId") url = r"http://adm.yunshuxie.com" + "/api/productType/update.htm" params = {"id": productId, "title": ""} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "1"} if result["code"] == "1" or result["code"] == 1: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_10_productType_update(self): """获取单条类目首级节点对应信息类目协议"title":"类目测试-修改"<br/>http://adm.yunshuxie.com/api/productType/update.htm<br/>{"id": , "title": "类目测试-修改"} """ productId = self.redis.str_get("productId") url = r"http://adm.yunshuxie.com" + "/api/productType/update.htm" params = {"id": productId, "title": "类目测试-修改"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_11_productType_delete(self): """删除类目类目协议<br/>http://adm.yunshuxie.com/api/productType/delete.htm<br/>{"id": } """ productId = self.redis.str_get("productId") url = r"http://adm.yunshuxie.com" + "/api/productType/delete.htm" params = {"id": productId} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) productId = self.redis.str_get("delete_productId") params = {"id": productId} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_12_productType_update(self): """获取单条类目首级节点对应信息类目协议-与商品产生关联<br/>http://adm.yunshuxie.com/api/productType/update.htm<br/>{"id":, "title": "类目测试"} """ productId = self.redis.str_get("productId") def add_spu_save(): """添加spu类目协议<br/>http://adm.yunshuxie.com/api/spu/save.htm<br/>{"type":112,"title":"类目测试商品",<br/>"imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg",<br/>"sellerPoint":"类目测试"","shareInfo":"类目测试","coupon":0,"introduceImgs":"类目测试使用","pcImgs":"类目测试","introduce":"类目测试"} """ url = r"http://adm.yunshuxie.com" + "/api/spu/save.htm" params = { "type": productId, "title": "类目测试商品-title-%s" % (self.timestamp), "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg", "sellerPoint": "类目测试-sellerPoint-%s" % (self.timestamp), "shareInfo": "类目测试-shareInfo-%s" % (self.timestamp), "coupon": 0, "introduceImgs": "类目测试使用-introduceImgs-%s" % (self.timestamp), "pcImgs": "类目测试", "introduce": "类目测试%s" % (self.timestamp), "telPhone": "60000007001" } logging.info( url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) add_spu_save() #创建spu url = r"http://adm.yunshuxie.com" + "/api/productType/update.htm" params = {"id": productId, "title": "类目测试"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_13_productType_delete(self): """删除类目类目协议-商品已关联<br/>http://adm.yunshuxie.com/api/productType/delete.htm<br/>{"id": } """ productId = self.redis.str_get("productId") url = r"http://adm.yunshuxie.com" + "/api/productType/delete.htm" params = {"id": productId} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "10001"} if result["code"] == "10001" or result["code"] == 10001: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) @classmethod def tearDownClass(self): pass
class Smoke_Testing(unittest.TestCase): """销售简章-添加类目相关协议-添加SPU-添加SKU""" @classmethod def setUpClass(self): self.redis = MyRedis() env_flag = self.redis.str_get("wacc_tortoise_env_flag") env_num = self.redis.str_get("wacc_tortoise_env_num") self.timestamp = "%d" % (time.time()) self.session = requests.Session() cookies = get_wacc_tortoise_cookie(env_flag,env_num) header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36","Content-Type":"application/x-www-form-urlencoded","Accept":"application/json, text/plain, */*","Connection":"keep-alive"} self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 self.session.headers = header self.session.cookies = cookies def test_00_productType_getTreeList(self): """商品类型树形结构接口协议<br/>http://adm.yunshuxie.com/api/productType/getTreeList.htm """ url = r"http://adm.yunshuxie.com"+"/api/productType/getTreeList.htm" self.resp = self.session.post(url=url) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_01_productType_save(self): """添加类目接口协议<br/>http://adm.yunshuxie.com/api/productType/save.htm<br/>{"pTitle":"冒烟自动化测试-pTitle-","pId":"","childTitle":"冒烟自动化测试-childTitle-"} """ url = r"http://adm.yunshuxie.com"+"/api/productType/save.htm" params = {"pTitle":"冒烟自动化测试-pTitle-{timestamp}".format(timestamp=self.timestamp), "pId":"","childTitle":"冒烟自动化测试-childTitle-{timestamp}".format(timestamp=self.timestamp)} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) self.redis.str_set("pTitle",params["pTitle"]) def test_02_productType_getList(self): """获取单条类目首级节点对应信息接口协议<br/>title=<br/>http://adm.yunshuxie.com/api/productType/getList.htm<br/>{"pageIndex":1,"pageSize":2,"title":} """ pTitle = self.redis.str_get("pTitle") url = r"http://adm.yunshuxie.com"+"/api/productType/getList.htm" params = {"pageIndex":0,"pageSize":2,"title":pTitle} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) self.redis.str_set("product_id",result["data"]["list"][0]["id"]) def test_03_productType_getRow(self): """获取单条类目首级节点对应信息接口协议<br/>http://adm.yunshuxie.com/api/productType/getRow.htm<br/>{"id":} """ productId = self.redis.str_get("product_id") url = r"http://adm.yunshuxie.com"+"/api/productType/getRow.htm" params = {"id":productId} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_04_productType_update(self): """获取单条类目首级节点对应信息接口协议<br/>http://adm.yunshuxie.com/api/productType/update.htm<br/>{"id":,"title":} """ productId = self.redis.str_get("product_id") pTitle = self.redis.str_get("pTitle") url = r"http://adm.yunshuxie.com"+"/api/productType/update.htm" params = {"id":productId,"title":pTitle} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False,encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_05_spu_save(self): """添加spu接口协议<br/>http://adm.yunshuxie.com/api/spu/save.htm<br/>{"type":,"title":"冒烟自动化测试",<br/>"imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg",<br/>"sellerPoint":"冒烟自动化测试"","shareInfo":"冒烟自动化测试","coupon":0,"introduceImgs":"冒烟自动化测试","pcImgs":"冒烟自动化测试","introduce":"冒烟自动化测试"} """ productId = self.redis.str_get("product_id") url = r"http://adm.yunshuxie.com" + "/api/spu/save.htm" #暂时使用Mock 数据 #url = r"http://uwsgi.sys.bandubanxie.com/mock" + "/api/spu/save.htm" params = {"type": productId, "title": "冒烟自动化测试商品-title-%s" % (self.timestamp), "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg", "sellerPoint": "冒烟自动化测试-sellerPoint-%s" % (self.timestamp), "shareInfo": "冒烟自动化测试-shareInfo-%s" % (self.timestamp), "coupon": 0, "introduceImgs": "冒烟自动化测试-introduceImgs-%s" % (self.timestamp), "pcImgs": "冒烟自动化测试", "introduce": "冒烟自动化测试%s" % (self.timestamp),"auditionIds":"1234","telPhone":"60000007001"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False,encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) self.redis.str_set("spu_title",params["title"]) def test_06_spu_getList(self): """获取spu列表信息接口协议<br/>http://adm.yunshuxie.com/api/spu/getList.htm<br/>{"pageIndex":1,"pageSize":10,"title":""} """ spu_title = self.redis.str_get("spu_title") url = r"http://adm.yunshuxie.com"+"/api/spu/getList.htm" #url = r"http://uwsgi.sys.bandubanxie.com/mock"+"/api/spu/getList.htm" params = {"pageIndex":0,"pageSize":10,"title":spu_title} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False,encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) self.redis.str_set("spu_id",result["data"]["list"][0]["id"]) def test_07_spu_getRow(self): """获取单条spu信息接口协议<br/>http://adm.yunshuxie.com/api/spu/getRow.htm<br/>{"id":}""" url = r"http://adm.yunshuxie.com"+"/api/spu/getRow.htm" spu_id = self.redis.str_get("spu_id") params = {"id":spu_id} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False,encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_08_spu_update(self): """更新spu接口协议<br/>http://adm.yunshuxie.com/api/spu/update.htm<br/>{"id":} """ spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com"+"/api/spu/update.htm" params = {"id":spu_id,"title":"冒烟自动化测试-title-%s"%self.timestamp, "imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "sellerPoint":"冒烟自动化测试-sellerPoint-%s"%self.timestamp, "shareInfo":"冒烟自动化测试-shareInfo-%s"%self.timestamp,"coupon":1, "introduceImgs":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "pcImgs":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "introduce":"冒烟自动化测试-introduce-%s"%self.timestamp,"telPhone":"60000007001"} logging.info(url + lianjiefu + json.dumps(params,ensure_ascii=False,encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url,data=params) print self.resp.text result = json.loads(self.resp.text,encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code":"0"} if result ["code"] == "0" or result["code"] == 0: assert result["code"]==expect["code"],self.msg.format(Expect=expect["code"],Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_09_spu_updateStatus(self): """更新spu状态接口协议<br/>""" spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/updateStatus.htm" params = {"id":spu_id,"status":"1","onlineTime":"","offlineTime":""} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_10_product_attribute_save(self): """添加规格接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/save.htm<br/>{"title":"自动化测试","value":"自动化测试"}""" url = r"http://adm.yunshuxie.com" + "/api/product/attribute/save.htm" params = {"title":"自动化测试-规格-%s"%(self.timestamp),"value":"自动化测试-规格值-%s"%(self.timestamp)} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_11_product_attribute_save(self): """添加规格接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/save.htm<br/>{"title":"冒烟自动化测试","value":"冒烟自动化测试"}""" url = r"http://adm.yunshuxie.com" + "/api/product/attribute/save.htm" params = {"title":"冒烟自动化测试2-规格-%s"%(self.timestamp),"value":"冒烟自动化测试2-规格值-%s"%(self.timestamp)} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_12_product_attribute_getList(self): """规格列表接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/getList.htm<br/>{"pageIndex":"1", "pageSize":"10", "productTypeName":"自动化测试"}""" url = r"http://adm.yunshuxie.com" + "/api/product/attribute/getList.htm" params = {"pageIndex":"1", "pageSize":"10", "productTypeName":"自动化测试-规格-%s"%(self.timestamp)} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) attribute = result["data"]["list"][0]["id"] self.redis.str_set("attribute_id",attribute) params = {"pageIndex": "1", "pageSize": "10", "productTypeName": "冒烟自动化测试2-规格-%s" % (self.timestamp)} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) attribute = result["data"]["list"][0]["id"] self.redis.str_set("attribute_smoke_id",attribute) def test_13_product_attribute_getRow(self): """规格列表接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/getRow.htm<br/>{"title":"自动化测试","value":"自动化测试"}""" attribute_id = self.redis.str_get("attribute_id") url = r"http://adm.yunshuxie.com" + "/api/product/attribute/getRow.htm" params = {"id":attribute_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) attribute = result["data"]["id"] self.redis.str_set("attribute_id",attribute) def test_14_product_attribute_saveAttr(self): """添加子规格值接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/saveAttr.htm<br/>{"title":"子规格值","pId":""}""" attribute_id = self.redis.str_get("attribute_smoke_id") url = r"http://adm.yunshuxie.com" + "/api/product/attribute/saveAttr.htm" params = {"title":"冒烟测试-子规格值-%s"%(self.timestamp),"pId": attribute_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_15_product_attribute_update(self): """修改规格信息接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/update.htm<br/>{"title":"规格名称","pId":""}""" attribute_id = self.redis.str_get("attribute_id") url = r"http://adm.yunshuxie.com" + "/api/product/attribute/update.htm" params = {"title":"规格名称-%s"%(self.timestamp),"id": attribute_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_16_sku_save(self): """添加sku接口协议<br/>http://adm.yunshuxie.com/api/sku/save.htm<br/>{"spuId":"","attributeIds":"123","marketPrice":"999",<br/>"shopPrice":"999","courseIds":"","stocks":""}""" spu_id = self.redis.str_get("spu_id") attribute_id = self.redis.str_get("attribute_id") url = r"http://adm.yunshuxie.com" + "/api/sku/save.htm" params = {"spuId":spu_id,"attributeIds":attribute_id,"marketPrice":"1","shopPrice":"1","courseIds":"1","stocks":"1"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_17_sku_update(self): """更新sku接口协议<br/>http://adm.yunshuxie.com/api/spu/getInfo.htm<br/>{"id":,"spuId":,"marketPrice":"9999999","shopPrice":"9999999","courseIds":"9999999"}""" spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/getInfo.htm" params = {"id":spu_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text logging.info(url + lianjiefu + self.resp.text + fengefu) result = json.loads(self.resp.text, encoding="utf8") sku_id = result["data"]["childList"][0]["id"] self.redis.str_set("sku_id", sku_id) url = r"http://adm.yunshuxie.com" + "/api/sku/update.htm" params = {"id":sku_id,"spuId":spu_id,"marketPrice":"9999999","shopPrice":"9999999","courseIds":"9999999"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text logging.info(url + lianjiefu + self.resp.text + fengefu) result = json.loads(self.resp.text, encoding="utf8") expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_18_stock_update(self): """sku库存增减接口协议-增库存<br/>http://adm.yunshuxie.com/api/sku/save.htm<br/>{"id":, "operateType":"1", "num":"2"}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/stock/update.htm" params = {"id":sku_id, "operateType":"1", "num":"2"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_19_stock_update(self): """sku库存增减接口协议-减库存<br/>http://adm.yunshuxie.com/api/sku/save.htm<br/>{"id": "operateType":"2", "num":"1"}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/stock/update.htm" params = {"id":sku_id, "operateType":"2", "num":"1"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_20_sku_updateStatus(self): """更新sku状态接口协议-下架<br/>http://adm.yunshuxie.com/api/sku/updateStatus.htm<br/>{"id":sku_id,"status":"0",<br/>"onlineTime":"2019-01-01 00:00:01","offlineTime":"2019-01-01 00:00:01"}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/sku/updateStatus.htm" params = {"id":sku_id,"status":"0","onlineTime":"2019-01-01 00:00:01","offlineTime":"2019-01-01 00:00:01"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_21_sku_updateStatus(self): """更新sku状态接口协议-上架<br/>http://adm.yunshuxie.com/api/sku/updateStatus.htm<br/>{"id":sku_id,"status":"1",<br/>"onlineTime":"2019-01-01 00:00:01","offlineTime":"2019-01-01 00:00:01"}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/sku/updateStatus.htm" params = {"id":sku_id,"status":"1","onlineTime":"2019-01-01 00:00:01","offlineTime":"2019-01-01 00:00:01"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_22_sku_updateStatus(self): """更新sku状态接口协议-自动上下架<br/>http://adm.yunshuxie.com/api/sku/updateStatus.htm<br/>{"id":sku_id,"status":"2",<br/>"onlineTime":"2019-01-01 00:00:01","offlineTime":"2019-12-31 00:00:01"}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/sku/updateStatus.htm" params = {"id": sku_id, "status": "2", "onlineTime": "2019-01-01 00:00:01", "offlineTime": "2019-12-31 00:00:01"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_23_sku_saveList(self): """批量添加sku接口协议<br/>http://adm.yunshuxie.com/api/sku/saveList.htm<br/>{"skuList":[{"spuId":"%s","attributeIds":"222",<br/>"marketPrice":"222","shopPrice":"222","courseIds":"222","stocks":"222"},<br/>{"spuId":"%s","attributeIds":"333","marketPrice":"333",<br/>"shopPrice":"333","courseIds":"333","stocks":"333"}]}""" spu_id = self.redis.str_get("spu_id") attribute_id = self.redis.str_get("attribute_id") url = r"http://adm.yunshuxie.com" + "/api/sku/saveList.htm" params = {"skuList":"""[{"spuId":"%s","attributeIds":"%s","marketPrice":"222","shopPrice":"222","courseIds":"222","stocks":"222"},{"spuId":"%s","attributeIds":"%s","marketPrice":"333","shopPrice":"333","courseIds":"333","stocks":"333"}]"""%(spu_id,attribute_id,spu_id,attribute_id)} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_24_sku_updateStatus(self): """新sku状态接口协议-上架<br/>http://adm.yunshuxie.com/api/sku/updateStatus.htm<br/>""" spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/getInfo.htm" params = {"id": spu_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text logging.info(url + lianjiefu + self.resp.text + fengefu) result = json.loads(self.resp.text, encoding="utf8") sku_id = result["data"]["childList"][1]["id"] url = r"http://adm.yunshuxie.com" + "/api/sku/updateStatus.htm" params = {"id": sku_id, "status": "1", "onlineTime": "2019-07-01 00:00:01", "offlineTime": "2019-12-31 00:00:01"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_25_sku_delete(self): """删除单条sku信息接口协议<br/>http://adm.yunshuxie.com/api/sku/delete.htm<br/>{"id": sku_id}""" sku_id = self.redis.str_get("sku_id") url = r"http://adm.yunshuxie.com" + "/api/sku/delete.htm" params = {"id": sku_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_26_course_getList(self): """sku选择课程列表<br/>http://adm.yunshuxie.com/api/course/getList.htm<br/>{"title": "测试"}""" url = r"http://adm.yunshuxie.com" + "/api/course/getList.htm" params = {"title": "测试"} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) def test_27_course_getList(self): """删除规格接口协议<br/>http://adm.yunshuxie.com/api/product/attribute/delete.htm<br/>{"id":""}""" url = r"http://adm.yunshuxie.com" + "/api/product/attribute/delete.htm" attribute_id = self.redis.str_get("attribute_id") params = {"id": attribute_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format(Expect=expect["code"], Really=result["code"]) @classmethod def tearDownClass(self): pass
class StandardProductUnit_Test(unittest.TestCase): """销售简章-SPU相关操作协议""" @classmethod def setUpClass(self): self.redis = MyRedis() env_flag = self.redis.str_get("wacc_tortoise_env_flag") env_num = self.redis.str_get("wacc_tortoise_env_num") self.timestamp = "%d" % (time.time()) self.session = requests.Session() cookies = get_wacc_tortoise_cookie(env_flag, env_num) header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json, text/plain, */*", "Connection": "keep-alive" } self.msg = """\n Expect: {Expect}-*-\n Really: {Really}""" # 校验HTTP返回代码 self.session.headers = header self.session.cookies = cookies def test_01_spu_save(self): """添加spu接口协议<br/>http://adm.yunshuxie.com/api/spu/save.htm<br/>{"type":112,"title":"测试商品",<br/>"imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg",<br/>"sellerPoint":"测试"","shareInfo":"测试","coupon":0,"introduceImgs":"测试使用","pcImgs":"测试","introduce":"测试"} """ url = r"http://adm.yunshuxie.com" + "/api/spu/save.htm" params = { "type": 112, "title": "测试商品-title-%s" % (self.timestamp), "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg", "sellerPoint": "测试-sellerPoint-%s" % (self.timestamp), "shareInfo": "测试-shareInfo-%s" % (self.timestamp), "coupon": 0, "introduceImgs": "测试使用-introduceImgs-%s" % (self.timestamp), "pcImgs": "测试", "introduce": "测试%s" % (self.timestamp), "auditionIds": "1234", "telPhone": "60000007001" } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) self.redis.str_set("spu_id", result["data"]["id"]) def test_02_spu_save(self): """添加spu接口协议-选填项为空<br/>http://adm.yunshuxie.com/api/spu/save.htm<br/>{"type":112,"title":"测试商品",<br/>"imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg",<br/>"sellerPoint":"","shareInfo":"","coupon":0,"introduceImgs":"测试使用","pcImgs":"","introduce":"测试使用-introduceImgs"} """ url = r"http://adm.yunshuxie.com" + "/api/spu/save.htm" params = { "type": 112, "title": "测试商品-title-%s" % (self.timestamp), "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg", "sellerPoint": "", "shareInfo": "", "coupon": 0, "introduceImgs": "测试使用-introduceImgs-%s" % (self.timestamp), "pcImgs": "", "introduce": "测试使用-introduceImgs-%s" % (self.timestamp), "auditionIds": "1234", "telPhone": "60000007001" } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.content + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_03_spu_save(self): """添加SPU接口协议-imgUrls&introduceImgs&pcImgs<br/>http://adm.yunshuxie.com/api/spu/save.htm<br/>{"type":112,"title":"测试商品","imgUrls":"https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg",<br/>"sellerPoint":"测试","shareInfo":"测试","coupon":0,"introduceImgs":"测试使用",<br/>"pcImgs":"测试","introduce":"测试"} """ url = r"http://adm.yunshuxie.com" + "/api/spu/save.htm" params = { "type": 112, "title": "测试商品-title-%s" % (self.timestamp), "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/03/12/19/1552388927736.jpg,https://oss-ysx-pic.yunshuxie.com/agent_c/2018/12/15/00/1544803384770.png", "sellerPoint": "测试-sellerPoint-%s" % (self.timestamp), "shareInfo": "测试-shareInfo-%s" % (self.timestamp), "coupon": 0, "introduceImgs": "测试使用-introduceImgs-%s" % (self.timestamp), "pcImgs": "测试-pcImgs-%s" % (self.timestamp), "introduce": "测试-introduce-%s" % (self.timestamp), "auditionIds": "1234", "telPhone": "60000007001" } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) self.redis.str_set("spu_id", result["data"]["id"]) def test_04_spu_getList(self): """获取spu列表信息接口协议<br/>http://adm.yunshuxie.com/api/spu/getList.htm<br/>{"pageIndex":1,"pageSize":10,"title":""} """ url = r"http://adm.yunshuxie.com" + "/api/spu/getList.htm" params = {"pageIndex": 0, "pageSize": 10, "title": ""} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_05_spu_getRow(self): """获取单条spu信息接口协议<br/>http://adm.yunshuxie.com/api/spu/getRow.htm<br/>{"id":}""" spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/getRow.htm" params = {"id": spu_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_06_spu_update(self): """更新spu接口协议<br/>http://adm.yunshuxie.com/api/spu/update.htm<br/>{"id":} """ spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/update.htm" params = { "id": spu_id, "title": "测试使用-title-%s" % self.timestamp, "imgUrls": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "sellerPoint": "测试-sellerPoint-%s" % self.timestamp, "shareInfo": "测试-shareInfo-%s" % self.timestamp, "coupon": 1, "introduceImgs": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "pcImgs": "https://oss-ysx-pic.yunshuxie.com/agent_c/2019/04/24/21/1556113834007.jpg", "introduce": "测试使用-introduce-%s" % self.timestamp, "telPhone": "60000007001" } logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False, encoding="utf8") + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_07_spu_getInfo(self): """获取单条spu以及相关sku信息接口协议-childList=[]<br/>http://adm.yunshuxie.com/api/spu/getInfo.htm<br/>{"id":} """ spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/getInfo.htm" spu_id = int(spu_id) params = {"id": spu_id} self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_08_spu_getInfo(self): """获取单条spu以及相关sku信息接口协议-存在SKU<br/>http://adm.yunshuxie.com/api/spu/getInfo.htm<br/>{"id":2} """ spu_id = self.redis.str_get("spu_id") def add_sku(): url = r"http://adm.yunshuxie.com" + "/api/sku/save.htm" params = { "spuId": int(spu_id), "attributeIds": "123", "marketPrice": "999", "shopPrice": "999", "courseIds": "111", "stocks": "10" } resp = self.session.post(url=url, params=params) print resp.text add_sku() #创建sku url = r"http://adm.yunshuxie.com" + "/api/spu/getInfo.htm" spu_id = int(spu_id) params = {"id": spu_id} self.resp = self.session.post(url=url, params=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_09_spu_delete(self): """删除单条spu信息接口协议<br/>http://adm.yunshuxie.com/api/spu/delete.htm<br/>{"id":} """ spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/delete.htm" params = {"id": spu_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_10_spu_getInfo(self): """获取单条spu以及相关sku信息接口协议-SPU不存在<br/>http://adm.yunshuxie.com/api/spu/getInfo.htm<br/>{"id":1} """ spu_id = self.redis.str_get("spu_id") url = r"http://adm.yunshuxie.com" + "/api/spu/getInfo.htm" params = {"id": spu_id} logging.info(url + lianjiefu + json.dumps(params, ensure_ascii=False) + fengefu) str_params = json.dumps(params, ensure_ascii=False, encoding="utf8") print str_params self.resp = self.session.post(url=url, data=params) print self.resp.text result = json.loads(self.resp.text, encoding="utf8") logging.info(url + lianjiefu + self.resp.text + fengefu) expect = {"code": "10002"} if result["code"] == "10002" or result["code"] == 10002: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) def test_11_spu_trial_getList(self): """spu选择试听链接<br/>http://adm.yunshuxie.com/api/product/trial/getList.htm""" url = r"http://adm.yunshuxie.com/api/product/trial/getList.htm" self.resp = self.session.post(url=url) print self.resp.text logging.info(url + lianjiefu + self.resp.text + fengefu) result = json.loads(self.resp.text, encoding="utf8") expect = {"code": "0"} if result["code"] == "0" or result["code"] == 0: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) else: assert result["code"] == expect["code"], self.msg.format( Expect=expect["code"], Really=result["code"]) @classmethod def tearDownClass(self): pass