Skip to content

Commit

Permalink
Add first two tests for combine_itemz
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed Sep 23, 2024
1 parent f6d698d commit 39f7408
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
73 changes: 73 additions & 0 deletions usage_function/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,79 @@ def test_combine_items(self) -> None:
)
self.assertEqual(expected, existing_item)

def test_combine_itemz_1(self) -> None:
"""Check that we sum the costs."""
items_a = [
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
),
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
),
]

actual = utils.usage.combine_itemz(items_a)

expected = [
models.Usage(
id="someid",
date=date.today(),
cost=2,
total_cost=2,
subscription_id=UUID(int=0),
),
]
self.assertListEqual(expected, actual)

def test_combine_itemz_2(self) -> None:
"""Check that we sum the costs."""
items_a = [
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
reservation_id="somereservation",
),
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
),
]

actual = utils.usage.combine_itemz(items_a)

expected = [
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
reservation_id="somereservation",
),
models.Usage(
id="someid",
date=date.today(),
cost=1,
total_cost=1,
subscription_id=UUID(int=0),
),
]
self.assertListEqual(expected, actual)


class TestSettings(TestCase):
"""Tests for the utils.settings module."""
Expand Down
7 changes: 6 additions & 1 deletion usage_function/utils/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def combine_items(item_to_update: models.Usage, other_item: models.Usage) -> Non
item_to_update.cost += other_item.cost


def combine_itemz(a):
"""Sample docstring."""
pass


def retrieve_usage(
usage_data: Iterable[UsageDetailsListResult],
) -> list[models.Usage]:
Expand All @@ -116,7 +121,7 @@ def retrieve_usage(
"""
logging.warning("Retrieve items")

all_items: Dict[str, models.Usage] = {}
all_items: Dict[str, list[models.Usage]] = {}
started_processing_at = datetime.now()

for i, item in enumerate(usage_data):
Expand Down

0 comments on commit 39f7408

Please sign in to comment.