class MyTest(unittest.TestCase): #封装测试环境的初始化 token = Fun.take_token('../common/token.json') def setUp(self): print("start test") pass def test_1_getStatus(self): token = self.token print("Get Appliance's Status Interface Test") self.url1 = Url.server + "/api/homeappliances/BOSCH-WTU879H00W-68A40E03C617/status" header = {'Content-Type': 'application/json'} header1_1 = Fun.merge_Two_Dicts(header, token) response1 = requests.get(url=self.url1, params={}, headers=header1_1) d = json.loads(response1.text) assert response1.status_code == 200 assert d["msg"] == "成功", "retInfo not right" assert "status" in d["data"].keys() print("Get Appliance's Status pass") print("response code :" + str(response1.status_code)) print("r.elapsed.millisecond :" + str(response1.elapsed.microseconds / 1000)) print("response data :" + response1.text) def tearDown(self): print("end test") pass
def getStatus(self): #写死getStatus请求 token = Fun.take_token('../common/token.json') print("Get Appliance's Status Interface Test") url1 = Url.server + "/api/homeappliances/BOSCH-WTU879H00W-68A40E03C617/status" header = {'Content-Type': 'application/json'} header1_1 = Fun.merge_Two_Dicts(header, token) response1 = requests.get(url=url1, params={}, headers=header1_1) return response1
class MyTest(unittest.TestCase): #封装测试环境的初始化 token = Fun.take_token('../common/token.json') def setUp(self): print("-----start test Recipe_Interfaces-----") pass def test_1_GetRecipeCatalogs(self): print("get Recipe Catalogs Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeCatalogs_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data1 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_2_GetRecipeHotCatalogs(self): print("get Recipe Hot Catalogs Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeHotCatalogs_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data1 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_3_GetRecipeList(self): print("Get Recipe List Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeList_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data3 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_4_getSearchRecipe(self): print("get Search Recipe Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getSearchRecipe_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data4 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_5_getRecipeDetails(self): print("Get recipe details Test") token = self.token url1 = self.url1 = Recipe_Interfaces.GetRecipeDetails_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data5 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def tearDown(self): print("-----end test Basic Support-----") pass
class MyTest(unittest.TestCase): #封装测试环境的初始化 token = Fun.take_token('../common/token.json') def setUp(self): print("-----start test Basic Support-----") pass def test_1_IPLocationInterface(self): print("IP Location Interface Test") token = self.token self.url1 = BasicSupport_Element.IPLocation_url head1_1 = Fun.merge_Two_Dicts(BasicSupport_Element.header1, token) Fun.post_url(self.url1, data={}, headers=head1_1) def test_2_Realtimeweather(self): print("Real time weather Interface Test") token = self.token self.url2 = BasicSupport_Element.Realtimeweather_url heaad2_2 = Fun.merge_Two_Dicts(BasicSupport_Element.header2, token) response2 = requests.get(url=self.url2, params={}, headers=heaad2_2) d = json.loads(response2.text) assert response2.status_code == 200 assert d["retInfo"] == "success", "retInfo not right" assert "retBody" in d.keys() print("status_code_IPLocation:" + str(response2.status_code)) print("pass") def test_3_WeatherforecastInterface(self): print("Weather forecast Interface Test") token = self.token self.url3 = BasicSupport_Element.WeatherforecastInterface_url heaad3_3 = Fun.merge_Two_Dicts(BasicSupport_Element.header3, token) response3 = requests.get(url=self.url3, params={}, headers=heaad3_3) d = json.loads(response3.text) assert response3.status_code == 200 assert d["retInfo"] == "success", "retInfo not right" assert "retBody" in d.keys() print("status_code_IPLocation:" + str(response3.status_code)) print("pass") def test_4_TimeSynchronizationInterface(self): print("Time Synchronization Interface Test") token = self.token self.url4 = BasicSupport_Element.TimeSynchronization_url self.params = {} self.head4_4 = Fun.merge_Two_Dicts(BasicSupport_Element.header4, self.token) Fun.get_url(self.url4, self.params, self.head4_4) def tearDown(self): print("-----end test Basic Support-----") pass
class MyTest(unittest.TestCase): #封装测试环境的初始化 token = Fun.take_token('../common/token.json') def setUp(self): print("-----start test Shopping Cart Interfaces-----") pass def test_01_AddToCart(self): print("Add to shopping cart Test") token = self.token url1 = self.url1 = ShoppingCartInterfaces.AddToCart_url head1 = Fun.merge_Two_Dicts(ShoppingCartInterfaces.header1, token) data1 = ShoppingCartInterfaces.data1 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_02_DeleteItemsInShoppingCart(self): print("Delete items in shopping cart Test") token = self.token url1 = self.url1 = ShoppingCartInterfaces.DeleteItemsInShoppingCart_url head1 = Fun.merge_Two_Dicts(ShoppingCartInterfaces.header1, token) data1 = ShoppingCartInterfaces.data2 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_03_ModifyProductInShoppingCart(self): print("Modify product in shopping cart Test") token = self.token url1 = self.url1 = ShoppingCartInterfaces.ModifyProductInShoppingCart_url head1 = Fun.merge_Two_Dicts(ShoppingCartInterfaces.header1, token) data1 = ShoppingCartInterfaces.data3 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_04_BrowseTheItemsInTheShoppingCart(self): print("Browse the items in the shopping cart Test") token = self.token url1 = self.url1 = ShoppingCartInterfaces.BrowseTheItemsInTheShoppingCart_url head1 = Fun.merge_Two_Dicts(ShoppingCartInterfaces.header1, token) data1 = ShoppingCartInterfaces.data4 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def tearDown(self): print("-----end test Basic Support-----") pass
class MyTest(unittest.TestCase): #封装测试环境的初始化 token = Fun.take_token('../common/token.json') def setUp(self): print("-----start test Recipe_Interfaces-----") pass def test_01_GetRecipeCatalogs(self): print("get Recipe Catalogs Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeCatalogs_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data1 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_02_GetRecipeHotCatalogs(self): print("get Recipe Hot Catalogs Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeHotCatalogs_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data1 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_03_GetRecipeList(self): print("Get Recipe List Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeList_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data3 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_04_getSearchRecipe(self): print("get Search Recipe Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getSearchRecipe_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data4 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_05_getRecipeDetails(self): print("Get recipe details Test") token = self.token url1 = self.url1 = Recipe_Interfaces.GetRecipeDetails_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data5 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_06_getSeasonIngredientList(self): print("get Season Ingredient List Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getSeasonIngredientList_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data6 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_07_getRankingRecipe(self): print("get Ranking Recipe Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRankingRecipe_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data7 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_08_getChosenRecipe(self): print("get Chosen Recipe Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getChosenRecipe_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data8 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_09_getHotMenus(self): print("get Hot Menus Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getHotMenus_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data9 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_10_getVideos(self): print("get Videos Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getVideos_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data10 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_11_getRecipeByTime(self): print("get Recipe By Time Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeByTime_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data11 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_12_getRecipeByIngredients(self): print("get Recipe By Ingredients Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getRecipeByIngredients_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data12 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_13_addCollect(self): print("add Collect Test") token = self.token url1 = self.url1 = Recipe_Interfaces.addCollect_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data13 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_14_getCollect(self): print("get Collect Test") token = self.token url1 = self.url1 = Recipe_Interfaces.getCollect_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data14 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def test_15_delCollect(self): print("del Collect Test") token = self.token url1 = self.url1 = Recipe_Interfaces.delCollect_url head1 = Fun.merge_Two_Dicts(Recipe_Interfaces.header1, token) data1 = Recipe_Interfaces.data15 data1_1 = json.dumps(data1) Fun.post_url(url=url1, data=data1_1, headers=head1) def tearDown(self): print("-----end test Basic Support-----") pass
import requests import unittest from testPlan.common.commonFun import BasicSupport_Element, Fun import json token = Fun.take_token('../common/token.json') #def get_url(url, params ,headers): # url = url # params = params # headers = headers # response = requests.get(url = url , params = params,headers= headers) # d = json.loads(response.text) # assert response.status_code == 200 # assert d["retInfo"] == "success", "retInfo not right" # assert "retBody" in d.keys() # print("status_code_IPLocation:" + str(response.status_code)) # print(response.text) # print("pass") url = "https://solution.home-connect.cn/sfmapi/service/v1/recipe/getRecipeCatalogs" data1 = { "header": { "timestamp": "2014-11-12 15:48:00", "deviceCode": "BE080A300QZ225H00002", "ver": "v1.0", "sign": "18c8c29f0898ac4b8b0a7a6afdb436aa" }, "data": {} } data2 = json.dumps(data1) #data3 = json.loads(data1)