zoukankan      html  css  js  c++  java
  • python unittest单元测试

    import json
    import unittest
    from manage import app

    headers={
    "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()
  • 相关阅读:
    时间复杂度和空间复杂度的故事
    Go -- 并发编程的两种限速方法
    Go -- type 和断言 interface{}转换
    Go -- 实现二叉搜索树
    Go语言程序的状态监控
    Go -- 中开启gctrace
    Go --- GC优化经验
    Mysql 性能优化20个原则(4)
    Mysql 性能优化20个原则(3)
    查看 activex 组件的方法
  • 原文地址:https://www.cnblogs.com/lutt/p/11751737.html
Copyright © 2011-2022 走看看