Ejemplo n.º 1
0
def login(ctx, username, api_key):
    """Logs the user in by asking for username and api_key
    """
    if username is None:
        username = click.prompt('Username (netID)')
        click.echo()
    if api_key is None:
        click.echo('Please get your API key from ' +
                   click.style(_api_key_url, underline=True))
        api_key = click.prompt('API key')
        click.echo()
    click.echo('Checking your credentials...', nl=False)

    client = ApiClient(api_server_url=settings.API_SERVER_URL,
                       username=username, api_key=api_key)
    try:
        client.test_api_key()
    except ApiClientAuthenticationError:
        click.secho('invalid', bg='red', fg='black')
        click.echo('Please try again.')
        ctx.exit(code=exit_codes.OTHER_FAILURE)
    else:
        click.secho('OK', bg='green', fg='black')
        user = User(username=username, api_key=api_key)
        save_user(user)
Ejemplo n.º 2
0
def test_save_user():
    private_dir.ensure_private_dir_exists(settings.APP_NAME)
    assert not has_saved_user()
    user = User(username='******', api_key='api_key')
    save_user(user)
    assert has_saved_user()
    assert load_user() == user
    delete_user()
    assert not has_saved_user()
Ejemplo n.º 3
0
def saved_user(ensure_private_dir):
    user = User(username='******', api_key='key')
    save_user(user)
Ejemplo n.º 4
0
def test_to_json():
    user = User(username='******', api_key='api_key')
    data = json.loads(user.to_json())
    assert data['username'] == 'username'
    assert data['api_key'] == 'api_key'
Ejemplo n.º 5
0
def test_symmetry():
    user = User(username='******', api_key='api_key')
    assert User.from_json(user.to_json()) == user