Skip to content

Commit

Permalink
Test and fix _apply_value_mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jul 26, 2023
1 parent f88056e commit 3740510
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions hic_aws_costing_tools/aws_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ def _apply_value_mappings(*, results, all_values1, all_values2, value_map1, valu
if value_map2:
for result in results:
for g in result["Groups"]:
g["Keys"][0] = value_map2[g["Keys"][0]]
all_values2 = set(value_map1[v] for v in all_values2)
g["Keys"][1] = value_map2[g["Keys"][1]]
all_values2 = set(value_map2[v] for v in all_values2)
return results, all_values1, all_values2


Expand Down
53 changes: 42 additions & 11 deletions tests/test_costbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,6 @@ def test_costs_to_flat(scenario):
assert_2d_costs_equal(expected_costs, costs, 4)


# @pytest.mark.parametrize("scenario", ["dummy-services", "dummy-proj"])
# def test_sum_cost_table_over_accounts(scenario):
# test_data = get_test_data(scenario, "test-costs_to_table")
# header = test_data["header"]
# costs = test_data["costs"]
# expected_sum = test_data["account_sum"]

# sum = aws_costs.sum_cost_table_over_accounts(header, costs)
# assert_2d_costs_equal(expected_sum, sum, 4)


@pytest.mark.parametrize("scenario", ["dummy-services", "dummy-proj"])
def test_format_message_summarise(scenario):
test_data = get_test_data(scenario, "test-costs_to_table")
Expand Down Expand Up @@ -260,6 +249,48 @@ def test_format_message_all(scenario, exclude_zero):
assert m == expected_output


def test_apply_value_mappings():
results_by_time = [
{
"Groups": [
{
"Keys": ["000000000001", "Service 1"],
"Metrics": {"UnblendedCost": {"Amount": "1.23", "Unit": "USD"}},
},
{
"Keys": ["000000000002", "Service 2"],
"Metrics": {"UnblendedCost": {"Amount": "4.56", "Unit": "USD"}},
},
]
}
]
value_map1 = {"000000000001": "Account 1", "000000000002": "Account 2"}
value_map2 = {"Service 1": "s.1", "Service 2": "s.2"}
results, all_values1, all_values2 = aws_costs._apply_value_mappings(
results=results_by_time,
all_values1=value_map1.keys(),
all_values2=value_map2.keys(),
value_map1=value_map1,
value_map2=value_map2,
)
assert all_values1 == set(value_map1.values())
assert all_values2 == set(value_map2.values())
assert results == [
{
"Groups": [
{
"Keys": ["Account 1", "s.1"],
"Metrics": {"UnblendedCost": {"Amount": "1.23", "Unit": "USD"}},
},
{
"Keys": ["Account 2", "s.2"],
"Metrics": {"UnblendedCost": {"Amount": "4.56", "Unit": "USD"}},
},
]
}
]


@pytest.mark.parametrize(
"startdate, days, enddate, expected_start, expected_end",
[
Expand Down

0 comments on commit 3740510

Please sign in to comment.