예제 #1
0
def test_from_json_malformed_string():
    data = {
        'username': '******',
        'api_key': 'api_key',
    }
    with pytest.raises(UserFormatError):
        User.from_json(json.dumps(data) + '}')
예제 #2
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)
예제 #3
0
def test_from_json():
    data = {
        'username': '******',
        'api_key': 'api_key',
    }
    user = User.from_json(json.dumps(data))
    assert user.username == 'username'
    assert user.api_key == 'api_key'
예제 #4
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()
예제 #5
0
def saved_user(ensure_private_dir):
    user = User(username='******', api_key='key')
    save_user(user)
예제 #6
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'
예제 #7
0
def test_symmetry():
    user = User(username='******', api_key='api_key')
    assert User.from_json(user.to_json()) == user
예제 #8
0
def test_from_json_incomplete_data():
    data = {
        'username': '******',
    }
    with pytest.raises(UserFormatError):
        User.from_json(json.dumps(data))