Merge lp:~marcustomlinson/unity-js-scopes/add-harness-tests into lp:unity-js-scopes

Proposed by Marcus Tomlinson on 2015-11-09
Status: Merged
Merged at revision: 113
Proposed branch: lp:~marcustomlinson/unity-js-scopes/add-harness-tests
Merge into: lp:unity-js-scopes
Diff against target: 615 lines (+507/-1)
16 files modified
CMakeLists.txt (+9/-0)
debian/control (+2/-1)
src/bindings/CMakeLists.txt (+16/-0)
src/launcher/CMakeLists.txt (+10/-0)
tests/CMakeLists.txt (+1/-0)
tests/owm_scope/CMakeLists.txt (+2/-0)
tests/owm_scope/scope/CMakeLists.txt (+11/-0)
tests/owm_scope/scope/owm_scope.ini (+5/-0)
tests/owm_scope/scope/owm_scope.js (+197/-0)
tests/owm_scope/tests/CMakeLists.txt (+22/-0)
tests/owm_scope/tests/server/forecast/London,uk.json (+1/-0)
tests/owm_scope/tests/server/forecast/Manchester,uk.json (+1/-0)
tests/owm_scope/tests/server/server.py (+78/-0)
tests/owm_scope/tests/server/weather/London,uk.json (+1/-0)
tests/owm_scope/tests/server/weather/Manchester,uk.json (+1/-0)
tests/owm_scope/tests/test-scope.py (+150/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/add-harness-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2015-11-09
WebApps 2015-11-09 Pending
Review via email: mp+276953@code.launchpad.net

Commit message

Add initial integration level tests using the scope-harness testing framework

To post a comment you must log in.
108. By Marcus Tomlinson on 2015-11-09

Added missing copyrights

109. By Marcus Tomlinson on 2015-11-09

Add google-mock to dependancies

110. By Marcus Tomlinson on 2015-11-09

Actually, add cmake-extras

111. By Marcus Tomlinson on 2015-11-09

Add google-mock to dependancies

112. By Marcus Tomlinson on 2015-11-09

Add python3-scope-harness dependancy

113. By Marcus Tomlinson on 2015-11-09

Clean up

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-10-25 19:03:30 +0000
3+++ CMakeLists.txt 2015-11-09 15:16:03 +0000
4@@ -69,3 +69,12 @@
5 DESTINATION /usr/share/qtcreator/templates/wizards/ubuntu)
6 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/qtc-templates/scope-js
7 DESTINATION /usr/ubuntu-sdk-ide/share/qtcreator/templates/wizards/ubuntu)
8+
9+# Set up the tests
10+enable_testing()
11+add_subdirectory(tests)
12+
13+add_custom_target(
14+ check
15+ ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
16+)
17
18=== modified file 'debian/control'
19--- debian/control 2015-10-27 14:43:23 +0000
20+++ debian/control 2015-11-09 15:16:03 +0000
21@@ -5,9 +5,10 @@
22 Build-Depends: bzr,
23 cmake (>= 2.8.9),
24 debhelper (>= 9),
25+ g++,
26 pkg-config,
27 python3,
28- g++,
29+ python3-scope-harness,
30 libboost-filesystem-dev,
31 libunity-scopes-dev,
32 Standards-Version: 3.9.5
33
34=== modified file 'src/bindings/CMakeLists.txt'
35--- src/bindings/CMakeLists.txt 2015-10-08 20:34:00 +0000
36+++ src/bindings/CMakeLists.txt 2015-11-09 15:16:03 +0000
37@@ -87,6 +87,22 @@
38 ${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NODEJS_ADDON_BIN_NAME}.node
39 )
40
41+add_custom_command(
42+ TARGET ${SCOPE_NODEJS_ADDON_BIN_NAME} POST_BUILD
43+ COMMAND ${CMAKE_COMMAND} -E make_directory
44+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/lib"
45+
46+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
47+ "${CMAKE_CURRENT_BINARY_DIR}/unity_js_scopes_bindings.node"
48+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
49+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
50+ "${CMAKE_CURRENT_SOURCE_DIR}/index.js"
51+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
52+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
53+ "${CMAKE_CURRENT_SOURCE_DIR}/lib/scope-core.js"
54+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/lib"
55+)
56+
57 install(DIRECTORY ${CMAKE_SOURCE_DIR}/deps/io.js/deps/npm
58 DESTINATION /node_modules
59 USE_SOURCE_PERMISSIONS
60
61=== modified file 'src/launcher/CMakeLists.txt'
62--- src/launcher/CMakeLists.txt 2015-09-30 06:10:51 +0000
63+++ src/launcher/CMakeLists.txt 2015-11-09 15:16:03 +0000
64@@ -68,5 +68,15 @@
65 ${Boost_LIBRARIES}
66 )
67
68+add_custom_command(
69+ TARGET ${LAUNCHER_EXECUTABLE_NAME} POST_BUILD
70+ COMMAND ${CMAKE_COMMAND} -E make_directory
71+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
72+
73+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
74+ "${CMAKE_CURRENT_BINARY_DIR}/unity-js-scopes-launcher"
75+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
76+)
77+
78 install(TARGETS ${LAUNCHER_EXECUTABLE_NAME}
79 RUNTIME DESTINATION /usr/bin)
80
81=== added file 'tests/CMakeLists.txt'
82--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
83+++ tests/CMakeLists.txt 2015-11-09 15:16:03 +0000
84@@ -0,0 +1,1 @@
85+add_subdirectory(owm_scope)
86
87=== added directory 'tests/owm_scope'
88=== added file 'tests/owm_scope/CMakeLists.txt'
89--- tests/owm_scope/CMakeLists.txt 1970-01-01 00:00:00 +0000
90+++ tests/owm_scope/CMakeLists.txt 2015-11-09 15:16:03 +0000
91@@ -0,0 +1,2 @@
92+add_subdirectory(scope)
93+add_subdirectory(tests)
94
95=== added directory 'tests/owm_scope/scope'
96=== added file 'tests/owm_scope/scope/CMakeLists.txt'
97--- tests/owm_scope/scope/CMakeLists.txt 1970-01-01 00:00:00 +0000
98+++ tests/owm_scope/scope/CMakeLists.txt 2015-11-09 15:16:03 +0000
99@@ -0,0 +1,11 @@
100+configure_file(
101+ "owm_scope.ini"
102+ "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.ini"
103+ @ONLY COPYONLY
104+)
105+
106+configure_file(
107+ "owm_scope.js"
108+ "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.js"
109+ @ONLY COPYONLY
110+)
111
112=== added file 'tests/owm_scope/scope/owm_scope.ini'
113--- tests/owm_scope/scope/owm_scope.ini 1970-01-01 00:00:00 +0000
114+++ tests/owm_scope/scope/owm_scope.ini 2015-11-09 15:16:03 +0000
115@@ -0,0 +1,5 @@
116+[ScopeConfig]
117+ScopeRunner=../../node_modules/unity-js-scopes/bin/unity-js-scopes-launcher %S %R
118+DisplayName=OpenWeatherMap Test Scope
119+Description=This is an OpenWeatherMap test scope
120+Author=WebApps <webapps@lists.launchpad.net>
121
122=== added file 'tests/owm_scope/scope/owm_scope.js'
123--- tests/owm_scope/scope/owm_scope.js 1970-01-01 00:00:00 +0000
124+++ tests/owm_scope/scope/owm_scope.js 2015-11-09 15:16:03 +0000
125@@ -0,0 +1,197 @@
126+/*
127+ * Copyright 2015 Canonical Ltd.
128+ *
129+ * This file is part of unity-js-scopes.
130+ *
131+ * unity-js-scopes is free software; you can redistribute it and/or modify
132+ * it under the terms of the GNU General Public License as published by
133+ * the Free Software Foundation; version 3.
134+ *
135+ * unity-js-scopes is distributed in the hope that it will be useful,
136+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
137+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138+ * GNU General Public License for more details.
139+ *
140+ * You should have received a copy of the GNU General Public License
141+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
142+ */
143+
144+var scopes = require('unity-js-scopes')
145+var http = require('http');
146+
147+var query_host = process.env.NETWORK_SCOPE_APIROOT ? process.env.NETWORK_SCOPE_APIROOT : "api.openweathermap.org";
148+var query_host_port = process.env.NETWORK_SCOPE_APIPORT ? process.env.NETWORK_SCOPE_APIPORT : 80;
149+var current_weather_path = "/data/2.5/weather?units=metric&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q="
150+var forecast_weather_path = "/data/2.5/forecast/daily?units=metric&cnt=7&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q="
151+
152+var CURRENT_TEMPLATE = {
153+ "schema-version": 1,
154+ "template": {
155+ "category-layout": "grid",
156+ "card-size": "medium"
157+ },
158+ "components": {
159+ "title": "title",
160+ "art": {
161+ "field": "art"
162+ },
163+ "subtitle": "subtitle"
164+ }
165+}
166+
167+var FORECAST_TEMPLATE = {
168+ "schema-version": 1,
169+ "template": {
170+ "category-layout": "grid",
171+ "card-layout": "horizontal",
172+ "card-size": "small"
173+ },
174+ "components": {
175+ "title": "title",
176+ "art" : {
177+ "field": "art"
178+ },
179+ "subtitle": "subtitle"
180+ }
181+}
182+
183+scopes.self.initialize(
184+ {}
185+ ,
186+ {
187+ run: function() {
188+ console.log('Running...')
189+ },
190+ start: function(scope_id) {
191+ console.log('Starting scope id: '
192+ + scope_id
193+ + ', '
194+ + scopes.self.scope_directory)
195+ },
196+ search: function(canned_query, metadata) {
197+ return new scopes.lib.SearchQuery(
198+ canned_query,
199+ metadata,
200+ // run
201+ function(search_reply) {
202+ var qs = canned_query.query_string();
203+ if (!qs) {
204+ qs = "London,uk"
205+ }
206+
207+ var current_weather_cb = function(response) {
208+ var res = '';
209+
210+ // Another chunk of data has been recieved, so append it to res
211+ response.on('data', function(chunk) {
212+ res += chunk;
213+ });
214+
215+ // The whole response has been recieved
216+ response.on('end', function() {
217+ r = JSON.parse(res);
218+
219+ var category_renderer = new scopes.lib.CategoryRenderer(JSON.stringify(CURRENT_TEMPLATE));
220+ var category = search_reply.register_category("current", r.name + ", " + r.sys.country, "", category_renderer);
221+
222+ var categorised_result = new scopes.lib.CategorisedResult(category);
223+ categorised_result.set_uri(r.id.toString());
224+ categorised_result.set_title(r.main.temp.toString() + "°C");
225+ categorised_result.set_art("http://openweathermap.org/img/w/" + r.weather[0].icon + ".png");
226+ categorised_result.set("subtitle", r.weather[0].description);
227+ categorised_result.set("description", "A description of the result");
228+
229+ search_reply.push(categorised_result);
230+
231+ // Now call back into the API for a 7 day forecast
232+ http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
233+ });
234+ }
235+
236+ var forecase_weather_cb = function(response) {
237+ var res = '';
238+
239+ // Another chunk of data has been recieved, so append it to res
240+ response.on('data', function(chunk) {
241+ res += chunk;
242+ });
243+
244+ // The whole response has been recieved
245+ response.on('end', function() {
246+ try {
247+ r = JSON.parse(res);
248+
249+ var category_renderer = new scopes.lib.CategoryRenderer(JSON.stringify(FORECAST_TEMPLATE));
250+ var category = search_reply.register_category("forecast", "7 day forecast", "", category_renderer);
251+
252+ for (i = 0; i < r.list.length; i++) {
253+ var categorised_result = new scopes.lib.CategorisedResult(category);
254+ categorised_result.set_uri(r.list[i].weather[0].id.toString());
255+ categorised_result.set_title(r.list[i].temp.min.toString() + "°C to "
256+ + r.list[i].temp.max.toString() + "°C");
257+ categorised_result.set_art("http://openweathermap.org/img/w/" + r.list[i].weather[0].icon + ".png");
258+ categorised_result.set("subtitle", r.list[i].weather[0].description);
259+ categorised_result.set("description", "A description of the result");
260+
261+ search_reply.push(categorised_result);
262+ }
263+
264+ // We are done, call finished() on our search_reply
265+ search_reply.finished();
266+ }
267+ catch(e) {
268+ // Forecast not available
269+ console.log("Forecast for '" + qs + "' is unavailable: " + e)
270+
271+ // We are done, call finished() on our search_reply
272+ search_reply.finished();
273+ }
274+ });
275+ }
276+
277+ http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();
278+ },
279+ // cancelled
280+ function() {
281+ });
282+ },
283+ preview: function(result, action_metadata) {
284+ return new scopes.lib.PreviewQuery(
285+ result,
286+ action_metadata,
287+ // run
288+ function(preview_reply) {
289+ var layout1col = new scopes.lib.ColumnLayout(1);
290+ var layout2col = new scopes.lib.ColumnLayout(2);
291+ var layout3col = new scopes.lib.ColumnLayout(3);
292+ layout1col.add_column(["image", "header", "summary"]);
293+
294+ layout2col.add_column(["image"]);
295+ layout2col.add_column(["header", "summary"]);
296+
297+ layout3col.add_column(["image"]);
298+ layout3col.add_column(["header", "summary"]);
299+ layout3col.add_column([]);
300+
301+ preview_reply.register_layout([layout1col, layout2col, layout3col]);
302+
303+ var header = new scopes.lib.PreviewWidget("header", "header");
304+ header.add_attribute_mapping("title", "title");
305+ header.add_attribute_mapping("subtitle", "subtitle");
306+
307+ var image = new scopes.lib.PreviewWidget("image", "image");
308+ image.add_attribute_mapping("source", "art");
309+
310+ var description = new scopes.lib.PreviewWidget("summary", "text");
311+ description.add_attribute_mapping("text", "description");
312+
313+ preview_reply.push([image, header, description ]);
314+ preview_reply.finished();
315+ },
316+ // cancelled
317+ function() {
318+ });
319+ }
320+ }
321+);
322+
323
324=== added directory 'tests/owm_scope/tests'
325=== added file 'tests/owm_scope/tests/CMakeLists.txt'
326--- tests/owm_scope/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
327+++ tests/owm_scope/tests/CMakeLists.txt 2015-11-09 15:16:03 +0000
328@@ -0,0 +1,22 @@
329+file(GLOB_RECURSE
330+ TEST_FIXTURES
331+ "server/*.json"
332+ "*.py"
333+)
334+
335+# Make these files show up in QtCreator
336+add_custom_target(hidden_test_fixtures ALL
337+ SOURCES ${TEST_FIXTURES}
338+)
339+
340+# Where to find the scope ini file
341+set(TEST_SCOPE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../scope")
342+
343+# Where to find the test server binary
344+set(FAKE_SERVER "${CMAKE_CURRENT_SOURCE_DIR}/server/server.py")
345+
346+# Register the test with CTest
347+add_test(
348+ owm_scope-tests
349+ "${CMAKE_CURRENT_SOURCE_DIR}/test-scope.py" "owm_scope" "${TEST_SCOPE_DIRECTORY}/owm_scope.ini" "${FAKE_SERVER}"
350+)
351
352=== added directory 'tests/owm_scope/tests/server'
353=== added directory 'tests/owm_scope/tests/server/forecast'
354=== added file 'tests/owm_scope/tests/server/forecast/London,uk.json'
355--- tests/owm_scope/tests/server/forecast/London,uk.json 1970-01-01 00:00:00 +0000
356+++ tests/owm_scope/tests/server/forecast/London,uk.json 2015-11-09 15:16:03 +0000
357@@ -0,0 +1,1 @@
358+{"cod":"200","message":0.1117,"city":{"id":2643743,"name":"London","coord":{"lon":-0.12574,"lat":51.50853},"country":"GB","population":0,"sys":{"population":0}},"cnt":7,"list":[{"dt":1407412800,"temp":{"day":23.33,"min":18.84,"max":25.09,"night":18.84,"eve":24.17,"morn":20.76},"pressure":1018.23,"humidity":83,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":1.87,"deg":295,"clouds":12,"rain":0.5},{"dt":1407499200,"temp":{"day":19.44,"min":15.54,"max":20.86,"night":15.54,"eve":18.28,"morn":16.21},"pressure":1010.57,"humidity":97,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":4.01,"deg":143,"clouds":92,"rain":8},{"dt":1407585600,"temp":{"day":18.78,"min":13.19,"max":19.58,"night":13.19,"eve":18.95,"morn":14.03},"pressure":1010.78,"humidity":83,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"speed":5.46,"deg":281,"clouds":32},{"dt":1407672000,"temp":{"day":18.09,"min":13.46,"max":18.09,"night":13.46,"eve":16.58,"morn":13.91},"pressure":1002.33,"humidity":67,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":10.68,"deg":162,"clouds":92,"rain":4},{"dt":1407758400,"temp":{"day":17.38,"min":15.39,"max":17.38,"night":16.3,"eve":17.03,"morn":15.39},"pressure":1008.2,"humidity":0,"weather":[{"id":502,"main":"Rain","description":"heavy intensity rain","icon":"10d"}],"speed":13.52,"deg":245,"clouds":74,"rain":12.63},{"dt":1407844800,"temp":{"day":18.44,"min":16.17,"max":18.44,"night":16.83,"eve":18.02,"morn":16.17},"pressure":1009.94,"humidity":0,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":10.93,"deg":251,"clouds":60,"rain":5.25},{"dt":1407931200,"temp":{"day":18.8,"min":16.67,"max":19.02,"night":16.77,"eve":19.02,"morn":16.67},"pressure":1013.17,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":9.88,"deg":275,"clouds":85,"rain":1.35}]}
359
360=== added file 'tests/owm_scope/tests/server/forecast/Manchester,uk.json'
361--- tests/owm_scope/tests/server/forecast/Manchester,uk.json 1970-01-01 00:00:00 +0000
362+++ tests/owm_scope/tests/server/forecast/Manchester,uk.json 2015-11-09 15:16:03 +0000
363@@ -0,0 +1,1 @@
364+{"cod":"200","message":0.0056,"city":{"id":2643123,"name":"Manchester","coord":{"lon":-2.23743,"lat":53.480949},"country":"GB","population":0,"sys":{"population":0}},"cnt":7,"list":[{"dt":1407412800,"temp":{"day":17.91,"min":11.96,"max":18.83,"night":11.96,"eve":18.01,"morn":16.13},"pressure":1014.82,"humidity":77,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":3.32,"deg":303,"clouds":0},{"dt":1407499200,"temp":{"day":18.59,"min":12.33,"max":18.59,"night":12.33,"eve":14.55,"morn":14.69},"pressure":1008.22,"humidity":79,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":3.46,"deg":163,"clouds":92,"rain":11},{"dt":1407585600,"temp":{"day":15.8,"min":10.79,"max":17.11,"night":10.79,"eve":16.89,"morn":13.19},"pressure":1005.76,"humidity":92,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"speed":5.61,"deg":279,"clouds":56},{"dt":1407672000,"temp":{"day":15.29,"min":12.21,"max":15.98,"night":12.41,"eve":15.98,"morn":12.21},"pressure":995.36,"humidity":95,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":10.75,"deg":137,"clouds":92,"rain":5},{"dt":1407758400,"temp":{"day":15.73,"min":12.99,"max":15.73,"night":13.8,"eve":15.23,"morn":12.99},"pressure":990.16,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":9.02,"deg":239,"clouds":99,"rain":1.15},{"dt":1407844800,"temp":{"day":17.64,"min":14.08,"max":17.64,"night":14.08,"eve":14.92,"morn":14.12},"pressure":992.52,"humidity":0,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":10.36,"deg":240,"clouds":45,"rain":4.84},{"dt":1407931200,"temp":{"day":14.35,"min":13.37,"max":15.52,"night":13.77,"eve":15.52,"morn":13.37},"pressure":999.39,"humidity":0,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":7.79,"deg":285,"clouds":92,"rain":5.98}]}
365
366=== added file 'tests/owm_scope/tests/server/server.py'
367--- tests/owm_scope/tests/server/server.py 1970-01-01 00:00:00 +0000
368+++ tests/owm_scope/tests/server/server.py 2015-11-09 15:16:03 +0000
369@@ -0,0 +1,78 @@
370+#!/usr/bin/env python3
371+
372+# Copyright (C) 2015 Canonical Ltd.
373+
374+# This library is free software; you can redistribute it and/or
375+# modify it under the terms of the GNU Lesser General Public
376+# License as published by the Free Software Foundation; either
377+# version 2.1 of the License, or (at your option) any later version.
378+
379+# This library is distributed in the hope that it will be useful,
380+# but WITHOUT ANY WARRANTY; without even the implied warranty of
381+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
382+# Lesser General Public License for more details.
383+
384+# You should have received a copy of the GNU Lesser General Public
385+# License along with this library; if not, write to the Free Software
386+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
387+# MA 02110-1301 USA
388+
389+import http.server
390+import os
391+import socketserver
392+import sys
393+from urllib.parse import urlparse,parse_qs
394+
395+def read_file(path):
396+ file = os.path.join(os.path.dirname(__file__), path)
397+ if os.path.isfile(file):
398+ with open(file, 'r') as fp:
399+ content = fp.read()
400+ else:
401+ content = ''
402+
403+ return content
404+
405+class MyRequestHandler(http.server.BaseHTTPRequestHandler):
406+ def do_GET(self):
407+ sys.stderr.write("GET: %s\n" % self.path)
408+ sys.stderr.flush()
409+
410+ parse = urlparse(self.path)
411+ path = parse.path
412+ query = parse_qs(parse.query)
413+
414+ if path == '/data/2.5/weather':
415+ self.send_response(200)
416+ self.send_header("Content-type", "text/html")
417+ self.end_headers()
418+
419+ mode = 'json'
420+ if 'mode' in query:
421+ mode = query['mode'][0]
422+
423+ self.wfile.write(bytes(read_file('weather/%s.%s' % (query['q'][0], mode)), 'UTF-8'))
424+ elif path == '/data/2.5/forecast/daily':
425+ self.send_response(200)
426+ self.send_header("Content-type", "text/html")
427+ self.end_headers()
428+
429+ mode = 'json'
430+ if 'mode' in query:
431+ mode = query['mode'][0]
432+
433+ self.wfile.write(bytes(read_file('forecast/%s.%s' % (query['q'][0], mode)), 'UTF-8'))
434+ else:
435+ self.send_response(404)
436+ self.send_header("Content-type", "text/html")
437+ self.end_headers()
438+ self.wfile.write(bytes('ERROR', 'UTF-8'))
439+
440+if __name__ == "__main__":
441+ Handler = MyRequestHandler
442+ httpd = socketserver.TCPServer(("127.0.0.1", 0), Handler)
443+
444+ sys.stdout.write('%d\n' % httpd.server_address[1])
445+ sys.stdout.flush()
446+
447+ httpd.serve_forever()
448
449=== added directory 'tests/owm_scope/tests/server/weather'
450=== added file 'tests/owm_scope/tests/server/weather/London,uk.json'
451--- tests/owm_scope/tests/server/weather/London,uk.json 1970-01-01 00:00:00 +0000
452+++ tests/owm_scope/tests/server/weather/London,uk.json 2015-11-09 15:16:03 +0000
453@@ -0,0 +1,1 @@
454+{"coord":{"lon":-0.13,"lat":51.51},"sys":{"type":1,"id":5091,"message":0.29,"country":"GB","sunrise":1407386057,"sunset":1407440289},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"cmc stations","main":{"temp":21.83,"pressure":1014,"humidity":53,"temp_min":20,"temp_max":24},"wind":{"speed":1.5,"deg":0},"clouds":{"all":20},"dt":1407408276,"id":2643743,"name":"London","cod":200}
455
456=== added file 'tests/owm_scope/tests/server/weather/Manchester,uk.json'
457--- tests/owm_scope/tests/server/weather/Manchester,uk.json 1970-01-01 00:00:00 +0000
458+++ tests/owm_scope/tests/server/weather/Manchester,uk.json 2015-11-09 15:16:03 +0000
459@@ -0,0 +1,1 @@
460+{"coord":{"lon":-2.24,"lat":53.48},"sys":{"type":1,"id":5060,"message":0.2423,"country":"GB","sunrise":1407386141,"sunset":1407441219},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"cmc stations","main":{"temp":17.35,"pressure":1016,"humidity":77,"temp_min":17,"temp_max":18},"wind":{"speed":2.6,"deg":20,"var_beg":330,"var_end":80},"clouds":{"all":40},"dt":1407408600,"id":2643123,"name":"Manchester","cod":200}
461
462=== added file 'tests/owm_scope/tests/test-scope.py'
463--- tests/owm_scope/tests/test-scope.py 1970-01-01 00:00:00 +0000
464+++ tests/owm_scope/tests/test-scope.py 2015-11-09 15:16:03 +0000
465@@ -0,0 +1,150 @@
466+#!/usr/bin/env python3
467+
468+# Copyright (C) 2015 Canonical Ltd.
469+
470+# This library is free software; you can redistribute it and/or
471+# modify it under the terms of the GNU Lesser General Public
472+# License as published by the Free Software Foundation; either
473+# version 2.1 of the License, or (at your option) any later version.
474+
475+# This library is distributed in the hope that it will be useful,
476+# but WITHOUT ANY WARRANTY; without even the implied warranty of
477+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
478+# Lesser General Public License for more details.
479+
480+# You should have received a copy of the GNU Lesser General Public
481+# License along with this library; if not, write to the Free Software
482+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
483+# MA 02110-1301 USA
484+
485+from scope_harness import (
486+ CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,
487+ Parameters, ResultMatcher, ScopeHarness
488+)
489+from scope_harness.testing import *
490+import unittest, sys, os
491+from subprocess import Popen, PIPE
492+
493+class AppsTest (ScopeHarnessTestCase):
494+ @classmethod
495+ def setUpClass(cls):
496+ cls.process = Popen(["/usr/bin/python3", FAKE_SERVER], stdout=PIPE)
497+ port = cls.process.stdout.readline().decode("utf-8").rstrip('\n')
498+ os.environ["NETWORK_SCOPE_APIROOT"] = "localhost"
499+ os.environ["NETWORK_SCOPE_APIPORT"] = port
500+
501+ @classmethod
502+ def tearDownClass(cls):
503+ cls.process.terminate()
504+
505+
506+ def start_harness(self):
507+ self.harness = ScopeHarness.new_from_scope_list(Parameters([SCOPE_INI]))
508+ self.view = self.harness.results_view
509+ self.view.active_scope = SCOPE_NAME
510+
511+
512+ def test_surfacing_results(self):
513+ self.start_harness()
514+ self.view.search_query = ''
515+
516+ match = CategoryListMatcher() \
517+ .has_exactly(2) \
518+ .mode(CategoryListMatcherMode.BY_ID) \
519+ .category(CategoryMatcher("current") \
520+ .title("London, GB") \
521+ .has_at_least(1) \
522+ .result(ResultMatcher("2643743") \
523+ .title("21.83°C") \
524+ .art("http://openweathermap.org/img/w/02d.png") \
525+ .subtitle("few clouds") ) ) \
526+ .category(CategoryMatcher("forecast") \
527+ .title("7 day forecast") \
528+ .has_at_least(7) \
529+ .result(ResultMatcher("500") \
530+ .title("18.84°C to 25.09°C") \
531+ .art("http://openweathermap.org/img/w/10d.png") \
532+ .subtitle("light rain") ) \
533+ .result(ResultMatcher("501") \
534+ .title("15.54°C to 20.86°C") \
535+ .art("http://openweathermap.org/img/w/10d.png") \
536+ .subtitle("moderate rain") ) \
537+ .result(ResultMatcher("802") \
538+ .title("13.19°C to 19.58°C") \
539+ .art("http://openweathermap.org/img/w/03d.png") \
540+ .subtitle("scattered clouds") ) \
541+ .result(ResultMatcher("501") \
542+ .title("13.46°C to 18.09°C") \
543+ .art("http://openweathermap.org/img/w/10d.png") \
544+ .subtitle("moderate rain") ) \
545+ .result(ResultMatcher("502") \
546+ .title("15.39°C to 17.38°C") \
547+ .art("http://openweathermap.org/img/w/10d.png") \
548+ .subtitle("heavy intensity rain") ) \
549+ .result(ResultMatcher("501") \
550+ .title("16.17°C to 18.44°C") \
551+ .art("http://openweathermap.org/img/w/10d.png") \
552+ .subtitle("moderate rain") ) \
553+ .result(ResultMatcher("500") \
554+ .title("16.67°C to 19.02°C") \
555+ .art("http://openweathermap.org/img/w/10d.png") \
556+ .subtitle("light rain") ) ) \
557+ .match(self.view.categories)
558+ self.assertMatchResult(match)
559+
560+
561+ def test_search_results(self):
562+ self.start_harness()
563+ self.view.search_query = 'Manchester,uk'
564+
565+ match = CategoryListMatcher() \
566+ .has_exactly(2) \
567+ .mode(CategoryListMatcherMode.BY_ID) \
568+ .category(CategoryMatcher("current") \
569+ .title("Manchester, GB") \
570+ .has_at_least(1) \
571+ .result(ResultMatcher("2643123") \
572+ .title("17.35°C") \
573+ .art("http://openweathermap.org/img/w/03d.png") \
574+ .subtitle("scattered clouds") ) ) \
575+ .category(CategoryMatcher("forecast") \
576+ .title("7 day forecast") \
577+ .has_at_least(7) \
578+ .result(ResultMatcher("800") \
579+ .title("11.96°C to 18.83°C") \
580+ .art("http://openweathermap.org/img/w/01d.png") \
581+ .subtitle("sky is clear") ) \
582+ .result(ResultMatcher("501") \
583+ .title("12.33°C to 18.59°C") \
584+ .art("http://openweathermap.org/img/w/10d.png") \
585+ .subtitle("moderate rain") ) \
586+ .result(ResultMatcher("803") \
587+ .title("10.79°C to 17.11°C") \
588+ .art("http://openweathermap.org/img/w/04d.png") \
589+ .subtitle("broken clouds") ) \
590+ .result(ResultMatcher("501") \
591+ .title("12.21°C to 15.98°C") \
592+ .art("http://openweathermap.org/img/w/10d.png") \
593+ .subtitle("moderate rain") ) \
594+ .result(ResultMatcher("500") \
595+ .title("12.99°C to 15.73°C") \
596+ .art("http://openweathermap.org/img/w/10d.png") \
597+ .subtitle("light rain") ) \
598+ .result(ResultMatcher("501") \
599+ .title("14.08°C to 17.64°C") \
600+ .art("http://openweathermap.org/img/w/10d.png") \
601+ .subtitle("moderate rain") ) \
602+ .result(ResultMatcher("501") \
603+ .title("13.37°C to 15.52°C") \
604+ .art("http://openweathermap.org/img/w/10d.png") \
605+ .subtitle("moderate rain") ) ) \
606+ .match(self.view.categories)
607+ self.assertMatchResult(match)
608+
609+
610+if __name__ == '__main__':
611+ SCOPE_NAME = sys.argv[1]
612+ SCOPE_INI = sys.argv[2]
613+ FAKE_SERVER = sys.argv[3]
614+
615+ unittest.main(argv = sys.argv[:1])

Subscribers

People subscribed via source and target branches

to all changes: