forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Bugfix/computation of credits (ITISFoundation#5151)
- Loading branch information
1 parent
4cfa318
commit 3f92d39
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
services/resource-usage-tracker/tests/unit/test_computation_of_credits.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# pylint: disable=redefined-outer-name | ||
# pylint: disable=unused-argument | ||
# pylint: disable=unused-variable | ||
# pylint: disable=too-many-arguments | ||
|
||
from datetime import datetime, timedelta, timezone | ||
from decimal import Decimal | ||
|
||
import pytest | ||
from simcore_service_resource_usage_tracker.resource_tracker_utils import ( | ||
compute_service_run_credit_costs, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"stop,start,cost_per_unit,expected_cost", | ||
[ | ||
( | ||
datetime.now(tz=timezone.utc), | ||
datetime.now(tz=timezone.utc) - timedelta(days=1), | ||
Decimal(25), | ||
Decimal(600), | ||
), | ||
( | ||
datetime.now(tz=timezone.utc), | ||
datetime.now(tz=timezone.utc) - timedelta(days=2.5), | ||
Decimal(40), | ||
Decimal(2400), | ||
), | ||
( | ||
datetime.now(tz=timezone.utc), | ||
datetime.now(tz=timezone.utc) - timedelta(days=25), | ||
Decimal(12), | ||
Decimal(7200), | ||
), | ||
( | ||
datetime.now(tz=timezone.utc), | ||
datetime.now(tz=timezone.utc) - timedelta(days=45), | ||
Decimal(13.5), | ||
Decimal(14580), | ||
), | ||
( | ||
datetime.now(tz=timezone.utc), | ||
datetime.now(tz=timezone.utc) - timedelta(minutes=37), | ||
Decimal(25), | ||
round(Decimal(15.42), 2), | ||
), | ||
], | ||
) | ||
async def test_credit_computation(stop, start, cost_per_unit, expected_cost): | ||
computed_credits = await compute_service_run_credit_costs( | ||
start, stop, cost_per_unit | ||
) | ||
assert computed_credits == expected_cost | ||
|
||
|
||
async def test_invalid_dates_in_credit_computation(): | ||
start = datetime.now(tz=timezone.utc) | ||
stop = datetime.now(tz=timezone.utc) - timedelta(minutes=3) | ||
cost_per_unit = Decimal(25) | ||
|
||
with pytest.raises(ValueError): | ||
await compute_service_run_credit_costs(start, stop, cost_per_unit) |