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

Fix first tab condition #27

Merged
merged 1 commit into from
Apr 9, 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
1 change: 1 addition & 0 deletions news/26.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix first tab condition @reebalazs
3 changes: 3 additions & 0 deletions src/kitconcept/solr/services/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def reply(self):
raise BadRequest(
"Property 'group_select` must be an integer, if specified"
)
elif len(solr_config.filters) > 0:
# By default select group 0 (unless there are no filters defined)
group_select = 0

facet_fields = (
solr_config.select_facet_fields(group_select)
Expand Down
85 changes: 85 additions & 0 deletions tests/services/custom_config/test_endpoint_first_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import pytest


solr_config = {
"fieldList": [
"UID",
"Title",
"Description",
"Type",
"effective",
"start",
"created",
"end",
"path_string",
"phone",
"email",
"location",
],
"searchTabs": [
{
"label": "All except Pages",
"filter": "-Type:(Page)",
},
{
"label": "Pages",
"filter": "Type:(Page)",
},
{
"label": "News Items",
"filter": 'Type:("News Item")',
},
{
"label": "Pages and News Items",
"filter": 'Type:(Page OR "News Item")',
},
],
}


@pytest.fixture()
def registry_config() -> dict:
"""Override registry configuration."""
return {
"collective.solr.active": 1,
"kitconcept.solr.config": solr_config,
}


class TestEndpointFirstTab:
@pytest.fixture(autouse=True)
def _init(self, portal_with_content, manager_request):
self.portal = portal_with_content
response = manager_request.get(self.url)
self.data = response.json()


class TestEndpointFirstTabBaseSearch(TestEndpointFirstTab):
url = "/@solr?q=chomsky"

def test_facet_groups(self):
# Using default configuration
assert "response" in self.data
assert self.data.get("facet_groups") == [
["All except Pages", 2],
["Pages", 1],
["News Items", 1],
["Pages and News Items", 2],
]

@pytest.mark.parametrize(
"path,expected",
[
("/plone/mydocument", False),
("/plone/noamchomsky", True),
("/plone/mynews", True),
],
)
def test_paths(self, all_path_string, path: str, expected: bool):
path_strings = all_path_string(self.data)
assert (path in path_strings) is expected

def test_portal_path(self):
"""portal_path is returned for the client"""
assert "response" in self.data
assert self.data.get("portal_path") == "/plone"
Loading