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

Proposed by Marcus Tomlinson on 2015-12-23
Status: Merged
Approved by: Alexandre Abreu on 2016-02-24
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) 2015-12-23 Approve on 2016-02-24
PS Jenkins bot (community) continuous-integration Approve on 2016-02-09
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 on 2015-12-23

Merged add-coverage

129. By Marcus Tomlinson on 2016-02-05

Add departments to owm_scope

130. By Marcus Tomlinson on 2016-02-05

Added department tests

131. By Marcus Tomlinson on 2016-02-09

Merged trunk

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/owm_scope/scope/CMakeLists.txt'
2--- tests/owm_scope/scope/CMakeLists.txt 2015-11-09 12:54:21 +0000
3+++ tests/owm_scope/scope/CMakeLists.txt 2016-02-09 05:10:07 +0000
4@@ -5,6 +5,12 @@
5 )
6
7 configure_file(
8+ "owm_scope-settings.ini"
9+ "${CMAKE_CURRENT_BINARY_DIR}/owm_scope-settings.ini"
10+ @ONLY COPYONLY
11+)
12+
13+configure_file(
14 "owm_scope.js"
15 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.js"
16 @ONLY COPYONLY
17
18=== added file 'tests/owm_scope/scope/owm_scope-settings.ini'
19--- tests/owm_scope/scope/owm_scope-settings.ini 1970-01-01 00:00:00 +0000
20+++ tests/owm_scope/scope/owm_scope-settings.ini 2016-02-09 05:10:07 +0000
21@@ -0,0 +1,4 @@
22+[forecast]
23+type = boolean
24+defaultValue = true
25+displayName = Enable Forecast
26
27=== modified file 'tests/owm_scope/scope/owm_scope.js'
28--- tests/owm_scope/scope/owm_scope.js 2015-11-09 12:54:21 +0000
29+++ tests/owm_scope/scope/owm_scope.js 2016-02-09 05:10:07 +0000
30@@ -79,6 +79,14 @@
31 qs = "London,uk"
32 }
33
34+ if (scopes.self.settings["forecast"].get_bool())
35+ {
36+ var root_department = new scopes.lib.Department("", canned_query, "Current + Forecast");
37+ root_department.add_subdepartment(new scopes.lib.Department("current", canned_query, "Current"));
38+ root_department.add_subdepartment(new scopes.lib.Department("forecast", canned_query, "Forecast"));
39+ search_reply.register_departments(root_department);
40+ }
41+
42 var current_weather_cb = function(response) {
43 var res = '';
44
45@@ -103,8 +111,21 @@
46
47 search_reply.push(categorised_result);
48
49- // Now call back into the API for a 7 day forecast
50- http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
51+ if (canned_query.department_id() === "current")
52+ {
53+ // We are done, call finished() on our search_reply
54+ search_reply.finished();
55+ }
56+ else if (scopes.self.settings["forecast"].get_bool())
57+ {
58+ // Now call back into the API for a 7 day forecast
59+ http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
60+ }
61+ else
62+ {
63+ // We are done, call finished() on our search_reply
64+ search_reply.finished();
65+ }
66 });
67 }
68
69@@ -149,7 +170,14 @@
70 });
71 }
72
73- http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();
74+ if (canned_query.department_id() === "forecast")
75+ {
76+ http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
77+ }
78+ else
79+ {
80+ http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();
81+ }
82 },
83 // cancelled
84 function() {
85
86=== modified file 'tests/owm_scope/tests/test-scope.py'
87--- tests/owm_scope/tests/test-scope.py 2015-11-09 15:15:46 +0000
88+++ tests/owm_scope/tests/test-scope.py 2016-02-09 05:10:07 +0000
89@@ -18,8 +18,10 @@
90 # MA 02110-1301 USA
91
92 from scope_harness import (
93- CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,
94- Parameters, ResultMatcher, ScopeHarness
95+ CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher, ChildDepartmentMatcher,
96+ DepartmentMatcher, DepartmentMatcherMode, Parameters, PreviewColumnMatcher,
97+ PreviewMatcher, PreviewView, PreviewWidgetMatcher, ResultMatcher, SettingsMatcher,
98+ SettingsMatcherMode, SettingsOptionMatcher, ScopeHarness
99 )
100 from scope_harness.testing import *
101 import unittest, sys, os
102@@ -141,6 +143,168 @@
103 .match(self.view.categories)
104 self.assertMatchResult(match)
105
106+ def test_settings_change(self):
107+ self.start_harness()
108+ settings = self.view.settings
109+
110+ self.assertMatchResult(
111+ SettingsMatcher()
112+ .mode(SettingsMatcherMode.BY_ID)
113+ .option(
114+ SettingsOptionMatcher("forecast")
115+ .value(True)
116+ )
117+ .match(settings)
118+ )
119+
120+ settings.set("forecast", False)
121+
122+ self.assertMatchResult(
123+ SettingsMatcher()
124+ .mode(SettingsMatcherMode.BY_ID)
125+ .option(
126+ SettingsOptionMatcher("forecast")
127+ .value(False)
128+ )
129+ .match(settings)
130+ )
131+
132+ def test_search_results_with_settings(self):
133+ self.start_harness()
134+ self.view.search_query = 'Manchester,uk'
135+
136+ settings = self.view.settings
137+ settings.set("forecast", False)
138+
139+ match = CategoryListMatcher() \
140+ .has_exactly(1) \
141+ .mode(CategoryListMatcherMode.BY_ID) \
142+ .category(CategoryMatcher("current") \
143+ .title("Manchester, GB") \
144+ .has_at_least(1) \
145+ .result(ResultMatcher("2643123") \
146+ .title("17.35°C") \
147+ .art("http://openweathermap.org/img/w/03d.png") \
148+ .subtitle("scattered clouds") ) ) \
149+ .match(self.view.categories)
150+ self.assertMatchResult(match)
151+
152+ def test_preview_layouts(self):
153+ self.start_harness()
154+ self.view.search_query = ''
155+
156+ pview = self.view.category(0).result(0).tap()
157+ self.assertIsInstance(pview, PreviewView)
158+
159+ pview.column_count = 1
160+ self.assertMatchResult(
161+ PreviewColumnMatcher()
162+ .column(PreviewMatcher()
163+ .widget(PreviewWidgetMatcher("image"))
164+ .widget(PreviewWidgetMatcher("header"))
165+ .widget(PreviewWidgetMatcher("summary"))
166+ ).match(pview.widgets))
167+
168+ pview.column_count = 2
169+ self.assertMatchResult(
170+ PreviewColumnMatcher()
171+ .column(PreviewMatcher()
172+ .widget(PreviewWidgetMatcher("image")))
173+ .column(PreviewMatcher()
174+ .widget(PreviewWidgetMatcher("header"))
175+ .widget(PreviewWidgetMatcher("summary"))
176+ ).match(pview.widgets))
177+
178+ pview.column_count = 3
179+ self.assertMatchResult(
180+ PreviewColumnMatcher()
181+ .column(PreviewMatcher()
182+ .widget(PreviewWidgetMatcher("image")))
183+ .column(PreviewMatcher()
184+ .widget(PreviewWidgetMatcher("header"))
185+ .widget(PreviewWidgetMatcher("summary")))
186+ .column(PreviewMatcher()
187+ ).match(pview.widgets))
188+
189+ def test_departments(self):
190+ self.start_harness()
191+ self.view.search_query = ''
192+
193+ assert(self.view.has_departments == True)
194+
195+ departments = self.view.browse_department('')
196+ self.assertMatchResult(
197+ DepartmentMatcher()
198+ .mode(DepartmentMatcherMode.STARTS_WITH)
199+ .id('')
200+ .label('Current + Forecast')
201+ .all_label('')
202+ .parent_id('')
203+ .parent_label('')
204+ .is_root(True)
205+ .is_hidden(False)
206+ .child(ChildDepartmentMatcher('current'))
207+ .child(ChildDepartmentMatcher('forecast'))
208+ .match(departments))
209+
210+ def test_departments_with_settings(self):
211+ self.start_harness()
212+ self.view.search_query = ''
213+
214+ settings = self.view.settings
215+ settings.set("forecast", False)
216+
217+ assert(self.view.has_departments == False)
218+
219+ def test_department_browsing(self):
220+ self.start_harness()
221+ self.view.search_query = ''
222+
223+ # Test "Current" department
224+
225+ departments = self.view.browse_department('current')
226+
227+ self.assertMatchResult(DepartmentMatcher()
228+ .has_exactly(0)
229+ .mode(DepartmentMatcherMode.STARTS_WITH)
230+ .label('Current')
231+ .all_label('')
232+ .parent_id('')
233+ .parent_label('Current + Forecast')
234+ .is_root(False)
235+ .is_hidden(False)
236+ .match(departments))
237+
238+ self.assertMatchResult(CategoryListMatcher()
239+ .has_exactly(1)
240+ .mode(CategoryListMatcherMode.BY_ID)
241+ .category(CategoryMatcher("current")
242+ .has_at_least(1)
243+ )
244+ .match(self.view.categories))
245+
246+ # Test "Forecast" department
247+
248+ departments = self.view.browse_department('forecast')
249+
250+ self.assertMatchResult(DepartmentMatcher()
251+ .has_exactly(0)
252+ .mode(DepartmentMatcherMode.STARTS_WITH)
253+ .label('Forecast')
254+ .all_label('')
255+ .parent_id('')
256+ .parent_label('Current + Forecast')
257+ .is_root(False)
258+ .is_hidden(False)
259+ .match(departments))
260+
261+ self.assertMatchResult(CategoryListMatcher()
262+ .has_exactly(1)
263+ .mode(CategoryListMatcherMode.BY_ID)
264+ .category(CategoryMatcher("forecast")
265+ .has_at_least(1)
266+ )
267+ .match(self.view.categories))
268
269 if __name__ == '__main__':
270 SCOPE_NAME = sys.argv[1]

Subscribers

People subscribed via source and target branches

to all changes: