python unittest单元测试
import jsonimport unittestfrom manage import appheaders={ "Authorization":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NzA3ODAxMDksImlhdCI6MTU3MDY5MzcwNCwic3ViIjozfQ.Ltj3TVBiG_BOY2lWQnSwAMTG3ZO9uebJ-_u9pebupxU", "content-type":‘application/json‘,}class TestSujectBlueprint(unittest.TestCase): def setUp(self): app.testing = True self.client = app.test_client() def test_right_data(self): data= { "subjectCode":"3", "subjectName":"myname", response = app.test_client().post(‘/api/subject/create_subject‘, data=json.dumps(data), headers=headers) json_data = response.data json_dict = json.loads(json_data) print(json_dict) # self.assertEqual(json_dict[‘msg‘], ‘成功‘, ‘创建成功‘) # # # def test_repeat_subjectcode(self): # data = { # "subjectCode": "7", # "subjectName": "myname", # response = app.test_client().post(‘/api/subject/create_subject‘, data=json.dumps(data), headers=headers) # json_data = response.data # self.assertEqual(json_dict[‘msg‘], ‘编号不能重复‘, ‘编号不能重复‘) # # def test_null_data(self): # data = { # "subjectCode": "", # "subjectName": "myname", # response = app.test_client().post(‘/api/subject/create_subject‘, data=json.dumps(data), headers=headers) # json_data = response.data # json_dict = json.loads(json_data) # self.assertEqual(json_dict[‘msg‘], ‘失败,不能为空‘, ‘不能为空‘)if __name__ == ‘__main__‘: unittest.main()
相关推荐
abdstime 2020-07-29
sdwylry 2020-06-26
银角大王 2020-06-25
freerocker 2020-06-12
deadgrape 2020-05-30
goodby 2020-05-07
abdstime 2020-05-04
huanghong 2020-05-01
taiyangshenniao 2020-04-29
bcbeer 2020-04-23
加油奋斗吧 2020-04-07
jszy 2020-03-08
deadgrape 2020-03-06
zcabcd 2020-03-04
lucialee 2020-02-23
AnndyR 2020-02-22
mohanzb 2020-02-21