Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samdoran committed Jan 3, 2024
1 parent 85ad51c commit 891c5f6
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion koku/api/settings/test/cost_groups/test_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_get_cost_groups_invalid(self):

def test_get_cost_groups_filters(self):
"""Basic test to exercise the API endpoint"""
parameters = [{"group": "Platform"}, {"default": True}, {"project": OCP_PLATFORM_NAMESPACE}]
parameters = ({"group": "Platform"}, {"default": True}, {"project": OCP_PLATFORM_NAMESPACE})
for parameter in parameters:
with self.subTest(parameter=parameter):
for filter_option, filter_value in parameter.items():
Expand All @@ -73,6 +73,31 @@ def test_get_cost_groups_filters(self):
for item in data:
self.assertEqual(item.get(filter_option), filter_value)

def test_get_cost_groups_filters_multiple(self):
"""Test filtering with multiple values per field"""

test_matrix = (
{"field": "group", "value": ["Platform"], "expected": {"Platform"}},
{
"field": "project",
"value": [OCP_PLATFORM_NAMESPACE, "-PrOd"],
"expected": {"openshift-default", "koku-prod"},
},
)
for case in test_matrix:
with self.subTest(parameter=case["value"]):
params = {f"filter[{case['field']}]": case["value"]}
with schema_context(self.schema_name):
response = self.client.get(self.url, params, headers=self.headers)

data = response.data.get("data")
result = {}
if data:
result = {item[case["field"]] for item in data}

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(result.issubset(case["expected"]))

def test_get_cost_groups_order(self):
"""Basic test to exercise the API endpoint"""

Expand Down

0 comments on commit 891c5f6

Please sign in to comment.