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
评论列表
文章目录