def test_login(monkeypatch): app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar') data = { 'grant_type': 'password', 'client_id': app.client_id, 'client_secret': app.client_secret, 'username': '******', 'password': '******', 'scope': SCOPES, } request = Request('POST', 'https://bigfish.software/oauth/token', data=data) response = MockResponse({ 'token_type': 'bearer', 'scope': 'read write follow', 'access_token': 'xxx', 'created_at': 1492523699 }) e = Expectations() e.add(request, response) e.patch(monkeypatch) login(app, 'user', 'pass')
def test_login_failed(mock_post): app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar') data = { 'grant_type': 'password', 'client_id': app.client_id, 'client_secret': app.client_secret, 'username': '******', 'password': '******', 'scope': SCOPES, } mock_post.return_value = MockResponse(is_redirect=True) with pytest.raises(AuthenticationError): login(app, 'user', 'pass') mock_post.assert_called_once_with( 'https://bigfish.software/oauth/token', data, allow_redirects=False)
def test_login(mock_post): app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar') data = { 'grant_type': 'password', 'client_id': app.client_id, 'client_secret': app.client_secret, 'username': '******', 'password': '******', 'scope': SCOPES, } mock_post.return_value = MockResponse({ 'token_type': 'bearer', 'scope': 'read write follow', 'access_token': 'xxx', 'created_at': 1492523699 }) login(app, 'user', 'pass') mock_post.assert_called_once_with( 'https://bigfish.software/oauth/token', data, allow_redirects=False)
def test_login_failed(monkeypatch): app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar') data = { 'grant_type': 'password', 'client_id': app.client_id, 'client_secret': app.client_secret, 'username': '******', 'password': '******', 'scope': SCOPES, } request = Request('POST', 'https://bigfish.software/oauth/token', data=data) response = MockResponse(is_redirect=True) e = Expectations() e.add(request, response) e.patch(monkeypatch) with pytest.raises(AuthenticationError): login(app, 'user', 'pass')
def login_interactive(app, email=None): print_out("Log in to <green>{}</green>".format(app.instance)) if email: print_out("Email: <green>{}</green>".format(email)) while not email: email = input('Email: ') password = getpass('Password: '******'access_token'])
def login_interactive(app): print("\nLog in to " + green(app.instance)) email = input('Email: ') password = getpass('Password: '******'access_token']) path = config.save_user(user) print("Access token saved to: " + green(path)) return user
def test_login(monkeypatch): app = App('https://bigfish.software', 'foo', 'bar') def mock_post(url, data): assert url == 'https://bigfish.software/oauth/token' assert data == { 'grant_type': 'password', 'client_id': app.client_id, 'client_secret': app.client_secret, 'username': '******', 'password': '******', 'scope': SCOPES, } return MockResponse({ 'access_token': 'xxx', }) monkeypatch.setattr(requests, 'post', mock_post) user = login(app, 'user', 'pass') assert isinstance(user, User) assert user.username == 'user' assert user.access_token == 'xxx'