Skip to content

Commit

Permalink
Merge pull request #287 from ASFHyP3/revert-user-check-2
Browse files Browse the repository at this point in the history
Revert unapproved user check
  • Loading branch information
jtherrmann authored Jul 11, 2024
2 parents f2a4326 + eef6834 commit eb77501
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 59 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [7.0.1]

### Removed
* Removed the unapproved user warning implemented in [v6.2.0](https://github.com/ASFHyP3/hyp3-sdk/releases/tag/v6.2.0) (see <https://github.com/ASFHyP3/hyp3-sdk/pull/276>). This feature had unintended consequences which broke some processing pipelines that rely on the HyP3 SDK (see <https://github.com/ASFHyP3/hyp3-sdk/issues/285> for more details).

## [7.0.0]

### Removed
Expand Down
14 changes: 0 additions & 14 deletions src/hyp3_sdk/hyp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ def __init__(self, api_url: str = PROD_API, username: Optional[str] = None, pass

self.session = hyp3_sdk.util.get_authenticated_session(username, password)
self.session.headers.update({'User-Agent': f'{hyp3_sdk.__name__}/{hyp3_sdk.__version__}'})
self._check_application_status()

def _check_application_status(self) -> None:
help_url = 'https://hyp3-docs.asf.alaska.edu/using/requesting_access'
info = self.my_info()
if info['application_status'] == 'NOT_STARTED':
warnings.warn(f'User {info["user_id"]} has not yet applied for a monthly credit allotment.'
f' Please visit {help_url} to submit your application.')
if info['application_status'] == 'PENDING':
warnings.warn(f'User {info["user_id"]}\'s request for access is pending review. For more information, '
f'visit {help_url}')
if info['application_status'] == 'REJECTED':
warnings.warn(f'{info["user_id"]}\'s request for access has been rejected. For more information, '
f'visit {help_url}')

def find_jobs(self,
start: Optional[datetime] = None,
Expand Down
8 changes: 2 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@

@pytest.fixture(autouse=True)
def get_mock_hyp3():
def mock_my_info(self):
return {'application_status': 'APPROVED'}

def mock_get_authenticated_session(username, password):
return requests.Session()

def default_hyp3():
with patch('hyp3_sdk.hyp3.HyP3.my_info', mock_my_info):
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
return HyP3()
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
return HyP3()
return default_hyp3


Expand Down
39 changes: 0 additions & 39 deletions tests/test_hyp3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import math
import warnings
from datetime import datetime, timedelta, timezone
from unittest.mock import patch
from urllib.parse import urljoin

import requests
import responses

import hyp3_sdk
Expand Down Expand Up @@ -417,43 +415,6 @@ def test_check_credits(get_mock_hyp3):
assert math.isclose(api.check_credits(), 25.)


@responses.activate
def test_check_application_status_approved(get_mock_hyp3):
with warnings.catch_warnings(record=True) as w:
_ = get_mock_hyp3()
assert len(w) == 0


@responses.activate
def test_check_application_status_errors(get_mock_hyp3):
application_status = 'NOT_STARTED'
with warnings.catch_warnings(record=True) as w:
with patch('hyp3_sdk.hyp3.HyP3.my_info', lambda x: {'user_id': 'someUser',
'application_status': application_status}):
with patch('hyp3_sdk.util.get_authenticated_session', lambda username, password: requests.Session()):
_ = HyP3()
assert len(w) == 1
assert 'not yet applied for a monthly credit allotment' in str(w[0].message)

application_status = 'PENDING'
with warnings.catch_warnings(record=True) as w:
with patch('hyp3_sdk.hyp3.HyP3.my_info', lambda x: {'user_id': 'someUser',
'application_status': application_status}):
with patch('hyp3_sdk.util.get_authenticated_session', lambda username, password: requests.Session()):
_ = HyP3()
assert len(w) == 1
assert 'request for access is pending review' in str(w[0].message)

application_status = 'REJECTED'
with warnings.catch_warnings(record=True) as w:
with patch('hyp3_sdk.hyp3.HyP3.my_info', lambda x: {'user_id': 'someUser',
'application_status': application_status}):
with patch('hyp3_sdk.util.get_authenticated_session', lambda username, password: requests.Session()):
_ = HyP3()
assert len(w) == 1
assert 'request for access has been rejected' in str(w[0].message)


@responses.activate
def test_costs(get_mock_hyp3):
api_response = {'foo': 5}
Expand Down

0 comments on commit eb77501

Please sign in to comment.