def test_auth_request(mocker): fetch_mock = Mock() mocker.patch('blockserver.backend.auth.AccountingServerAuth.send_request', new=make_coroutine(fetch_mock)) token = 'Token foobar' ret = sentinel.ret ret.body = b'{"user_id": 0, "active": true, "block_quota": 512, "monthly_traffic_quota": 1024}' fetch_mock.return_value = ret response = yield auth.AccountingServerAuth.request_auth(token) assert response == auth.User(user_id=0, is_active=True, quota=512, traffic_quota=1024) fetch_mock.assert_called_once_with('{"auth": "Token foobar"}')
def mock_auth(mocker): mock = Mock() mocker.patch('blockserver.backend.auth.AccountingServerAuth.request_auth', new=make_coroutine(mock)) return mock