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

Deprecate HyP3.check_quota in favor of HyP3.check_credits #261

Merged
merged 3 commits into from
Feb 2, 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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ This release accommodates changes to the HyP3 API schema introduced in HyP3 v6.0

### Added
* `credit_cost` attribute to the `Job` class
* `HyP3.check_credits` method to determine your remaining processing credits

### Changed
* `HyP3.my_info()`: A new `remaining_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
* `HyP3.check_quota` may return a float or an integer if the user has processing credits

### Deprecated
* `HyP3.check_quota` has been deprecated in favor of `HyP3.check_credits`

## [5.0.0]
### Removed
Expand Down
13 changes: 12 additions & 1 deletion src/hyp3_sdk/hyp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from getpass import getpass
from typing import List, Literal, Optional, Union
from urllib.parse import urljoin
from warnings import warn

import hyp3_sdk
import hyp3_sdk.util
Expand Down Expand Up @@ -487,10 +488,20 @@ def my_info(self) -> dict:
_raise_for_hyp3_status(response)
return response.json()

def check_quota(self) -> Optional[int]:
def check_credits(self) -> Union[float, int, None]:
"""
Returns:
Your remaining processing credits, or None if you have no processing limit
"""
info = self.my_info()
return info['remaining_credits']

def check_quota(self) -> Union[float, int, None]:
"""Deprecated method for checking your remaining processing credits; replaced by `HyP3.check_credits`

Returns:
Your remaining processing credits, or None if you have no processing limit
"""
warn('This method is deprecated and will be removed in a future release.\n'
'Please use `HyP3.check_credits` instead.', DeprecationWarning, stacklevel=2)
return self.check_credits()
9 changes: 5 additions & 4 deletions tests/test_hyp3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import warnings
from datetime import datetime, timedelta, timezone
from unittest.mock import patch
Expand Down Expand Up @@ -411,7 +412,7 @@ def test_my_info():
'name1',
'name2'
],
'remaining_credits': 25,
'remaining_credits': 25.,
'user_id': 'someUser'
}
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
Expand All @@ -422,17 +423,17 @@ def test_my_info():


@responses.activate
def test_check_quota():
def test_check_credits():
api_response = {
'job_names': [
'name1',
'name2'
],
'remaining_credits': 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)

assert api.check_quota() == 25
assert math.isclose(api.check_credits(), 25.)
Loading