Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def __init__(
        self,
        *,
        auth: Optional[Tuple[str, str]] = None,
        should_validate_auth: bool = True,
        env: Environment = Environment.PROD,
    ):
        """Creates a Harmony Client that can be used to interact with Harmony.

        Args:
            auth : A tuple of the format ('edl_username', 'edl_password')
            should_validate_auth: Whether EDL credentials will be validated.
        """
        self.config = Config(env)
        self.session = None
        self.auth = auth

        num_workers = int(self.config.NUM_REQUESTS_WORKERS)
        self.executor = ThreadPoolExecutor(max_workers=num_workers)

        if should_validate_auth:
            validate_auth(self.config, self._session())
Ejemplo n.º 3
0
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)