def test_get_tag_values_for_value_filter(self): """Test that get tag values runs properly with value query.""" key = "vm_key_proj2" value = "test_storage_label" url = f"?filter[value]={value}" query_params = self.mocked_query_params(url, GCPTagView) handler = GCPTagQueryHandler(query_params) handler.key = key with tenant_context(self.tenant): tags = GCPTagsValues.objects.filter( key__exact=key, value=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")))
def test_get_tag_values_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, GCPTagView) # the mocked query parameters dont include the key from the url so it needs to be added query_params.kwargs = {"key": key} handler = GCPTagQueryHandler(query_params) with tenant_context(self.tenant): tags = (GCPTagsValues.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")))