Skip to content

Commit

Permalink
[Fixes #12413] Group filter autocomplete does not work (#12414)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Jul 12, 2024
1 parent 007e640 commit 0c827f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions geonode/facets/providers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def get_facet_items(
logger.debug("Filtering by keys %r", keys)
filters["group__id__in"] = keys

if topic_contains:
filters["group__name__icontains"] = topic_contains

visible_groups = get_user_visible_groups(user=kwargs["user"])

q = (
Expand Down
25 changes: 25 additions & 0 deletions geonode/facets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,28 @@ def test_group_facet_api_call(self):

self.assertDictEqual(expected_response_filtered, response_dict_filtered)
self.assertDictEqual(expected_response_base, response_dict_base)

def test_group_facets_are_filtered_by_words(self):
# there are some groups and the facets return them
url = f"{reverse('get_facet',args=['group'])}"

response = self.client.get(url)
self.assertEqual(200, response.status_code, response.json())

self.assertTrue(response.json().get("topics", {}).get("total", 0) > 0)

# topic_contains with real name should return 1
url = f"{reverse('get_facet',args=['group'])}?topic_contains=UserAdmin"
response = self.client.get(url)

self.assertEqual(200, response.status_code, response.json())

self.assertEqual(1, response.json().get("topics", {}).get("total", 0))

# topic_contains with a random string to be searched for should be 0
url = f"{reverse('get_facet',args=['group'])}?topic_contains=abc123scfuqbrwefbasascgiu"
response = self.client.get(url)

self.assertEqual(200, response.status_code, response.json())

self.assertEqual(0, response.json().get("topics", {}).get("total", 0))

0 comments on commit 0c827f5

Please sign in to comment.