对烧瓶API进行单元测试

时间:2019-04-09 18:20:23

标签: unit-testing

我正在为此API运行单元测试,并收到此错误 ----->追踪(最近通话最近):   在test_create_user中,文件“ /home/william/Questioner/app/tests/v1/test_mainmodule.py”,第29行     self.assertEqual(result [“ id”],“ 4”) TypeError:字符串索引必须是整数 。可能是什么问题?

def setUp(self):
    APP.testing = True
    self.app = APP.test_client()
    self.data = {"admin": False,
            "id": "4",
            "name": "njati",
            "password": "sha256$xfIUTEIX$6973717971585c3b7ebb593876def4124ff3eb4f8e30c3b43e2c8af20fe64952",
            "public_id": "<function uuid4 at 0x7fb631f93d08>"}

def post_create_user(self, data = {}):
    if not data:
        data = self.data
    result= self.app.post(path = "/user", data = json.dumps(self.data), content_type = "application/json")
    json_response = json.loads(result.get_data(as_text=True))
    return json_response

def test_create_user(self):
    with APP.app_context():
        result = self.post_create_user()

    self.assertEqual(result["id"],"4")
    self.assertEqual(result["public_id"], "<function uuid4 at 0x7fb631f93d08>")
    self.assertTrue(result["admin"], False)
    self.assertEqual(result["name"], "njati")
    self.assertEqual(result["password"], "sha256$xfIUTEIX$6973717971585c3b7ebb593876def4124ff3eb4f8e30c3b43e2c8af20fe64952")

0 个答案:

没有答案