Merge lp:~marcustomlinson/unity-js-scopes/flesh-out-owm-tests into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 131
Merged at revision: 136
Proposed branch: lp:~marcustomlinson/unity-js-scopes/flesh-out-owm-tests
Merge into: lp:unity-js-scopes
Prerequisite: lp:~marcustomlinson/unity-js-scopes/add-coverage
Diff against target: 270 lines (+207/-5)
4 files modified
tests/owm_scope/scope/CMakeLists.txt (+6/-0)
tests/owm_scope/scope/owm_scope-settings.ini (+4/-0)
tests/owm_scope/scope/owm_scope.js (+31/-3)
tests/owm_scope/tests/test-scope.py (+166/-2)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/flesh-out-owm-tests
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+281277@code.launchpad.net

Commit message

Fleshed out OWM test scope to include a regression test for recent settings bug as well as missing tests for departments and previews

To post a comment you must log in.
128. By Marcus Tomlinson

Merged add-coverage

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
129. By Marcus Tomlinson

Add departments to owm_scope

130. By Marcus Tomlinson

Added department tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
131. By Marcus Tomlinson

Merged trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/owm_scope/scope/CMakeLists.txt'
--- tests/owm_scope/scope/CMakeLists.txt 2015-11-09 12:54:21 +0000
+++ tests/owm_scope/scope/CMakeLists.txt 2016-02-09 05:10:07 +0000
@@ -5,6 +5,12 @@
5)5)
66
7configure_file(7configure_file(
8 "owm_scope-settings.ini"
9 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope-settings.ini"
10 @ONLY COPYONLY
11)
12
13configure_file(
8 "owm_scope.js"14 "owm_scope.js"
9 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.js"15 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.js"
10 @ONLY COPYONLY16 @ONLY COPYONLY
1117
=== added file 'tests/owm_scope/scope/owm_scope-settings.ini'
--- tests/owm_scope/scope/owm_scope-settings.ini 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/scope/owm_scope-settings.ini 2016-02-09 05:10:07 +0000
@@ -0,0 +1,4 @@
1[forecast]
2type = boolean
3defaultValue = true
4displayName = Enable Forecast
05
=== modified file 'tests/owm_scope/scope/owm_scope.js'
--- tests/owm_scope/scope/owm_scope.js 2015-11-09 12:54:21 +0000
+++ tests/owm_scope/scope/owm_scope.js 2016-02-09 05:10:07 +0000
@@ -79,6 +79,14 @@
79 qs = "London,uk"79 qs = "London,uk"
80 }80 }
8181
82 if (scopes.self.settings["forecast"].get_bool())
83 {
84 var root_department = new scopes.lib.Department("", canned_query, "Current + Forecast");
85 root_department.add_subdepartment(new scopes.lib.Department("current", canned_query, "Current"));
86 root_department.add_subdepartment(new scopes.lib.Department("forecast", canned_query, "Forecast"));
87 search_reply.register_departments(root_department);
88 }
89
82 var current_weather_cb = function(response) {90 var current_weather_cb = function(response) {
83 var res = '';91 var res = '';
8492
@@ -103,8 +111,21 @@
103111
104 search_reply.push(categorised_result);112 search_reply.push(categorised_result);
105113
106 // Now call back into the API for a 7 day forecast114 if (canned_query.department_id() === "current")
107 http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();115 {
116 // We are done, call finished() on our search_reply
117 search_reply.finished();
118 }
119 else if (scopes.self.settings["forecast"].get_bool())
120 {
121 // Now call back into the API for a 7 day forecast
122 http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
123 }
124 else
125 {
126 // We are done, call finished() on our search_reply
127 search_reply.finished();
128 }
108 });129 });
109 }130 }
110131
@@ -149,7 +170,14 @@
149 });170 });
150 }171 }
151172
152 http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();173 if (canned_query.department_id() === "forecast")
174 {
175 http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
176 }
177 else
178 {
179 http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();
180 }
153 },181 },
154 // cancelled182 // cancelled
155 function() {183 function() {
156184
=== modified file 'tests/owm_scope/tests/test-scope.py'
--- tests/owm_scope/tests/test-scope.py 2015-11-09 15:15:46 +0000
+++ tests/owm_scope/tests/test-scope.py 2016-02-09 05:10:07 +0000
@@ -18,8 +18,10 @@
18# MA 02110-1301 USA18# MA 02110-1301 USA
1919
20from scope_harness import (20from scope_harness import (
21 CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,21 CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher, ChildDepartmentMatcher,
22 Parameters, ResultMatcher, ScopeHarness22 DepartmentMatcher, DepartmentMatcherMode, Parameters, PreviewColumnMatcher,
23 PreviewMatcher, PreviewView, PreviewWidgetMatcher, ResultMatcher, SettingsMatcher,
24 SettingsMatcherMode, SettingsOptionMatcher, ScopeHarness
23)25)
24from scope_harness.testing import *26from scope_harness.testing import *
25import unittest, sys, os27import unittest, sys, os
@@ -141,6 +143,168 @@
141 .match(self.view.categories)143 .match(self.view.categories)
142 self.assertMatchResult(match)144 self.assertMatchResult(match)
143145
146 def test_settings_change(self):
147 self.start_harness()
148 settings = self.view.settings
149
150 self.assertMatchResult(
151 SettingsMatcher()
152 .mode(SettingsMatcherMode.BY_ID)
153 .option(
154 SettingsOptionMatcher("forecast")
155 .value(True)
156 )
157 .match(settings)
158 )
159
160 settings.set("forecast", False)
161
162 self.assertMatchResult(
163 SettingsMatcher()
164 .mode(SettingsMatcherMode.BY_ID)
165 .option(
166 SettingsOptionMatcher("forecast")
167 .value(False)
168 )
169 .match(settings)
170 )
171
172 def test_search_results_with_settings(self):
173 self.start_harness()
174 self.view.search_query = 'Manchester,uk'
175
176 settings = self.view.settings
177 settings.set("forecast", False)
178
179 match = CategoryListMatcher() \
180 .has_exactly(1) \
181 .mode(CategoryListMatcherMode.BY_ID) \
182 .category(CategoryMatcher("current") \
183 .title("Manchester, GB") \
184 .has_at_least(1) \
185 .result(ResultMatcher("2643123") \
186 .title("17.35°C") \
187 .art("http://openweathermap.org/img/w/03d.png") \
188 .subtitle("scattered clouds") ) ) \
189 .match(self.view.categories)
190 self.assertMatchResult(match)
191
192 def test_preview_layouts(self):
193 self.start_harness()
194 self.view.search_query = ''
195
196 pview = self.view.category(0).result(0).tap()
197 self.assertIsInstance(pview, PreviewView)
198
199 pview.column_count = 1
200 self.assertMatchResult(
201 PreviewColumnMatcher()
202 .column(PreviewMatcher()
203 .widget(PreviewWidgetMatcher("image"))
204 .widget(PreviewWidgetMatcher("header"))
205 .widget(PreviewWidgetMatcher("summary"))
206 ).match(pview.widgets))
207
208 pview.column_count = 2
209 self.assertMatchResult(
210 PreviewColumnMatcher()
211 .column(PreviewMatcher()
212 .widget(PreviewWidgetMatcher("image")))
213 .column(PreviewMatcher()
214 .widget(PreviewWidgetMatcher("header"))
215 .widget(PreviewWidgetMatcher("summary"))
216 ).match(pview.widgets))
217
218 pview.column_count = 3
219 self.assertMatchResult(
220 PreviewColumnMatcher()
221 .column(PreviewMatcher()
222 .widget(PreviewWidgetMatcher("image")))
223 .column(PreviewMatcher()
224 .widget(PreviewWidgetMatcher("header"))
225 .widget(PreviewWidgetMatcher("summary")))
226 .column(PreviewMatcher()
227 ).match(pview.widgets))
228
229 def test_departments(self):
230 self.start_harness()
231 self.view.search_query = ''
232
233 assert(self.view.has_departments == True)
234
235 departments = self.view.browse_department('')
236 self.assertMatchResult(
237 DepartmentMatcher()
238 .mode(DepartmentMatcherMode.STARTS_WITH)
239 .id('')
240 .label('Current + Forecast')
241 .all_label('')
242 .parent_id('')
243 .parent_label('')
244 .is_root(True)
245 .is_hidden(False)
246 .child(ChildDepartmentMatcher('current'))
247 .child(ChildDepartmentMatcher('forecast'))
248 .match(departments))
249
250 def test_departments_with_settings(self):
251 self.start_harness()
252 self.view.search_query = ''
253
254 settings = self.view.settings
255 settings.set("forecast", False)
256
257 assert(self.view.has_departments == False)
258
259 def test_department_browsing(self):
260 self.start_harness()
261 self.view.search_query = ''
262
263 # Test "Current" department
264
265 departments = self.view.browse_department('current')
266
267 self.assertMatchResult(DepartmentMatcher()
268 .has_exactly(0)
269 .mode(DepartmentMatcherMode.STARTS_WITH)
270 .label('Current')
271 .all_label('')
272 .parent_id('')
273 .parent_label('Current + Forecast')
274 .is_root(False)
275 .is_hidden(False)
276 .match(departments))
277
278 self.assertMatchResult(CategoryListMatcher()
279 .has_exactly(1)
280 .mode(CategoryListMatcherMode.BY_ID)
281 .category(CategoryMatcher("current")
282 .has_at_least(1)
283 )
284 .match(self.view.categories))
285
286 # Test "Forecast" department
287
288 departments = self.view.browse_department('forecast')
289
290 self.assertMatchResult(DepartmentMatcher()
291 .has_exactly(0)
292 .mode(DepartmentMatcherMode.STARTS_WITH)
293 .label('Forecast')
294 .all_label('')
295 .parent_id('')
296 .parent_label('Current + Forecast')
297 .is_root(False)
298 .is_hidden(False)
299 .match(departments))
300
301 self.assertMatchResult(CategoryListMatcher()
302 .has_exactly(1)
303 .mode(CategoryListMatcherMode.BY_ID)
304 .category(CategoryMatcher("forecast")
305 .has_at_least(1)
306 )
307 .match(self.view.categories))
144308
145if __name__ == '__main__':309if __name__ == '__main__':
146 SCOPE_NAME = sys.argv[1]310 SCOPE_NAME = sys.argv[1]

Subscribers

People subscribed via source and target branches

to all changes: