Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #12413] Group filter autocomplete does not work #12414

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Loading