Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support introduction of credits in the HyP3 API #259

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ 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).

## [6.0.0]
This release accommodates changes to the HyP3 API schema introduced in HyP3 v6.0.0

### Added
* `credit_cost` attribute to the `Job` class

### Changed
* `HyP3.my_info()`: A new `remaining_credits` field replaces the `quota` field in the return value

## [5.0.0]
### Removed
* `legacy` option for the `dem_name` argument of `HyP3.prepare_rtc_job()` and `HyP3.submit_rtc_job()`.
Expand Down
4 changes: 2 additions & 2 deletions src/hyp3_sdk/hyp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def my_info(self) -> dict:
def check_quota(self) -> Optional[int]:
"""
Returns:
The number of jobs left in your quota, or None if you have no quota
Your remaining processing credits, or None if you have no processing limit
"""
info = self.my_info()
return info['quota']['remaining']
return info['remaining_credits']
3 changes: 3 additions & 0 deletions src/hyp3_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
thumbnail_images: Optional[List] = None,
expiration_time: Optional[datetime] = None,
processing_times: Optional[List[float]] = None,
credit_cost: Optional[float] = None,
):
self.job_id = job_id
self.job_type = job_type
Expand All @@ -45,6 +46,7 @@ def __init__(
self.thumbnail_images = thumbnail_images
self.expiration_time = expiration_time
self.processing_times = processing_times
self.credit_cost = credit_cost

def __repr__(self):
return f'Job.from_dict({self.to_dict()})'
Expand Down Expand Up @@ -72,6 +74,7 @@ def from_dict(input_dict: dict):
thumbnail_images=input_dict.get('thumbnail_images'),
expiration_time=expiration_time,
processing_times=input_dict.get('processing_times'),
credit_cost=input_dict.get('credit_cost'),
)

def to_dict(self, for_resubmit: bool = False):
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def default_job(
files=None,
browse_images=None,
thumbnail_images=None,
expiration_time=None
expiration_time=None,
credit_cost=None,
):
if job_parameters is None:
job_parameters = {'param1': 'value1'}
Expand Down
14 changes: 4 additions & 10 deletions tests/test_hyp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,7 @@ def test_my_info():
'name1',
'name2'
],
'quota': {
'max_job_per_month': 50,
'remaining': 25
},
'remaining_credits': 25,
'user_id': 'someUser'
}
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
Expand All @@ -431,14 +428,11 @@ def test_check_quota():
'name1',
'name2'
],
'quota': {
'max_job_per_month': 50,
'remaining': 25
},
'remaining_credits': 25,
'user_id': 'someUser'
}
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
api = HyP3()
responses.add(responses.GET, urljoin(api.url, '/user'), json=api_response)
response = api.check_quota()
assert response == api_response['quota']['remaining']

assert api.check_quota() == 25
6 changes: 4 additions & 2 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"request_time": "2020-09-22T23:55:10+00:00",
"status_code": "SUCCEEDED",
"thumbnail_images": ["https://PAIR_PROCESS_thumb.png"],
"user_id": "asf_hyp3"
"user_id": "asf_hyp3",
"credit_cost": 1,
}

FAILED_JOB = {
Expand All @@ -39,7 +40,8 @@
"name": "test_failure",
"request_time": "2020-09-22T23:55:10+00:00",
"status_code": "FAILED",
"user_id": "asf_hyp3"
"user_id": "asf_hyp3",
"credit_cost": 1,
}


Expand Down
Loading