Beispiel #1
0
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')
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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')
Beispiel #5
0
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'])
Beispiel #6
0
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
Beispiel #7
0
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'