Merge lp:~dobey/unity-scope-click/lowercase-query into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: Charles Kerr
Approved revision: 405
Merged at revision: 413
Proposed branch: lp:~dobey/unity-scope-click/lowercase-query
Merge into: lp:unity-scope-click
Diff against target: 265 lines (+98/-29)
4 files modified
libclickscope/click/index.cpp (+4/-2)
libclickscope/click/webclient.cpp (+5/-0)
libclickscope/click/webclient.h (+1/-0)
libclickscope/tests/test_index.cpp (+88/-27)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/lowercase-query
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+283554@code.launchpad.net

Commit message

Always convert query to lowercase.
Add operator override to read call params back out for testing.
Refactor tests to be able to test that query is lowercase.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
405. By dobey

[ Pawel Stolowski ]
* Support two column layouts in the previews. (LP: #1536372)
[ Rodney Dawes ]
* Avoid a race and crash by unlinking the callback inside the
  callback. (LP: #1486287)
* Only try to parse the JSON when we get a 200. (LP: #1531656)
* Remove reference to click in translated strings. (LP: #1536252)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Wily Jenkins failures not withstanding, LGTM.

review: Approve

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 2015-11-24 18:23:23 +0000
3+++ libclickscope/click/index.cpp 2016-02-01 16:10:29 +0000
4@@ -97,9 +97,11 @@
5
6 std::string Index::build_index_query(const std::string& query, const std::string& department)
7 {
8+ std::string lquery{query};
9+ std::transform(lquery.begin(), lquery.end(), lquery.begin(), ::tolower);
10+
11 std::stringstream result;
12-
13- result << query;
14+ result << lquery;
15 if (!department.empty()) {
16 result << ",department:" << department;
17 }
18
19=== modified file 'libclickscope/click/webclient.cpp'
20--- libclickscope/click/webclient.cpp 2016-01-21 20:43:16 +0000
21+++ libclickscope/click/webclient.cpp 2016-02-01 16:10:29 +0000
22@@ -42,6 +42,11 @@
23 query.addQueryItem(key.c_str(), value.c_str());
24 }
25
26+std::string click::web::CallParams::operator[](const std::string& key) const
27+{
28+ return query.queryItemValue(key.c_str()).toUtf8().data();
29+}
30+
31 bool click::web::CallParams::operator==(const CallParams &other) const
32 {
33 return (this->query == other.query);
34
35=== modified file 'libclickscope/click/webclient.h'
36--- libclickscope/click/webclient.h 2016-01-21 20:43:16 +0000
37+++ libclickscope/click/webclient.h 2016-02-01 16:10:29 +0000
38@@ -64,6 +64,7 @@
39 friend class Client;
40 public:
41 void add(const std::string& key, const std::string& value);
42+ std::string operator[](const std::string& key) const;
43 bool operator==(const CallParams &other) const;
44 };
45
46
47=== modified file 'libclickscope/tests/test_index.cpp'
48--- libclickscope/tests/test_index.cpp 2015-11-24 18:23:23 +0000
49+++ libclickscope/tests/test_index.cpp 2016-02-01 16:10:29 +0000
50@@ -44,6 +44,10 @@
51
52 namespace
53 {
54+ const std::string fake_arch{"fake_arch"};
55+ const std::string fake_fwk_1{"fake_fwk_1"};
56+ const std::string fake_fwk_2{"fake_fwk_2"};
57+ std::vector<std::string> fake_frameworks{fake_fwk_1, fake_fwk_2};
58
59 class MockableIndex : public click::Index {
60 public:
61@@ -53,8 +57,6 @@
62 click::Index(client, configuration)
63 {
64 }
65- MOCK_METHOD0(build_headers, std::map<std::string, std::string>());
66- MOCK_METHOD2(build_index_query, std::string(const std::string&, const std::string&));
67 };
68
69 class MockConfiguration : public click::Configuration {
70@@ -97,6 +99,12 @@
71 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
72 auto response = responseForReply(reply.asSharedPtr());
73
74+ EXPECT_CALL(*configPtr, get_architecture())
75+ .Times(1)
76+ .WillOnce(Return(fake_arch));
77+ EXPECT_CALL(*configPtr, get_available_frameworks())
78+ .Times(1)
79+ .WillOnce(Return(fake_frameworks));
80 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
81 .Times(1)
82 .WillOnce(Return(response));
83@@ -104,11 +112,41 @@
84 indexPtr->search("", [](click::Packages, click::Packages) {});
85 }
86
87+MATCHER_P(QueryContains, query, "")
88+{
89+ return arg["q"].find(query) != std::string::npos;
90+}
91+
92+TEST_F(IndexTest, testSearchQueryIsLowercase)
93+{
94+ LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
95+ auto response = responseForReply(reply.asSharedPtr());
96+
97+ EXPECT_CALL(*configPtr, get_architecture())
98+ .Times(1)
99+ .WillOnce(Return(fake_arch));
100+ EXPECT_CALL(*configPtr, get_available_frameworks())
101+ .Times(1)
102+ .WillOnce(Return(fake_frameworks));
103+ EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, QueryContains("foobar")))
104+ .Times(1)
105+ .WillOnce(Return(response));
106+
107+ indexPtr->search("FooBar", [](click::Packages, click::Packages) {});
108+}
109+
110+
111 TEST_F(IndexTest, testSearchSignsCall)
112 {
113 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
114 auto response = responseForReply(reply.asSharedPtr());
115
116+ EXPECT_CALL(*configPtr, get_architecture())
117+ .Times(1)
118+ .WillOnce(Return(fake_arch));
119+ EXPECT_CALL(*configPtr, get_available_frameworks())
120+ .Times(1)
121+ .WillOnce(Return(fake_frameworks));
122 EXPECT_CALL(*clientPtr, callImpl(_, _, true, _, _, _))
123 .Times(1)
124 .WillOnce(Return(response));
125@@ -121,6 +159,12 @@
126 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
127 auto response = responseForReply(reply.asSharedPtr());
128
129+ EXPECT_CALL(*configPtr, get_architecture())
130+ .Times(1)
131+ .WillOnce(Return(fake_arch));
132+ EXPECT_CALL(*configPtr, get_available_frameworks())
133+ .Times(1)
134+ .WillOnce(Return(fake_frameworks));
135 EXPECT_CALL(*clientPtr, callImpl(_, _, true, _, _, _))
136 .Times(1)
137 .WillOnce(Return(response));
138@@ -133,6 +177,12 @@
139 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
140 auto response = responseForReply(reply.asSharedPtr());
141
142+ EXPECT_CALL(*configPtr, get_architecture())
143+ .Times(1)
144+ .WillOnce(Return(fake_arch));
145+ EXPECT_CALL(*configPtr, get_available_frameworks())
146+ .Times(1)
147+ .WillOnce(Return(fake_frameworks));
148 EXPECT_CALL(*clientPtr, callImpl(_, _, true, _, _, _))
149 .Times(1)
150 .WillOnce(Return(response));
151@@ -140,31 +190,17 @@
152 indexPtr->departments("departments", [](const click::DepartmentList&, const click::HighlightList&, click::Index::Error, int) {});
153 }
154
155-TEST_F(IndexTest, testSearchSendsBuiltQueryAsParam)
156-{
157- const std::string FAKE_BUILT_QUERY = "FAKE_QUERY,frameworks:fake-14.04,architecture:fake-arch";
158-
159- LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
160- auto response = responseForReply(reply.asSharedPtr());
161-
162- click::web::CallParams params;
163- params.add(click::QUERY_ARGNAME, FAKE_BUILT_QUERY);
164- EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, params))
165- .Times(1)
166- .WillOnce(Return(response));
167-
168- EXPECT_CALL(*indexPtr, build_index_query(FAKE_QUERY, ""))
169- .Times(1)
170- .WillOnce(Return(FAKE_BUILT_QUERY));
171-
172- indexPtr->search(FAKE_QUERY, [](click::Packages, click::Packages) {});
173-}
174-
175 TEST_F(IndexTest, testSearchSendsRightPath)
176 {
177 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
178 auto response = responseForReply(reply.asSharedPtr());
179
180+ EXPECT_CALL(*configPtr, get_architecture())
181+ .Times(1)
182+ .WillOnce(Return(fake_arch));
183+ EXPECT_CALL(*configPtr, get_available_frameworks())
184+ .Times(1)
185+ .WillOnce(Return(fake_frameworks));
186 EXPECT_CALL(*clientPtr, callImpl(EndsWith(click::SEARCH_PATH),
187 _, _, _, _, _))
188 .Times(1)
189@@ -182,6 +218,12 @@
190 EXPECT_CALL(reply.instance, readAll())
191 .Times(1)
192 .WillOnce(Return(fake_json));
193+ EXPECT_CALL(*configPtr, get_architecture())
194+ .Times(1)
195+ .WillOnce(Return(fake_arch));
196+ EXPECT_CALL(*configPtr, get_available_frameworks())
197+ .Times(1)
198+ .WillOnce(Return(fake_frameworks));
199 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
200 .Times(1)
201 .WillOnce(Return(response));
202@@ -203,6 +245,12 @@
203 EXPECT_CALL(reply.instance, readAll())
204 .Times(1)
205 .WillOnce(Return(fake_json));
206+ EXPECT_CALL(*configPtr, get_architecture())
207+ .Times(1)
208+ .WillOnce(Return(fake_arch));
209+ EXPECT_CALL(*configPtr, get_available_frameworks())
210+ .Times(1)
211+ .WillOnce(Return(fake_frameworks));
212 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
213 .Times(1)
214 .WillOnce(Return(response));
215@@ -225,6 +273,12 @@
216 EXPECT_CALL(reply.instance, readAll())
217 .Times(1)
218 .WillOnce(Return(fake_json));
219+ EXPECT_CALL(*configPtr, get_architecture())
220+ .Times(1)
221+ .WillOnce(Return(fake_arch));
222+ EXPECT_CALL(*configPtr, get_available_frameworks())
223+ .Times(1)
224+ .WillOnce(Return(fake_frameworks));
225 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
226 .Times(1)
227 .WillOnce(Return(response));
228@@ -251,6 +305,12 @@
229 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
230 auto response = responseForReply(reply.asSharedPtr());
231
232+ EXPECT_CALL(*configPtr, get_architecture())
233+ .Times(1)
234+ .WillOnce(Return(fake_arch));
235+ EXPECT_CALL(*configPtr, get_available_frameworks())
236+ .Times(1)
237+ .WillOnce(Return(fake_frameworks));
238 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
239 .Times(1)
240 .WillOnce(Return(response));
241@@ -271,6 +331,12 @@
242 LifetimeHelper<click::network::Reply, MockNetworkReply> reply;
243 auto response = responseForReply(reply.asSharedPtr());
244
245+ EXPECT_CALL(*configPtr, get_architecture())
246+ .Times(1)
247+ .WillOnce(Return(fake_arch));
248+ EXPECT_CALL(*configPtr, get_available_frameworks())
249+ .Times(1)
250+ .WillOnce(Return(fake_frameworks));
251 EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _))
252 .Times(1)
253 .WillOnce(Return(response));
254@@ -560,11 +626,6 @@
255
256 class QueryStringTest : public ::testing::Test {
257 protected:
258- const std::string fake_arch{"fake_arch"};
259- const std::string fake_fwk_1{"fake_fwk_1"};
260- const std::string fake_fwk_2{"fake_fwk_2"};
261- std::vector<std::string> fake_frameworks{fake_fwk_1, fake_fwk_2};
262-
263 QSharedPointer<MockClient> clientPtr;
264 QSharedPointer<MockNetworkAccessManager> namPtr;
265 QSharedPointer<MockConfiguration> configPtr;

Subscribers

People subscribed via source and target branches

to all changes: