Merge lp:~stolowski/unity-scope-click/apps-new-search-semantics into lp:unity-scope-click
- apps-new-search-semantics
- Merge into trunk
Proposed by
Paweł Stołowski
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | 400 |
Merged at revision: | 430 |
Proposed branch: | lp:~stolowski/unity-scope-click/apps-new-search-semantics |
Merge into: | lp:unity-scope-click |
Diff against target: |
514 lines (+132/-57) 13 files modified
libclickscope/click/index.cpp (+2/-2) libclickscope/click/index.h (+1/-1) libclickscope/click/interface.cpp (+1/-1) libclickscope/tests/integration/webclient_integration.cpp (+1/-1) libclickscope/tests/test_index.cpp (+9/-9) scope/clickapps/apps-query.cpp (+3/-5) scope/clickstore/store-query.cpp (+18/-2) scope/clickstore/store-query.h (+1/-0) scope/tests/test_apps_query.cpp (+34/-18) scope/tests/test_helpers.h (+22/-4) scope/tests/test_query.cpp (+40/-12) tests/scope-harness/tests/test_apps.py (+0/-1) tests/scope-harness/tests/test_store.py (+0/-1) |
To merge this branch: | bzr merge lp:~stolowski/unity-scope-click/apps-new-search-semantics |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Needs Fixing | |
dobey (community) | Approve | ||
Review via email: mp+276634@code.launchpad.net |
Commit message
Always push departments (departments should be available also in search mode) and allow searching inside departments.
Description of the change
Always push departments (departments should be available also in search mode) and allow searching inside departments.
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:400
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
review:
Needs Fixing
(continuous-integration)
- 401. By Paweł Stołowski
-
Merged trunk
- 402. By Paweł Stołowski
-
Fix test
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libclickscope/click/index.cpp' | |||
2 | --- libclickscope/click/index.cpp 2016-01-21 23:25:38 +0000 | |||
3 | +++ libclickscope/click/index.cpp 2016-03-09 13:08:23 +0000 | |||
4 | @@ -147,11 +147,11 @@ | |||
5 | 147 | return std::pair<Packages, Packages>(pl, recommends); | 147 | return std::pair<Packages, Packages>(pl, recommends); |
6 | 148 | } | 148 | } |
7 | 149 | 149 | ||
9 | 150 | click::web::Cancellable Index::search (const std::string& query, | 150 | click::web::Cancellable Index::search (const std::string& query, const std::string& department, |
10 | 151 | std::function<void(click::Packages search_results, click::Packages recommendations)> callback) | 151 | std::function<void(click::Packages search_results, click::Packages recommendations)> callback) |
11 | 152 | { | 152 | { |
12 | 153 | click::web::CallParams params; | 153 | click::web::CallParams params; |
14 | 154 | const std::string built_query(build_index_query(query, "")); | 154 | const std::string built_query(build_index_query(query, department)); |
15 | 155 | params.add(click::QUERY_ARGNAME, built_query.c_str()); | 155 | params.add(click::QUERY_ARGNAME, built_query.c_str()); |
16 | 156 | QSharedPointer<click::web::Response> response(client->call( | 156 | QSharedPointer<click::web::Response> response(client->call( |
17 | 157 | get_base_url() + click::SEARCH_PATH, "GET", true, build_headers(), "", params)); | 157 | get_base_url() + click::SEARCH_PATH, "GET", true, build_headers(), "", params)); |
18 | 158 | 158 | ||
19 | === modified file 'libclickscope/click/index.h' | |||
20 | --- libclickscope/click/index.h 2015-11-24 18:23:23 +0000 | |||
21 | +++ libclickscope/click/index.h 2016-03-09 13:08:23 +0000 | |||
22 | @@ -79,7 +79,7 @@ | |||
23 | 79 | Index(const QSharedPointer<click::web::Client>& client, | 79 | Index(const QSharedPointer<click::web::Client>& client, |
24 | 80 | const QSharedPointer<Configuration> configuration=QSharedPointer<Configuration>(new Configuration())); | 80 | const QSharedPointer<Configuration> configuration=QSharedPointer<Configuration>(new Configuration())); |
25 | 81 | virtual std::pair<Packages, Packages> package_lists_from_json(const std::string& json); | 81 | virtual std::pair<Packages, Packages> package_lists_from_json(const std::string& json); |
27 | 82 | virtual click::web::Cancellable search (const std::string& query, std::function<void(Packages, Packages)> callback); | 82 | virtual click::web::Cancellable search (const std::string& query, const std::string& department, std::function<void(Packages, Packages)> callback); |
28 | 83 | virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback); | 83 | virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback); |
29 | 84 | virtual click::web::Cancellable bootstrap(std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); | 84 | virtual click::web::Cancellable bootstrap(std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); |
30 | 85 | virtual click::web::Cancellable departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); | 85 | virtual click::web::Cancellable departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); |
31 | 86 | 86 | ||
32 | === modified file 'libclickscope/click/interface.cpp' | |||
33 | --- libclickscope/click/interface.cpp 2016-03-07 14:10:22 +0000 | |||
34 | +++ libclickscope/click/interface.cpp 2016-03-09 13:08:23 +0000 | |||
35 | @@ -274,7 +274,7 @@ | |||
36 | 274 | { | 274 | { |
37 | 275 | // | 275 | // |
38 | 276 | // only apply department filtering if not in root of all departments. | 276 | // only apply department filtering if not in root of all departments. |
40 | 277 | bool apply_department_filter = (search_query.empty() && !current_department.empty()); | 277 | bool apply_department_filter = !current_department.empty(); |
41 | 278 | 278 | ||
42 | 279 | // get the set of packages that belong to current deparment; | 279 | // get the set of packages that belong to current deparment; |
43 | 280 | std::unordered_set<std::string> packages_in_department; | 280 | std::unordered_set<std::string> packages_in_department; |
44 | 281 | 281 | ||
45 | === modified file 'libclickscope/tests/integration/webclient_integration.cpp' | |||
46 | --- libclickscope/tests/integration/webclient_integration.cpp 2014-06-24 17:18:53 +0000 | |||
47 | +++ libclickscope/tests/integration/webclient_integration.cpp 2016-03-09 13:08:23 +0000 | |||
48 | @@ -103,7 +103,7 @@ | |||
49 | 103 | new click::web::Client(namPtr)); | 103 | new click::web::Client(namPtr)); |
50 | 104 | click::Index index(clientPtr); | 104 | click::Index index(clientPtr); |
51 | 105 | click::Packages packages; | 105 | click::Packages packages; |
53 | 106 | index.search("qr", [&, this](click::Packages found_packages, | 106 | index.search("qr", "", [&, this](click::Packages found_packages, |
54 | 107 | click::Packages){ | 107 | click::Packages){ |
55 | 108 | packages = found_packages; | 108 | packages = found_packages; |
56 | 109 | Quit(); | 109 | Quit(); |
57 | 110 | 110 | ||
58 | === modified file 'libclickscope/tests/test_index.cpp' | |||
59 | --- libclickscope/tests/test_index.cpp 2016-01-21 23:25:38 +0000 | |||
60 | +++ libclickscope/tests/test_index.cpp 2016-03-09 13:08:23 +0000 | |||
61 | @@ -109,7 +109,7 @@ | |||
62 | 109 | .Times(1) | 109 | .Times(1) |
63 | 110 | .WillOnce(Return(response)); | 110 | .WillOnce(Return(response)); |
64 | 111 | 111 | ||
66 | 112 | indexPtr->search("", [](click::Packages, click::Packages) {}); | 112 | indexPtr->search("", "", [](click::Packages, click::Packages) {}); |
67 | 113 | } | 113 | } |
68 | 114 | 114 | ||
69 | 115 | MATCHER_P(QueryContains, query, "") | 115 | MATCHER_P(QueryContains, query, "") |
70 | @@ -132,7 +132,7 @@ | |||
71 | 132 | .Times(1) | 132 | .Times(1) |
72 | 133 | .WillOnce(Return(response)); | 133 | .WillOnce(Return(response)); |
73 | 134 | 134 | ||
75 | 135 | indexPtr->search("FooBar", [](click::Packages, click::Packages) {}); | 135 | indexPtr->search("FooBar", "", [](click::Packages, click::Packages) {}); |
76 | 136 | } | 136 | } |
77 | 137 | 137 | ||
78 | 138 | 138 | ||
79 | @@ -151,7 +151,7 @@ | |||
80 | 151 | .Times(1) | 151 | .Times(1) |
81 | 152 | .WillOnce(Return(response)); | 152 | .WillOnce(Return(response)); |
82 | 153 | 153 | ||
84 | 154 | indexPtr->search("", [](click::Packages, click::Packages) {}); | 154 | indexPtr->search("", "", [](click::Packages, click::Packages) {}); |
85 | 155 | } | 155 | } |
86 | 156 | 156 | ||
87 | 157 | TEST_F(IndexTest, testBootstrapSignsCall) | 157 | TEST_F(IndexTest, testBootstrapSignsCall) |
88 | @@ -206,7 +206,7 @@ | |||
89 | 206 | .Times(1) | 206 | .Times(1) |
90 | 207 | .WillOnce(Return(response)); | 207 | .WillOnce(Return(response)); |
91 | 208 | 208 | ||
93 | 209 | indexPtr->search("", [](click::Packages, click::Packages) {}); | 209 | indexPtr->search("", "", [](click::Packages, click::Packages) {}); |
94 | 210 | } | 210 | } |
95 | 211 | 211 | ||
96 | 212 | TEST_F(IndexTest, testSearchCallbackIsCalled) | 212 | TEST_F(IndexTest, testSearchCallbackIsCalled) |
97 | @@ -229,7 +229,7 @@ | |||
98 | 229 | .WillOnce(Return(response)); | 229 | .WillOnce(Return(response)); |
99 | 230 | EXPECT_CALL(*this, search_callback(_, _)).Times(1); | 230 | EXPECT_CALL(*this, search_callback(_, _)).Times(1); |
100 | 231 | 231 | ||
102 | 232 | indexPtr->search("", [this](click::Packages packages, | 232 | indexPtr->search("", "", [this](click::Packages packages, |
103 | 233 | click::Packages recommends){ | 233 | click::Packages recommends){ |
104 | 234 | search_callback(packages, recommends); | 234 | search_callback(packages, recommends); |
105 | 235 | }); | 235 | }); |
106 | @@ -257,7 +257,7 @@ | |||
107 | 257 | click::Packages empty_package_list; | 257 | click::Packages empty_package_list; |
108 | 258 | EXPECT_CALL(*this, search_callback(empty_package_list, _)).Times(1); | 258 | EXPECT_CALL(*this, search_callback(empty_package_list, _)).Times(1); |
109 | 259 | 259 | ||
111 | 260 | indexPtr->search("", [this](click::Packages packages, | 260 | indexPtr->search("", "", [this](click::Packages packages, |
112 | 261 | click::Packages recommends){ | 261 | click::Packages recommends){ |
113 | 262 | search_callback(packages, recommends); | 262 | search_callback(packages, recommends); |
114 | 263 | }); | 263 | }); |
115 | @@ -293,7 +293,7 @@ | |||
116 | 293 | }; | 293 | }; |
117 | 294 | EXPECT_CALL(*this, search_callback(single_package_list, _)).Times(1); | 294 | EXPECT_CALL(*this, search_callback(single_package_list, _)).Times(1); |
118 | 295 | 295 | ||
120 | 296 | indexPtr->search("", [this](click::Packages packages, | 296 | indexPtr->search("", "", [this](click::Packages packages, |
121 | 297 | click::Packages recommends){ | 297 | click::Packages recommends){ |
122 | 298 | search_callback(packages, recommends); | 298 | search_callback(packages, recommends); |
123 | 299 | }); | 299 | }); |
124 | @@ -315,7 +315,7 @@ | |||
125 | 315 | .Times(1) | 315 | .Times(1) |
126 | 316 | .WillOnce(Return(response)); | 316 | .WillOnce(Return(response)); |
127 | 317 | 317 | ||
129 | 318 | auto search_operation = indexPtr->search("", [](click::Packages, | 318 | auto search_operation = indexPtr->search("", "", [](click::Packages, |
130 | 319 | click::Packages) {}); | 319 | click::Packages) {}); |
131 | 320 | EXPECT_CALL(reply.instance, abort()).Times(1); | 320 | EXPECT_CALL(reply.instance, abort()).Times(1); |
132 | 321 | search_operation.cancel(); | 321 | search_operation.cancel(); |
133 | @@ -341,7 +341,7 @@ | |||
134 | 341 | .Times(1) | 341 | .Times(1) |
135 | 342 | .WillOnce(Return(response)); | 342 | .WillOnce(Return(response)); |
136 | 343 | EXPECT_CALL(reply.instance, errorString()).Times(1).WillOnce(Return("fake error")); | 343 | EXPECT_CALL(reply.instance, errorString()).Times(1).WillOnce(Return("fake error")); |
138 | 344 | indexPtr->search("", [this](click::Packages packages, | 344 | indexPtr->search("", "", [this](click::Packages packages, |
139 | 345 | click::Packages recommends){ | 345 | click::Packages recommends){ |
140 | 346 | search_callback(packages, recommends); | 346 | search_callback(packages, recommends); |
141 | 347 | }); | 347 | }); |
142 | 348 | 348 | ||
143 | === modified file 'scope/clickapps/apps-query.cpp' | |||
144 | --- scope/clickapps/apps-query.cpp 2016-02-19 03:35:43 +0000 | |||
145 | +++ scope/clickapps/apps-query.cpp 2016-03-09 13:08:23 +0000 | |||
146 | @@ -412,11 +412,9 @@ | |||
147 | 412 | auto const ignoredApps = impl->configuration.get_ignored_apps(); | 412 | auto const ignoredApps = impl->configuration.get_ignored_apps(); |
148 | 413 | auto const localResults = clickInterfaceInstance().find_installed_apps(querystr, ignoredApps, current_dept, impl->depts_db); | 413 | auto const localResults = clickInterfaceInstance().find_installed_apps(querystr, ignoredApps, current_dept, impl->depts_db); |
149 | 414 | 414 | ||
155 | 415 | if (querystr.empty()) { | 415 | if (impl->depts_db) |
156 | 416 | if (impl->depts_db) | 416 | { |
157 | 417 | { | 417 | push_local_departments(searchReply, localResults); |
153 | 418 | push_local_departments(searchReply, localResults); | ||
154 | 419 | } | ||
158 | 420 | } | 418 | } |
159 | 421 | 419 | ||
160 | 422 | if (show_top_apps) | 420 | if (show_top_apps) |
161 | 423 | 421 | ||
162 | === modified file 'scope/clickstore/store-query.cpp' | |||
163 | --- scope/clickstore/store-query.cpp 2016-01-06 18:08:33 +0000 | |||
164 | +++ scope/clickstore/store-query.cpp 2016-03-09 13:08:23 +0000 | |||
165 | @@ -429,6 +429,20 @@ | |||
166 | 429 | } | 429 | } |
167 | 430 | } | 430 | } |
168 | 431 | 431 | ||
169 | 432 | void click::Query::push_departments(scopes::SearchReplyProxy const& searchReply) | ||
170 | 433 | { | ||
171 | 434 | auto rootdep = impl->department_lookup.get_department_info(""); | ||
172 | 435 | if (!rootdep) | ||
173 | 436 | { | ||
174 | 437 | qWarning() << "No department information available"; | ||
175 | 438 | return; | ||
176 | 439 | } | ||
177 | 440 | |||
178 | 441 | auto subdepts = rootdep->sub_departments(); | ||
179 | 442 | auto root = populate_departments(subdepts, ""); | ||
180 | 443 | push_departments(searchReply, root); | ||
181 | 444 | } | ||
182 | 445 | |||
183 | 432 | // | 446 | // |
184 | 433 | // push highlights and departments | 447 | // push highlights and departments |
185 | 434 | // use cached highlights for root department, otherwise run an async job for highlights of current department. | 448 | // use cached highlights for root department, otherwise run an async job for highlights of current department. |
186 | @@ -559,7 +573,8 @@ | |||
187 | 559 | else | 573 | else |
188 | 560 | { | 574 | { |
189 | 561 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); | 575 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
191 | 562 | impl->search_operation = impl->index.search(query().query_string(), search_cb); | 576 | push_departments(searchReply); |
192 | 577 | impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); | ||
193 | 563 | } | 578 | } |
194 | 564 | } | 579 | } |
195 | 565 | }); | 580 | }); |
196 | @@ -573,7 +588,8 @@ | |||
197 | 573 | else // normal search | 588 | else // normal search |
198 | 574 | { | 589 | { |
199 | 575 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); | 590 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
201 | 576 | impl->search_operation = impl->index.search(query().query_string(), search_cb); | 591 | push_departments(searchReply); |
202 | 592 | impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); | ||
203 | 577 | } | 593 | } |
204 | 578 | } | 594 | } |
205 | 579 | }); | 595 | }); |
206 | 580 | 596 | ||
207 | === modified file 'scope/clickstore/store-query.h' | |||
208 | --- scope/clickstore/store-query.h 2015-11-24 18:23:23 +0000 | |||
209 | +++ scope/clickstore/store-query.h 2016-03-09 13:08:23 +0000 | |||
210 | @@ -88,6 +88,7 @@ | |||
211 | 88 | virtual unity::scopes::Department::SPtr populate_departments(const click::DepartmentList& depts, const std::string& current_department_id); | 88 | virtual unity::scopes::Department::SPtr populate_departments(const click::DepartmentList& depts, const std::string& current_department_id); |
212 | 89 | virtual void store_departments(const click::DepartmentList& depts); | 89 | virtual void store_departments(const click::DepartmentList& depts); |
213 | 90 | virtual void push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root); | 90 | virtual void push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root); |
214 | 91 | virtual void push_departments(scopes::SearchReplyProxy const& searchReply); | ||
215 | 91 | virtual void add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& installedPackages); | 92 | virtual void add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& installedPackages); |
216 | 92 | virtual void add_available_apps(const scopes::SearchReplyProxy &searchReply, const PackageSet &installedPackages, const std::string &category); | 93 | virtual void add_available_apps(const scopes::SearchReplyProxy &searchReply, const PackageSet &installedPackages, const std::string &category); |
217 | 93 | virtual click::Interface& clickInterfaceInstance(); | 94 | virtual click::Interface& clickInterfaceInstance(); |
218 | 94 | 95 | ||
219 | === modified file 'scope/tests/test_apps_query.cpp' | |||
220 | --- scope/tests/test_apps_query.cpp 2016-02-19 03:35:43 +0000 | |||
221 | +++ scope/tests/test_apps_query.cpp 2016-03-09 13:08:23 +0000 | |||
222 | @@ -172,24 +172,6 @@ | |||
223 | 172 | q.add_fake_store_app(reply); | 172 | q.add_fake_store_app(reply); |
224 | 173 | } | 173 | } |
225 | 174 | 174 | ||
226 | 175 | // this matcher expects a list of department ids in depts: | ||
227 | 176 | // first on the list is the root, followed by children ids. | ||
228 | 177 | // the arg of the matcher is unity::scopes::Department ptr. | ||
229 | 178 | MATCHER_P(MatchesDepartments, depts, "") { | ||
230 | 179 | auto it = depts.begin(); | ||
231 | 180 | if (arg->id() != *it) | ||
232 | 181 | return false; | ||
233 | 182 | auto const subdeps = arg->subdepartments(); | ||
234 | 183 | if (subdeps.size() != depts.size() - 1) | ||
235 | 184 | return false; | ||
236 | 185 | for (auto const& sub: subdeps) | ||
237 | 186 | { | ||
238 | 187 | if (sub->id() != *(++it)) | ||
239 | 188 | return false; | ||
240 | 189 | } | ||
241 | 190 | return true; | ||
242 | 191 | } | ||
243 | 192 | |||
244 | 193 | class DepartmentsTest : public ::testing::Test { | 175 | class DepartmentsTest : public ::testing::Test { |
245 | 194 | protected: | 176 | protected: |
246 | 195 | virtual void SetUp() override | 177 | virtual void SetUp() override |
247 | @@ -323,3 +305,37 @@ | |||
248 | 323 | q.run(reply); | 305 | q.run(reply); |
249 | 324 | } | 306 | } |
250 | 325 | } | 307 | } |
251 | 308 | |||
252 | 309 | TEST_F(DepartmentsTest, testSearchInDepartment) | ||
253 | 310 | { | ||
254 | 311 | auto clickif = std::make_shared<MockClickInterface>(); | ||
255 | 312 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | ||
256 | 313 | auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:", true); | ||
257 | 314 | |||
258 | 315 | // query for a leaf department | ||
259 | 316 | { | ||
260 | 317 | const unity::scopes::CannedQuery query("foo.scope", "Fooo", "games"); | ||
261 | 318 | |||
262 | 319 | MockAppsQuery q(query, depts_db, metadata, clickif); | ||
263 | 320 | |||
264 | 321 | scopes::testing::MockSearchReply mock_reply; | ||
265 | 322 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
266 | 323 | |||
267 | 324 | std::list<std::string> expected_departments({"", "games"}); | ||
268 | 325 | |||
269 | 326 | EXPECT_CALL(*clickif, find_installed_apps("Fooo", _, "games", _)).WillOnce(Return(installed_apps)); | ||
270 | 327 | EXPECT_CALL(mock_reply, register_category("local", StrEq(""), _, _)).WillOnce(Return(ptrCat)); | ||
271 | 328 | EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat)); | ||
272 | 329 | EXPECT_CALL(*depts_db, get_department_name("games", expected_locales)).WillOnce(Return("Games")); | ||
273 | 330 | EXPECT_CALL(*depts_db, get_children_departments("games")).WillOnce(Return( | ||
274 | 331 | std::list<click::DepartmentsDb::DepartmentInfo>({}) | ||
275 | 332 | )); | ||
276 | 333 | |||
277 | 334 | EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments))); | ||
278 | 335 | |||
279 | 336 | EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(3).WillRepeatedly(Return(true)); | ||
280 | 337 | |||
281 | 338 | q.run(reply); | ||
282 | 339 | } | ||
283 | 340 | |||
284 | 341 | } | ||
285 | 326 | 342 | ||
286 | === modified file 'scope/tests/test_helpers.h' | |||
287 | --- scope/tests/test_helpers.h 2014-08-07 15:34:47 +0000 | |||
288 | +++ scope/tests/test_helpers.h 2016-03-09 13:08:23 +0000 | |||
289 | @@ -6,6 +6,7 @@ | |||
290 | 6 | #include "click/index.h" | 6 | #include "click/index.h" |
291 | 7 | #include <click/interface.h> | 7 | #include <click/interface.h> |
292 | 8 | #include <click/package.h> | 8 | #include <click/package.h> |
293 | 9 | #include <gtest/gtest.h> | ||
294 | 9 | 10 | ||
295 | 10 | namespace click | 11 | namespace click |
296 | 11 | { | 12 | { |
297 | @@ -16,6 +17,23 @@ | |||
298 | 16 | static const std::string FAKE_QUERY {"FAKE_QUERY"}; | 17 | static const std::string FAKE_QUERY {"FAKE_QUERY"}; |
299 | 17 | static const std::string FAKE_CATEGORY_TEMPLATE {"{}"}; | 18 | static const std::string FAKE_CATEGORY_TEMPLATE {"{}"}; |
300 | 18 | 19 | ||
301 | 20 | // this matcher expects a list of department ids in depts: | ||
302 | 21 | // first on the list is the root, followed by children ids. | ||
303 | 22 | // the arg of the matcher is unity::scopes::Department ptr. | ||
304 | 23 | MATCHER_P(MatchesDepartments, depts, "") { | ||
305 | 24 | auto it = depts.begin(); | ||
306 | 25 | if (arg->id() != *it) | ||
307 | 26 | return false; | ||
308 | 27 | auto const subdeps = arg->subdepartments(); | ||
309 | 28 | if (subdeps.size() != depts.size() - 1) | ||
310 | 29 | return false; | ||
311 | 30 | for (auto const& sub: subdeps) | ||
312 | 31 | { | ||
313 | 32 | if (sub->id() != *(++it)) | ||
314 | 33 | return false; | ||
315 | 34 | } | ||
316 | 35 | return true; | ||
317 | 36 | } | ||
318 | 19 | 37 | ||
319 | 20 | class MockIndex : public click::Index { | 38 | class MockIndex : public click::Index { |
320 | 21 | click::Packages packages; | 39 | click::Packages packages; |
321 | @@ -35,9 +53,9 @@ | |||
322 | 35 | 53 | ||
323 | 36 | } | 54 | } |
324 | 37 | 55 | ||
326 | 38 | click::web::Cancellable search(const std::string &query, std::function<void (click::Packages, click::Packages)> callback) override | 56 | click::web::Cancellable search(const std::string &query, const std::string &department, std::function<void (click::Packages, click::Packages)> callback) override |
327 | 39 | { | 57 | { |
329 | 40 | do_search(query, callback); | 58 | do_search(query, department, callback); |
330 | 41 | callback(packages, recommends); | 59 | callback(packages, recommends); |
331 | 42 | return click::web::Cancellable(); | 60 | return click::web::Cancellable(); |
332 | 43 | } | 61 | } |
333 | @@ -48,8 +66,8 @@ | |||
334 | 48 | return click::web::Cancellable(); | 66 | return click::web::Cancellable(); |
335 | 49 | } | 67 | } |
336 | 50 | 68 | ||
339 | 51 | MOCK_METHOD2(do_search, | 69 | MOCK_METHOD3(do_search, |
340 | 52 | void(const std::string&, | 70 | void(const std::string&, const std::string&, |
341 | 53 | std::function<void(click::Packages, click::Packages)>)); | 71 | std::function<void(click::Packages, click::Packages)>)); |
342 | 54 | }; | 72 | }; |
343 | 55 | 73 | ||
344 | 56 | 74 | ||
345 | === modified file 'scope/tests/test_query.cpp' | |||
346 | --- scope/tests/test_query.cpp 2015-07-31 20:06:49 +0000 | |||
347 | +++ scope/tests/test_query.cpp 2016-03-09 13:08:23 +0000 | |||
348 | @@ -141,7 +141,7 @@ | |||
349 | 141 | PackageSet no_installed_packages; | 141 | PackageSet no_installed_packages; |
350 | 142 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 142 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
351 | 143 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 143 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
353 | 144 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)).Times(1); | 144 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)).Times(1); |
354 | 145 | 145 | ||
355 | 146 | scopes::testing::MockSearchReply mock_reply; | 146 | scopes::testing::MockSearchReply mock_reply; |
356 | 147 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | 147 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); |
357 | @@ -168,7 +168,7 @@ | |||
358 | 168 | PackageSet no_installed_packages; | 168 | PackageSet no_installed_packages; |
359 | 169 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 169 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
360 | 170 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 170 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
362 | 171 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 171 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
363 | 172 | 172 | ||
364 | 173 | scopes::CategoryRenderer renderer("{}"); | 173 | scopes::CategoryRenderer renderer("{}"); |
365 | 174 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 174 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
366 | @@ -199,7 +199,7 @@ | |||
367 | 199 | PackageSet no_installed_packages; | 199 | PackageSet no_installed_packages; |
368 | 200 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 200 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
369 | 201 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 201 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
371 | 202 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 202 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
372 | 203 | 203 | ||
373 | 204 | scopes::CategoryRenderer renderer("{}"); | 204 | scopes::CategoryRenderer renderer("{}"); |
374 | 205 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 205 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
375 | @@ -254,7 +254,7 @@ | |||
376 | 254 | MockPayPackage pay_pkg; | 254 | MockPayPackage pay_pkg; |
377 | 255 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 255 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
378 | 256 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 256 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
380 | 257 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 257 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
381 | 258 | 258 | ||
382 | 259 | scopes::CategoryRenderer renderer("{}"); | 259 | scopes::CategoryRenderer renderer("{}"); |
383 | 260 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 260 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
384 | @@ -286,7 +286,7 @@ | |||
385 | 286 | MockPayPackage pay_pkg; | 286 | MockPayPackage pay_pkg; |
386 | 287 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 287 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
387 | 288 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 288 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
389 | 289 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 289 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
390 | 290 | 290 | ||
391 | 291 | scopes::CategoryRenderer renderer("{}"); | 291 | scopes::CategoryRenderer renderer("{}"); |
392 | 292 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 292 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
393 | @@ -325,7 +325,7 @@ | |||
394 | 325 | MockPayPackage pay_pkg; | 325 | MockPayPackage pay_pkg; |
395 | 326 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 326 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
396 | 327 | MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata, pay_pkg); | 327 | MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata, pay_pkg); |
398 | 328 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 328 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
399 | 329 | 329 | ||
400 | 330 | scopes::CategoryRenderer renderer("{}"); | 330 | scopes::CategoryRenderer renderer("{}"); |
401 | 331 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 331 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
402 | @@ -337,6 +337,34 @@ | |||
403 | 337 | q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE); | 337 | q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE); |
404 | 338 | } | 338 | } |
405 | 339 | 339 | ||
406 | 340 | TEST(QueryTest, testSearchInDepartment) | ||
407 | 341 | { | ||
408 | 342 | auto dept1 = std::make_shared<click::Department>("1", "Department one", "http://one.com", true); | ||
409 | 343 | DepartmentList init_departments({dept1}); | ||
410 | 344 | auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:", true); | ||
411 | 345 | |||
412 | 346 | MockIndex mock_index(click::Packages(), click::DepartmentList(), init_departments); | ||
413 | 347 | scopes::SearchMetadata metadata("en_EN", "phone"); | ||
414 | 348 | |||
415 | 349 | click::DepartmentLookup dept_lookup; | ||
416 | 350 | click::HighlightList highlights; | ||
417 | 351 | MockPayPackage pay_pkg; | ||
418 | 352 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "1"); | ||
419 | 353 | MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata, pay_pkg); | ||
420 | 354 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, "1", _)); | ||
421 | 355 | |||
422 | 356 | scopes::CategoryRenderer renderer("{}"); | ||
423 | 357 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | ||
424 | 358 | EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat)); | ||
425 | 359 | |||
426 | 360 | std::list<std::string> expected_departments({"", "1"}); | ||
427 | 361 | scopes::testing::MockSearchReply mock_reply; | ||
428 | 362 | EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments))); | ||
429 | 363 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
430 | 364 | EXPECT_CALL(q, finished(_)).Times(1); | ||
431 | 365 | q.wrap_add_available_apps(reply, PackageSet(), FAKE_CATEGORY_TEMPLATE); | ||
432 | 366 | } | ||
433 | 367 | |||
434 | 340 | class FakeInterface : public click::Interface | 368 | class FakeInterface : public click::Interface |
435 | 341 | { | 369 | { |
436 | 342 | public: | 370 | public: |
437 | @@ -385,7 +413,7 @@ | |||
438 | 385 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 413 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
439 | 386 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 414 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
440 | 387 | q.purchased_apps.insert({"name"}); | 415 | q.purchased_apps.insert({"name"}); |
442 | 388 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 416 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
443 | 389 | 417 | ||
444 | 390 | scopes::CategoryRenderer renderer("{}"); | 418 | scopes::CategoryRenderer renderer("{}"); |
445 | 391 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 419 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
446 | @@ -421,7 +449,7 @@ | |||
447 | 421 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 449 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
448 | 422 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 450 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
449 | 423 | q.purchased_apps.insert({"name"}); | 451 | q.purchased_apps.insert({"name"}); |
451 | 424 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 452 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
452 | 425 | 453 | ||
453 | 426 | scopes::CategoryRenderer renderer("{}"); | 454 | scopes::CategoryRenderer renderer("{}"); |
454 | 427 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 455 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
455 | @@ -456,7 +484,7 @@ | |||
456 | 456 | MockPayPackage pay_pkg; | 484 | MockPayPackage pay_pkg; |
457 | 457 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 485 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
458 | 458 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 486 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
460 | 459 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 487 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
461 | 460 | 488 | ||
462 | 461 | scopes::CategoryRenderer renderer("{}"); | 489 | scopes::CategoryRenderer renderer("{}"); |
463 | 462 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 490 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
464 | @@ -488,7 +516,7 @@ | |||
465 | 488 | MockPayPackage pay_pkg; | 516 | MockPayPackage pay_pkg; |
466 | 489 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 517 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
467 | 490 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 518 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
469 | 491 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 519 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
470 | 492 | 520 | ||
471 | 493 | scopes::CategoryRenderer renderer("{}"); | 521 | scopes::CategoryRenderer renderer("{}"); |
472 | 494 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 522 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
473 | @@ -521,7 +549,7 @@ | |||
474 | 521 | MockPayPackage pay_pkg; | 549 | MockPayPackage pay_pkg; |
475 | 522 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 550 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
476 | 523 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 551 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
478 | 524 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 552 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
479 | 525 | 553 | ||
480 | 526 | scopes::CategoryRenderer renderer("{}"); | 554 | scopes::CategoryRenderer renderer("{}"); |
481 | 527 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 555 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
482 | @@ -617,7 +645,7 @@ | |||
483 | 617 | MockPayPackage pay_pkg; | 645 | MockPayPackage pay_pkg; |
484 | 618 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 646 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
485 | 619 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); | 647 | MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
487 | 620 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 648 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
488 | 621 | 649 | ||
489 | 622 | scopes::CategoryRenderer renderer("{}"); | 650 | scopes::CategoryRenderer renderer("{}"); |
490 | 623 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 651 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
491 | 624 | 652 | ||
492 | === modified file 'tests/scope-harness/tests/test_apps.py' | |||
493 | --- tests/scope-harness/tests/test_apps.py 2015-06-22 17:05:41 +0000 | |||
494 | +++ tests/scope-harness/tests/test_apps.py 2016-03-09 13:08:23 +0000 | |||
495 | @@ -107,7 +107,6 @@ | |||
496 | 107 | departments = self.view.browse_department('') | 107 | departments = self.view.browse_department('') |
497 | 108 | 108 | ||
498 | 109 | self.assertTrue(self.view.has_departments) | 109 | self.assertTrue(self.view.has_departments) |
499 | 110 | self.assertFalse(self.view.has_alt_departments) | ||
500 | 111 | 110 | ||
501 | 112 | # TODO: list all expected departments (depending on installed apps) | 111 | # TODO: list all expected departments (depending on installed apps) |
502 | 113 | match = DepartmentMatcher() \ | 112 | match = DepartmentMatcher() \ |
503 | 114 | 113 | ||
504 | === modified file 'tests/scope-harness/tests/test_store.py' | |||
505 | --- tests/scope-harness/tests/test_store.py 2015-04-03 18:33:10 +0000 | |||
506 | +++ tests/scope-harness/tests/test_store.py 2016-03-09 13:08:23 +0000 | |||
507 | @@ -111,7 +111,6 @@ | |||
508 | 111 | departments = self.view.browse_department('') | 111 | departments = self.view.browse_department('') |
509 | 112 | 112 | ||
510 | 113 | self.assertTrue(self.view.has_departments) | 113 | self.assertTrue(self.view.has_departments) |
511 | 114 | self.assertFalse(self.view.has_alt_departments) | ||
512 | 115 | 114 | ||
513 | 116 | match = DepartmentMatcher() \ | 115 | match = DepartmentMatcher() \ |
514 | 117 | .mode(DepartmentMatcherMode.STARTS_WITH) \ | 116 | .mode(DepartmentMatcherMode.STARTS_WITH) \ |
FAILED: Continuous integration, rev:398 jenkins. qa.ubuntu. com/job/ unity-scope- click-ci/ 720/ jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- amd64-ci/ 124/console jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- armhf-ci/ 120/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scope-click- ci/720/ rebuild
http://