def test_set_access_filters_with_list(self): """Test that the execute query runs properly with value query and an RBAC restriction on cluster.""" key = "app" value = "b" url = f"/app/?filter[value]={value}" query_params = self.mocked_query_params(url, OCPTagView) # the mocked query parameters dont include the key from the url so it needs to be added query_params.kwargs = {"key": key} handler = OCPTagQueryHandler(query_params) access = ["my-ocp-cluster-2"] filt = [ { "field": "report_period__cluster_id", "operation": "icontains", "composition_key": "cluster_filter" }, { "field": "report_period__cluster_alias", "operation": "icontains", "composition_key": "cluster_filter" }, ] filters = QueryFilterCollection() handler.set_access_filters(access, filt, filters) expected = [] expected.append( QueryFilter(field="report_period__cluster_id", operation="icontains", parameter=["my-ocp-cluster-2"])) expected.append( QueryFilter(field="report_period__cluster_alias", operation="icontains", parameter=["my-ocp-cluster-2"])) self.assertEqual(filters._filters, expected)
def test_set_access_filters(self): """Test that the execute query runs properly with value query and an RBAC restriction on cluster.""" key = "app" value = "b" url = f"/app/?filter[value]={value}" query_params = self.mocked_query_params(url, OCPTagView) # the mocked query parameters dont include the key from the url so it needs to be added query_params.kwargs = {"key": key} handler = OCPTagQueryHandler(query_params) access = ["aws_compute1"] filt = {"field": "nodes", "operation": "contained_by"} filters = QueryFilterCollection() handler.set_access_filters(access, filt, filters) expected = [ QueryFilter(field="nodes", operation="contained_by", parameter=["aws_compute1"]) ] self.assertEqual(filters._filters, expected)