test_github_helper.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:zazu 作者: stopthatcow 项目源码 文件源码
def test_make_gh_token_otp(mocker):
    def require_otp(uri, headers={}, auth=(), json={}):
        assert ('user', 'password') == auth
        if 'X-GitHub-OTP' not in headers:
            return MockResponce(json={'message': 'Must specify two-factor authentication OTP code.'}, status_code=401)
        else:
            assert headers['X-GitHub-OTP'] == 'token'
            return MockResponce(json={'token': 'token'}, status_code=201)

    mocker.patch('zazu.util.prompt', side_effect=['user', 'token'], autospec=True)
    mocker.patch('click.prompt', return_value='password', autospec=True)
    mocker.patch('keyring.set_password')

    with mock_post(mocker, 'https://api.github.com/authorizations', mocker.Mock(wraps=require_otp)) as post_auth:
        assert 'token' == zazu.github_helper.make_gh_token()
        post_auth.call_count == 2
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号