From 39f74083180c9a670cc735baefff06a848cada80 Mon Sep 17 00:00:00 2001 From: Iain-S <25081046+Iain-S@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:45:23 +0100 Subject: [PATCH] Add first two tests for combine_itemz --- usage_function/tests/test_utils.py | 73 ++++++++++++++++++++++++++++++ usage_function/utils/usage.py | 7 ++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/usage_function/tests/test_utils.py b/usage_function/tests/test_utils.py index 2c4b1dd..6ec4090 100644 --- a/usage_function/tests/test_utils.py +++ b/usage_function/tests/test_utils.py @@ -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.""" diff --git a/usage_function/utils/usage.py b/usage_function/utils/usage.py index 4dd4b65..8173899 100644 --- a/usage_function/utils/usage.py +++ b/usage_function/utils/usage.py @@ -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]: @@ -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):