-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_suggest.py
More file actions
103 lines (83 loc) · 2.65 KB
/
Copy pathtest_suggest.py
File metadata and controls
103 lines (83 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from typing import ClassVar
import pytest
import urllib.parse
class TestSuggestDefault:
@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()
@pytest.fixture
def get_suggest_result_props():
def func(
a: dict,
) -> bool:
ac = dict(a)
del ac["@id"]
return ac
return func
@pytest.fixture
def get_suggest_result_path():
def func(a: dict) -> bool:
return urllib.parse.urlparse(a["@id"]).path
return func
@pytest.fixture
def get_suggest_item():
def func(data, index: int) -> dict:
return data.get("suggestions")[index]
return func
class TestSuggestDefaultBaseSearch(TestSuggestDefault):
url = "/@solr-suggest?query=chomsky"
expected_result: ClassVar[list] = [
{
"@id": "http://localhost:59793/plone/mydocument",
"@type": "Document",
"description": "",
"review_state": "private",
"title": "My Document about Noam Chomsky",
"type_title": "Page",
},
{
"@id": "http://localhost:59793/plone/mynews",
"@type": "News Item",
"description": "",
"review_state": "private",
"title": "My News Item with Noam Chomsky",
"type_title": "News Item",
},
]
@pytest.mark.parametrize(
"index,expected_dict",
enumerate(expected_result),
)
def test_suggest_result_path(
self,
get_suggest_item,
get_suggest_result_path,
index: int,
expected_dict: dict,
):
assert get_suggest_result_path(
get_suggest_item(self.data, index)
) == get_suggest_result_path(expected_dict)
@pytest.mark.parametrize(
"index,expected_dict",
enumerate(expected_result),
)
def test_suggest_result_props(
self,
get_suggest_item,
get_suggest_result_props,
index: int,
expected_dict: dict,
):
assert (
get_suggest_result_props(expected_dict).items()
<= get_suggest_result_props(get_suggest_item(self.data, index)).items()
)
class TestSuggestPathPrefix(TestSuggestDefault):
"""path_prefix restricts suggestions to a subtree (e.g. a workspace)."""
url = "/@solr-suggest?query=chomsky&path_prefix=/mydocument"
def test_only_prefixed_results(self, get_suggest_result_path):
paths = [get_suggest_result_path(item) for item in self.data["suggestions"]]
assert paths == ["/plone/mydocument"]