带身份验证的烧瓶测试用户创建

时间:2019-07-29 14:16:27

标签: python authentication flask token

我正在通过身份验证测试用户创建,但是失败。

def register_user(self):
    return self.client.post(
        '/user/',
        data=json.dumps(dict(
            username='darek34',
            password="adsda"
        )),

        content_type='application/json'
    )

如何向此self.client.post添加身份验证令牌?

我将身份验证令牌存储为{'auth_token':dsadfdsa38432423 ...}

这是在最后一行失败的类。

class TestAuthBlueprint(BaseTestCase):
    def test_registration(self):
        """ Test for user registration """
        with self.client:
            print(self.client)
            response = register_user(self)
            data = json.loads(response.data.decode())
            self.assertTrue(data['status'] == 'success')

我使用装饰器@token_required保护用户创建

0 个答案:

没有答案