def test_api_specialcms(self): ''' 测试调用内置api文章 :return: ''' ts = TestApiSpecialcms #when url, data, method, expected = ts.urls[0], ts.datas[0], ts.methods[ 0], ts.expected[0] #then res = ConfigHttp(url=url, params=data, method=method).request() self.mylog.debug("-----test_api_specialcms----响应结果为{}".format( res.text)) # reg = re.findall(r'\"single_article_title\":\".*?(?=,)\"',date) # date = res["result"[2][reg]] # print(reg) pattern = re.compile(r"\"single_article_title\":\"(.+?)\"") # single_article_title_list = pattern.findall(res.text) # 列表 # #then # self.assertEqual("success",res["status"],"信息调用失败") self.mylog.debug("-----tsingle_article_title_list----响应结果为{}".format( single_article_title_list)) self.assertListEqual(single_article_title_list, expected)
def test_1(self): method = TestConnCase.methods[0] content = ConfigHttp(method=method, url="").request().json() self.log.debug("连接响应数据 ==={}".format(content)) self.assertEqual("success", content["status"], "连接测试不通过")
def test_job_login(self): url,data,method = TestApijobLogin.urls[0],TestApijobLogin.datas[0],TestApijobLogin.methods[0] res = ConfigHttp(url=url,data=data,method=method).request().json() self.mylog.debug("---test_job_login---,响应结果为{}".format(res)) self.assertEqual("success",res["status"],"登录失败") self.assertFalse(0)
def test_get_token(self): url, data, method = TestApispecialGoods.urls[ 0], TestApispecialGoods.datas[0], TestApispecialGoods.methods[0] res = ConfigHttp(url=url, data=data, method=method).request().json() self.assertEqual("success", res["status"], "登录失败") global token token = res["result"]["user_token"]
def test_api_addgoodsask(self): url, data, method, expected = TestAddgoodsask.urls[ 0], TestAddgoodsask.datas[0], TestAddgoodsask.methods[ 0], TestAddgoodsask.expecteds[0] res = ConfigHttp(url=url, data=data, method=method).request().json() self.mylog.debug("----test_api_addgoodsask----,响应结果{}".format(res)) self.assertEqual(["添加商品咨询成功!"], expected)
def test_api_statistics(self): url, data, method = self.dal.urls[1], self.dal.datas[ 1], self.dal.methods[1] global token data.update({"user_token": token}) # when res = ConfigHttp(url=url, data=data, method=method).request().json() self.mylog.debug("test_api_statistics---------响应结果{}".format(res)) self.assertEqual(6, res["result"][0]["favorites_num"], "失败")
def dbshop_login(user_name, user_password, user_unionid): # given url, data, method = TestApiLogin.urls[0], TestApiLogin.datas[ 0], TestApiLogin.methods[0], data.update({ 'user_name': user_name, 'user_password': user_password, 'user_unionid': user_unionid }) # when return ConfigHttp(url=url, data=data, method=method).request().json()
def test_api_inlay_ad(self, ): ''' 正向用例 :return: ''' # given url, method, data = TestApiSpecialad.urls[0], TestApiSpecialad.methods[ 0], TestApiSpecialad.datas[0] # when res = ConfigHttp(method=method, url=url, params=data).request().json() self.log.debug("test_api_inlay_ad 响应结果=={}".format(res)) # then self.assertEqual("success", res['status'], "内置广告调用标记失败")
def test_api_goodsinfo(self,): url,data,method = TestApigoodsInfo.urls[0],TestApigoodsInfo.datas[0],TestApigoodsInfo.methods[0] res = ConfigHttp(url=url,data=data,method=method).request() self.mylog.debug("----test_api_goodsinfo----,响应结果为{}".format(res.text)) pattern = re.compile(r"\"goods_name\":\"(.+?)\"") goods_name_list = pattern.findall(res.text) self.mylog.debug("----goods_name_list----,响应结果为{}".format(goods_name_list)) self.assertListEqual(goods_name_list,['皮卡皮卡皮'])
def test_api_inlay_ad(self, ad_code): ''' 正向用例 :return: ''' # given url, method, data = TestApiSpecialad.urls[0], TestApiSpecialad.methods[ 0], TestApiSpecialad.datas[0] data.update({"ad_code": ad_code}) # when res = ConfigHttp(method=method, url=url, params=data).request().json() #self.log.debug("test_api_text_ad 响应结果=={}".format(res)) # then self.assertEqual(ad_code, res["result"]['dbapi_ad_code'], "文字广告调用标记失败")
def test_api_statistics(self, user_name, user_password, user_unionid): res = dbshop_login(user_name, user_password, user_unionid) # out global token token = res["result"]["user_token"] # url, data, method = TestApiStatistics.urls[1], TestApiStatistics.datas[ 1], TestApiStatistics.methods[1] data.update({"user_token": token}) # when res = ConfigHttp(url=url, data=data, method=method).request().json() self.assertEqual(6, res["result"][0]["favorites_num"], " 失败")
def test_db_api_goodsClass(self): ''' 商品分类 :return: ''' url, data, method = TestApigoodsClass.urls[0], TestApigoodsClass.datas[ 0], TestApigoodsClass.methods[0] res = ConfigHttp(url=url, params=data, method=method).request() self.mylog.debug("----test_db_api_goodsClass---,响应结果为{}".format(res)) pattern = re.compile(r"\"class_name\":\"(.+?)\"") class_name_list = pattern.findall(res.text) self.assertListEqual(class_name_list, ['家用电器'])
def test_api_orderlist(self): user_name, user_password, user_unionid = TestApiLogin.datas[0][ "user_name"], TestApiLogin.datas[0][ "user_password"], TestApiLogin.datas[0]["user_unionid"] login_res = dbshop_login(user_name, user_password, user_unionid) token = login_res["result"]["user_token"] url, data, method, expected = TestApiOrderlist.urls[ 0], TestApiOrderlist.datas[0], TestApiOrderlist.methods[ 0], TestApiOrderlist.expecteds[0] data.update({"user_token": token}) res = ConfigHttp(url=url, params=data, method=method).request().json() self.mylog.debug("---test_api_orderlist----,响应结果为{}".format(res)) self.assertEqual(res['status'], expected)
def test_db_api_specialgoods(self): url, data, method = TestApispecialGoods.urls[ 1], TestApispecialGoods.datas[1], TestApispecialGoods.methods[1] global token data.update({"user_token": token}) res = ConfigHttp(url=url, params=data, method=method).request() self.mylog.debug( "------test_db_api_specialgoods----,响应结果{}".format(res)) pattern = re.compile(r"\"goods_id\":\"(.+?)\"") goods_id_list = pattern.findall(res.text) self.mylog.debug("---goods_id_list-----,响应结果为{}".format(goods_id_list)) self.assertListEqual(goods_id_list, ["7", "2"])
def test_apijob_addgoodsask(self, user_name, user_password, user_unionid, goods_ask_content, goods_id): login_res = dbshop_login(user_name, user_password, user_unionid) token = login_res["result"]["user_token"] url, data, method, expected = TestApijobAddgoodsask.urls[0], TestApijobAddgoodsask.datas[0], \ TestApijobAddgoodsask.methods[0], TestApijobAddgoodsask.expecteds[0] data.update({ "user_token": token, "goods_id": goods_id, "goods_ask_content": goods_ask_content }) res = ConfigHttp(url=url, data=data, method=method).request() self.mylog.debug("----test_apijob_addgoodsask----,相应结果为{}".format(res)) self.assertEqual(["添加商品咨询成功!"], expected)
def test_api_sumbitordergoods(self): data = self.dal.datas[0] login_res = dbshop_login(**data) #global token token= login_res["result"]["user_token"] url,data,method,expected = self.dal.urls[1],self.dal.datas[1],self.dal.methods[1],self.dal.expecteds[1] data.update ( { "user_token": token }) res = ConfigHttp(url=url,data=data,method=method).request().json() self.mylog.debug("----提交评价信息------".format(res)) self.assertEqual("商品评价添加完成!",expected)
def test_job_api_addCart(self): url,data,method = TestApiaddCart.urls[0],TestApiaddCart.datas[0],TestApiaddCart.methods[0] res = ConfigHttp(url=url,data=data,method=method).request() self.mylog.debug("----test_job_api_addCart---,响应结果为{}".format(res))
def test_api_logout(self): url, method = self.dal.urls[2], self.dal.methods[2] res = ConfigHttp(url=url, method=method).request().json() self.mylog.debug("test_api_logout---------响应结果{}".format(res))
def dbshop_logout(token): url, method = TestApiLogout.urls[0], TestApiLogout.methods[0] data = {"user_token": token} return ConfigHttp(url=url, data=data, method=method).request().json()