From 454865aa74f50cbe6575a924a1123654c388799c Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Thu, 25 Jan 2024 14:54:59 -0900 Subject: [PATCH 1/3] support introduction of credits in the HyP3 API --- CHANGELOG.md | 9 +++++++++ src/hyp3_sdk/hyp3.py | 4 ++-- src/hyp3_sdk/jobs.py | 3 +++ tests/conftest.py | 3 ++- tests/test_hyp3.py | 14 ++++---------- tests/test_jobs.py | 6 ++++-- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9848719..f1974ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). +## [5.1.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 `reminaing_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()`. diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 84d9abf..463ff74 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -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'] diff --git a/src/hyp3_sdk/jobs.py b/src/hyp3_sdk/jobs.py index c29541f..1a10b31 100644 --- a/src/hyp3_sdk/jobs.py +++ b/src/hyp3_sdk/jobs.py @@ -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 @@ -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()})' @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index ade967b..fdb2895 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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'} diff --git a/tests/test_hyp3.py b/tests/test_hyp3.py index 96dc7f1..ab9d7a7 100644 --- a/tests/test_hyp3.py +++ b/tests/test_hyp3.py @@ -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): @@ -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 diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 92d7691..64e8cac 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -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 = { @@ -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, } From 7396151bc2b2f7c0aeea0a5c7c2d7899a20e9abe Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Fri, 26 Jan 2024 09:37:05 -0900 Subject: [PATCH 2/3] Update CHANGELOG.md Co-authored-by: Jake Herrmann --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1974ba..4187fed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This release accommodates changes to the HyP3 API schema introduced in HyP3 v6.0 * `credit_cost` attribute to the `Job` class ### Changed -* `HyP3.my_info()`: A new `reminaing_credits` field replaces the `quota` field in the return value +* `HyP3.my_info()`: A new `remaining_credits` field replaces the `quota` field in the return value ## [5.0.0] ### Removed From 6747b34dba45d451c20379ddbc2f9516104d942b Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Wed, 31 Jan 2024 13:53:04 -0900 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Jake Herrmann --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4187fed..88c55c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ 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). -## [5.1.0] +## [6.0.0] This release accommodates changes to the HyP3 API schema introduced in HyP3 v6.0.0 ### Added