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

TSPS-405 Add quota units to quota info response #45

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ terralab = "terralab.cli:cli"

[tool.poetry.dependencies]
python = "^3.12"
terra-scientific-pipelines-service-api-client = "0.1.40"
terra-scientific-pipelines-service-api-client = "0.1.40" # TODO update once service PR is merged
python-dotenv = "^1.0.1"
click = "^8.1.7"
colorlog = "^6.9.0"
Expand Down
2 changes: 1 addition & 1 deletion terralab/auth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _exchange_code_for_response(
if "error" in json_response:
# see https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#error-response-1
LOGGER.debug(
f"Error in authentication flow exchanging code for response: {json_response["error"]}; error description: {json_response["error_description"]}"
f'Error in authentication flow exchanging code for response: {json_response["error"]}; error description: {json_response["error_description"]}'
Copy link
Collaborator Author

@mmorgantaylor mmorgantaylor Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR, but this will fix the issue George saw previously

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know what was causing this to be an "error" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does seem to be a python version thing. this error comes up using python 3.10 but not using python 3.12.

)
else:
LOGGER.debug("Token refresh successful")
Expand Down
9 changes: 6 additions & 3 deletions terralab/commands/quotas_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def quota(pipeline_name: str) -> None:
quota_limit = quota_info.quota_limit
quota_consumed = quota_info.quota_consumed
quota_pipeline = quota_info.pipeline_name
quota_units = quota_info.quota_units
LOGGER.info(f"Pipeline: {quota_pipeline}")
LOGGER.info(indented(f"Quota Limit: {quota_limit}"))
LOGGER.info(indented(f"Quota Used: {quota_consumed}"))
LOGGER.info(indented(f"Quota Available: {quota_limit - quota_consumed}"))
LOGGER.info(indented(f"Quota Limit: {quota_limit} {quota_units}"))
LOGGER.info(indented(f"Quota Used: {quota_consumed} {quota_units}"))
LOGGER.info(
indented(f"Quota Available: {quota_limit - quota_consumed} {quota_units}")
)
11 changes: 7 additions & 4 deletions tests/commands/test_quotas_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
def test_get_info_success(capture_logs, unstub):
test_pipeline_name = "test_pipeline"
test_quota_details = QuotaWithDetails(
pipeline_name=test_pipeline_name, quota_limit=1000, quota_consumed=300
pipeline_name=test_pipeline_name,
quota_limit=1000,
quota_consumed=300,
quota_units="samples",
)

when(quotas_commands.quotas_logic).get_user_quota(test_pipeline_name).thenReturn(
Expand All @@ -25,11 +28,11 @@ def test_get_info_success(capture_logs, unstub):
verify(quotas_commands.quotas_logic).get_user_quota(test_pipeline_name)
assert test_pipeline_name in capture_logs.text
# quota limit
assert "Quota Limit: 1000" in capture_logs.text
assert "Quota Limit: 1000 samples" in capture_logs.text
# quota consumed
assert "Quota Used: 300" in capture_logs.text
assert "Quota Used: 300 samples" in capture_logs.text
# quota left
assert "Quota Available: 700" in capture_logs.text
assert "Quota Available: 700 samples" in capture_logs.text

unstub()

Expand Down
6 changes: 5 additions & 1 deletion tests/logic/test_quotas_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def mock_quotas_api(mock_client_wrapper, unstub):
def test_get_user_quota(mock_quotas_api):
pipeline_name = "Test Pipeline"
mock_quota = QuotaWithDetails(
pipeline_name=pipeline_name, quota_limit=1000, quota_consumed=300
pipeline_name=pipeline_name,
quota_limit=1000,
quota_consumed=300,
quota_units="samples",
)
when(mock_quotas_api).get_quota_for_pipeline(
pipeline_name=pipeline_name
Expand All @@ -49,3 +52,4 @@ def test_get_user_quota(mock_quotas_api):
assert mock_quota.pipeline_name == result.pipeline_name
assert mock_quota.quota_limit == result.quota_limit
assert mock_quota.quota_consumed == result.quota_consumed
assert mock_quota.quota_units == result.quota_units
Loading