def test_authentication(status_code, should_error, config, mocker): auth_url = 'https://harmony.earthdata.nasa.gov/jobs' responses.add( responses.GET, auth_url, status=status_code ) if should_error: with pytest.raises(BadAuthentication) as exc_info: actual_session = create_session(config) validate_auth(config, actual_session) if status_code == 401: assert 'Authentication: incorrect or missing credentials' in str(exc_info.value) elif status_code == 500: assert 'Authentication: An unknown error occurred' in str(exc_info.value) else: actual_session = create_session(config) validate_auth(config, actual_session) assert actual_session is not None
def test_authentication_no_args_no_validate(): fake_config = Object() fake_config.EDL_USERNAME = None fake_config.EDL_PASSWORD = None session = create_session(fake_config) assert session.auth is None
def test_authentication_with_malformed_auth(auth, config, mocker): with pytest.raises(MalformedCredentials) as exc_info: session = create_session(config, auth=auth) validate_auth(config, session) assert 'Authentication: `auth` argument requires tuple' in str(exc_info.value)
def _session(self): """Creates (if needed) and returns the Client's requests Session.""" if self.session is None: self.session = create_session(self.config, self.auth) return self.session