From e33da7a28fb99fe8b60d69705f4ec66dce1036f5 Mon Sep 17 00:00:00 2001 From: Bernard Paques Date: Fri, 17 May 2024 13:31:49 +0200 Subject: [PATCH] add year in reports on activities, on costs and on exceptions - #131 --- lambdas/on_activity_handler.py | 1 + lambdas/on_cost_computation_handler.py | 1 + lambdas/on_exception_handler.py | 1 + tests/test_lambda_on_activity_handler.py | 4 ++-- tests/test_lambda_on_cost_computation_handler.py | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lambdas/on_activity_handler.py b/lambdas/on_activity_handler.py index aac5cd3..e4500d2 100644 --- a/lambdas/on_activity_handler.py +++ b/lambdas/on_activity_handler.py @@ -149,4 +149,5 @@ def get_report_path(label, day=None): day = day or date.today() return '/'.join([os.environ["REPORTING_ACTIVITIES_PREFIX"], label, + f"{day.year:04d}", f"{day.year:04d}-{day.month:02d}-{label}-activities.csv"]) diff --git a/lambdas/on_cost_computation_handler.py b/lambdas/on_cost_computation_handler.py index dc0a14c..b10d56e 100644 --- a/lambdas/on_cost_computation_handler.py +++ b/lambdas/on_cost_computation_handler.py @@ -191,6 +191,7 @@ def get_report_path(cost_center, label, day=None, suffix='csv'): day = day or date.today() return '/'.join([os.environ["REPORTING_COSTS_PREFIX"], cost_center, + f"{day.year:04d}", f"{day.year:04d}-{day.month:02d}-{cost_center}-{label}.{suffix}"]) diff --git a/lambdas/on_exception_handler.py b/lambdas/on_exception_handler.py index e4a75a8..8dd0410 100644 --- a/lambdas/on_exception_handler.py +++ b/lambdas/on_exception_handler.py @@ -148,6 +148,7 @@ def get_report_path(label, day=None): day = day or date.today() return '/'.join([os.environ["REPORTING_EXCEPTIONS_PREFIX"], label, + f"{day.year:04d}", f"{day.year:04d}-{day.month:02d}-{label}-cost-and-usage.xlsx"]) diff --git a/tests/test_lambda_on_activity_handler.py b/tests/test_lambda_on_activity_handler.py index 49ceed9..66c6f42 100644 --- a/tests/test_lambda_on_activity_handler.py +++ b/tests/test_lambda_on_activity_handler.py @@ -160,6 +160,6 @@ def test_get_hashes(): @patch.dict(os.environ, dict(REPORTING_ACTIVITIES_PREFIX="all/the/activities")) def test_get_report_path(): key = get_report_path("CostCenterOne", date(2022, 12, 25)) - assert key == "all/the/activities/CostCenterOne/2022-12-CostCenterOne-activities.csv" + assert key == "all/the/activities/CostCenterOne/2022/2022-12-CostCenterOne-activities.csv" key = get_report_path("CostCenterTwo", date(2023, 1, 2)) - assert key == "all/the/activities/CostCenterTwo/2023-01-CostCenterTwo-activities.csv" + assert key == "all/the/activities/CostCenterTwo/2023/2023-01-CostCenterTwo-activities.csv" diff --git a/tests/test_lambda_on_cost_computation_handler.py b/tests/test_lambda_on_cost_computation_handler.py index 67a3321..0f8c8df 100644 --- a/tests/test_lambda_on_cost_computation_handler.py +++ b/tests/test_lambda_on_cost_computation_handler.py @@ -140,7 +140,7 @@ def test_get_json_from_url(): @patch.dict(os.environ, dict(REPORTING_COSTS_PREFIX="costs")) def test_get_report_path(): result = get_report_path(cost_center='product-a', label='charges', day=date(2023, 3, 25), suffix='xyz') - assert result == 'costs/product-a/2023-03-product-a-charges.xyz' + assert result == 'costs/product-a/2023/2023-03-product-a-charges.xyz' @pytest.mark.unit_tests