def test_configures_new_aws_creds(): session = Session() session.configure(aws_access_key='new_aws_key', aws_secret_access_key='new_aws_secret') assert session.auth.aws_secret_access_key == 'new_aws_secret' assert session.auth.aws_access_key == 'new_aws_key' assert session.auth.aws_region == 'us-east-1'
def test_request_expired_token(): session = Session() session.configure(use_jwt=True) previous_jwt = session.jwt_token.token with freeze_time(dt.datetime.utcnow() + dt.timedelta(days=40)): response = session.get('/api_keys') assert response['items'] assert session.jwt_token != previous_jwt
def test_request_valid_token(): session = Session() # Set date when the cassette was created otherwise will retrieve # an expired token with freeze_time(dt.date(2020, 10, 22)): session.configure(use_jwt=True) response = session.get('/api_keys') assert response['items']
def session(): session = Session() session.configure( 'api_key', 'api_secret', sandbox=True, ) return session
def test_overrides_session(mock_request): mock_request.return_value.ok = True mock_request.return_value.content = '{"items": []}' session = Session() session.configure(api_key='USER_API_KEY', api_secret='USER_SECRET', sandbox=True) Card.first(user_id='USER_ID', session=session) mock_request.assert_called_once() _, kwargs = mock_request.call_args_list[0] assert kwargs['auth'] == session.auth
def test_invalid_auth(): session = Session() session.configure(sandbox=False) with pytest.raises(CuencaResponseException) as e: session.post('/api_keys', dict()) assert e.value.status_code == 401 assert str(e.value)
def test_configures_jwt(): session = Session() session.configure(use_jwt=True) assert session.auth assert session.jwt_token
def test_basic_auth_configuration(): session = Session() assert session.auth == session.basic_auth assert session.auth == ('api_key', 'secret') assert not session.jwt_token
def test_aws_iam_auth_configuration(): session = Session() assert session.auth == session.iam_auth
def test_gives_preference_to_basic_auth_configuration(): session = Session() assert session.auth == session.basic_auth assert session.iam_auth