Skip to content

Commit

Permalink
deprecate quota; add check credits
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkennedy committed Feb 2, 2024
1 parent 5a21c09 commit 3455de4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
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.credits_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` now returns a float instead of 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) -> Optional[float]:
"""
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) -> Optional[float]:
"""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.)

0 comments on commit 3455de4

Please sign in to comment.