def test01_collection(self, url, headers, data, except_result, status_code): #临时数据 # url = "http://ttapi.research.itcast.cn/app/v1_0/article/collections" # headers = {"Content-Type": "application/json", "Authorization": "Bearer token-c9cdbf31e439486f9637471eb1630aee"} # data = {"target":1} #调用收藏文章方法 r = ApiArticle().api_post_collection(url, headers, data) #断言 # self.assertEqual(201,r.status_code) # self.assertEqual("OK",r.json()["message"]) print "收藏响应数据为:", r.json() #使用动态数据获取状态码 self.assertEqual(status_code, r.status_code) self.assertEqual(except_result, r.json()["message"])
def test_collect(self, url, headers, data, status_code, expect_result): # 临时数据 # url = 'http://ttapi.research.itcast.cn/app/v1_0/article/collections' # headers = { # "Content-Type": "application/json", # "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg5NjkyMzYsInVzZXJfaWQiOjEzMDA3MTI4MDY4MDIyNTk5NjgsInJlZnJlc2giOmZhbHNlfQ.j7WyrRVTowbt97HWN3KzoCKOsVVrNvU4JH-cExhj4z0" # } # data = {"target": 2} # 调用收藏文章方法 res = ApiArticle().api_post_collect(url, headers, data) # 调试 查看响应数据测试结果 print('响应结果为:', res.json()) # 断言 状态码 self.assertEqual(status_code, res.status_code) # 断言 响应信息 self.assertEqual(expect_result, res.json()['message'])
def test02_cancel(self, url, headers, status_code): # 临时数据,target暂时用1代替,header和前面有所不同 # url = "http://ttapi.research.itcast.cn/app/v1_0/article/collections/1" # headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": "Bearer token-c9cdbf31e439486f9637471eb1630aee"} # 调用取消收藏方法 r = ApiArticle().api_del_collection(url, headers) #必须要有括号才代表ApiArticle类的实例 # 断言 # self.assertEqual(204,r.status_code) #使用动态数据获取状态码 self.assertEqual(status_code, r.status_code)
def test01_collection(self, url, headers, data, expect_result, status_code): #临时数据 # url = "" # headers = {} # data = {} r = ApiArticle.api_post_collection(url, headers, data) print("响应数据为:", r.json()) self.assertEquals(status_code, r.status_code) self.assertEquals(expect_result, r.json()["message"])
def test01_collection(self, url, headers, data, expect_result, status_code): # 临时数据 # url = "http://ttapi.research.itcast.cn/app/v1_0/article/collections" # headers = {"Content-Type": "application/json","Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTAyNTg3MDksInVzZXJfaWQiOjU3LCJyZWZyZXNoIjpmYWxzZX0.1P7ksBYRR3DuDdsAfDynB_jl_MJCkjwkwRC_roJx6OE"} # data = {"target": 1} # 调用收藏文章方法 r = ApiArticle().api_post_collection(url, headers, data) # 调试 查看响应数据测试结果 print("收藏响应数据为:", r.json()) # 断言响应状态码 # self.assertEquals(201, r.status_code) # 使用动态数据获取状体码 self.assertEquals(status_code, r.status_code) # 断言响应信息 # self.assertEquals("OK", r.json()["message"]) # 使用动态数据获取 响应信息 self.assertEquals(expect_result, r.json()["message"])
def test_cancel_collect(self, url, headers, status_code): # url = 'http://ttapi.research.itcast.cn/app/v1_0/article/collections/2' # headers = { # "Content-Type": "application/x-www-form-urlencoded", # "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg5NjkyMzYsInVzZXJfaWQiOjEzMDA3MTI4MDY4MDIyNTk5NjgsInJlZnJlc2giOmZhbHNlfQ.j7WyrRVTowbt97HWN3KzoCKOsVVrNvU4JH-cExhj4z0" # } # 调用取消收藏方法 res = ApiArticle().api_delete_cancel_collect(url, headers) # 调试, 查看响应数据 print('响应数据为:', res.text) # 断言 状态码 self.assertEqual(status_code, res.status_code)
def test02_cancel(self, url, headers, status_code): # 临时数据 # url = "http://ttapi.research.itcast.cn/app/v1_0/article/collections/1" # headers = {"Content-Type": "application/x-www-form-urlencoded","Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTAyNTg3MDksInVzZXJfaWQiOjU3LCJyZWZyZXNoIjpmYWxzZX0.1P7ksBYRR3DuDdsAfDynB_jl_MJCkjwkwRC_roJx6OE"} # 调用去取消收藏方法 r = ApiArticle().api_delete_article(url, headers) # 获取 响应状态码 print(r.status_code) # 断言状态码 # self.assertEquals(204, r.status_code) # 使用动态获取 状态码 self.assertEquals(status_code, r.status_code)
def test02_cancel(self, url, headers, status_code): # url = "" # headers = {} r = ApiArticle().api_post_collection(url, headers) self.assertEquals(status_code, r.status_code)