def test_execute_query_for_value_filter(self): """Test that the execute query runs properly with value query.""" key = "version" value = "prod" url = f"?filter[value]={value}" query_params = self.mocked_query_params(url, OCPAWSTagView) handler = OCPAWSTagQueryHandler(query_params) handler.key = key with tenant_context(self.tenant): tags = OCPAWSTagsValues.objects.filter(key__exact="version", value="prod").values("value").distinct().all() tag_values = [tag.get("value") for tag in tags] expected = {"key": key, "values": tag_values} result = handler.get_tag_values() self.assertEqual(result[0].get("key"), expected.get("key")) self.assertEqual(sorted(result[0].get("values")), sorted(expected.get("values")))
def test_execute_query_for_value_filter_partial_match(self): """Test that the execute query runs properly with value query.""" key = "version" value = "a" url = f"/version/?filter[value]={value}" query_params = self.mocked_query_params(url, OCPAWSTagView) # the mocked query parameters dont include the key from the url so it needs to be added query_params.kwargs = {"key": key} handler = OCPAWSTagQueryHandler(query_params) with tenant_context(self.tenant): tags = (OCPAWSTagsValues.objects.filter( key__exact=key, value__icontains=value).values("value").distinct().all()) tag_values = [tag.get("value") for tag in tags] expected = {"key": key, "values": tag_values} result = handler.get_tag_values() self.assertEqual(result[0].get("key"), expected.get("key")) self.assertEqual(sorted(result[0].get("values")), sorted(expected.get("values")))