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

Proposed by Marcus Tomlinson
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
WebApps 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.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
108. By Marcus Tomlinson

Added missing copyrights

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

Add google-mock to dependancies

110. By Marcus Tomlinson

Actually, add cmake-extras

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

Add google-mock to dependancies

112. By Marcus Tomlinson

Add python3-scope-harness dependancy

113. By Marcus Tomlinson

Clean up

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 :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-10-25 19:03:30 +0000
+++ CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -69,3 +69,12 @@
69 DESTINATION /usr/share/qtcreator/templates/wizards/ubuntu)69 DESTINATION /usr/share/qtcreator/templates/wizards/ubuntu)
70install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/qtc-templates/scope-js70install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/qtc-templates/scope-js
71 DESTINATION /usr/ubuntu-sdk-ide/share/qtcreator/templates/wizards/ubuntu)71 DESTINATION /usr/ubuntu-sdk-ide/share/qtcreator/templates/wizards/ubuntu)
72
73# Set up the tests
74enable_testing()
75add_subdirectory(tests)
76
77add_custom_target(
78 check
79 ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
80)
7281
=== modified file 'debian/control'
--- debian/control 2015-10-27 14:43:23 +0000
+++ debian/control 2015-11-09 15:16:03 +0000
@@ -5,9 +5,10 @@
5Build-Depends: bzr,5Build-Depends: bzr,
6 cmake (>= 2.8.9),6 cmake (>= 2.8.9),
7 debhelper (>= 9),7 debhelper (>= 9),
8 g++,
8 pkg-config,9 pkg-config,
9 python3,10 python3,
10 g++,11 python3-scope-harness,
11 libboost-filesystem-dev,12 libboost-filesystem-dev,
12 libunity-scopes-dev,13 libunity-scopes-dev,
13Standards-Version: 3.9.514Standards-Version: 3.9.5
1415
=== modified file 'src/bindings/CMakeLists.txt'
--- src/bindings/CMakeLists.txt 2015-10-08 20:34:00 +0000
+++ src/bindings/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -87,6 +87,22 @@
87 ${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NODEJS_ADDON_BIN_NAME}.node87 ${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NODEJS_ADDON_BIN_NAME}.node
88 )88 )
8989
90add_custom_command(
91 TARGET ${SCOPE_NODEJS_ADDON_BIN_NAME} POST_BUILD
92 COMMAND ${CMAKE_COMMAND} -E make_directory
93 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/lib"
94
95 COMMAND ${CMAKE_COMMAND} -E copy_if_different
96 "${CMAKE_CURRENT_BINARY_DIR}/unity_js_scopes_bindings.node"
97 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
98 COMMAND ${CMAKE_COMMAND} -E copy_if_different
99 "${CMAKE_CURRENT_SOURCE_DIR}/index.js"
100 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
101 COMMAND ${CMAKE_COMMAND} -E copy_if_different
102 "${CMAKE_CURRENT_SOURCE_DIR}/lib/scope-core.js"
103 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/lib"
104)
105
90install(DIRECTORY ${CMAKE_SOURCE_DIR}/deps/io.js/deps/npm106install(DIRECTORY ${CMAKE_SOURCE_DIR}/deps/io.js/deps/npm
91 DESTINATION /node_modules107 DESTINATION /node_modules
92 USE_SOURCE_PERMISSIONS108 USE_SOURCE_PERMISSIONS
93109
=== modified file 'src/launcher/CMakeLists.txt'
--- src/launcher/CMakeLists.txt 2015-09-30 06:10:51 +0000
+++ src/launcher/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -68,5 +68,15 @@
68 ${Boost_LIBRARIES}68 ${Boost_LIBRARIES}
69 )69 )
7070
71add_custom_command(
72 TARGET ${LAUNCHER_EXECUTABLE_NAME} POST_BUILD
73 COMMAND ${CMAKE_COMMAND} -E make_directory
74 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
75
76 COMMAND ${CMAKE_COMMAND} -E copy_if_different
77 "${CMAKE_CURRENT_BINARY_DIR}/unity-js-scopes-launcher"
78 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
79)
80
71install(TARGETS ${LAUNCHER_EXECUTABLE_NAME}81install(TARGETS ${LAUNCHER_EXECUTABLE_NAME}
72 RUNTIME DESTINATION /usr/bin)82 RUNTIME DESTINATION /usr/bin)
7383
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -0,0 +1,1 @@
1add_subdirectory(owm_scope)
02
=== added directory 'tests/owm_scope'
=== added file 'tests/owm_scope/CMakeLists.txt'
--- tests/owm_scope/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -0,0 +1,2 @@
1add_subdirectory(scope)
2add_subdirectory(tests)
03
=== added directory 'tests/owm_scope/scope'
=== added file 'tests/owm_scope/scope/CMakeLists.txt'
--- tests/owm_scope/scope/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/scope/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -0,0 +1,11 @@
1configure_file(
2 "owm_scope.ini"
3 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.ini"
4 @ONLY COPYONLY
5)
6
7configure_file(
8 "owm_scope.js"
9 "${CMAKE_CURRENT_BINARY_DIR}/owm_scope.js"
10 @ONLY COPYONLY
11)
012
=== added file 'tests/owm_scope/scope/owm_scope.ini'
--- tests/owm_scope/scope/owm_scope.ini 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/scope/owm_scope.ini 2015-11-09 15:16:03 +0000
@@ -0,0 +1,5 @@
1[ScopeConfig]
2ScopeRunner=../../node_modules/unity-js-scopes/bin/unity-js-scopes-launcher %S %R
3DisplayName=OpenWeatherMap Test Scope
4Description=This is an OpenWeatherMap test scope
5Author=WebApps <webapps@lists.launchpad.net>
06
=== added file 'tests/owm_scope/scope/owm_scope.js'
--- tests/owm_scope/scope/owm_scope.js 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/scope/owm_scope.js 2015-11-09 15:16:03 +0000
@@ -0,0 +1,197 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19var scopes = require('unity-js-scopes')
20var http = require('http');
21
22var query_host = process.env.NETWORK_SCOPE_APIROOT ? process.env.NETWORK_SCOPE_APIROOT : "api.openweathermap.org";
23var query_host_port = process.env.NETWORK_SCOPE_APIPORT ? process.env.NETWORK_SCOPE_APIPORT : 80;
24var current_weather_path = "/data/2.5/weather?units=metric&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q="
25var forecast_weather_path = "/data/2.5/forecast/daily?units=metric&cnt=7&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q="
26
27var CURRENT_TEMPLATE = {
28 "schema-version": 1,
29 "template": {
30 "category-layout": "grid",
31 "card-size": "medium"
32 },
33 "components": {
34 "title": "title",
35 "art": {
36 "field": "art"
37 },
38 "subtitle": "subtitle"
39 }
40}
41
42var FORECAST_TEMPLATE = {
43 "schema-version": 1,
44 "template": {
45 "category-layout": "grid",
46 "card-layout": "horizontal",
47 "card-size": "small"
48 },
49 "components": {
50 "title": "title",
51 "art" : {
52 "field": "art"
53 },
54 "subtitle": "subtitle"
55 }
56}
57
58scopes.self.initialize(
59 {}
60 ,
61 {
62 run: function() {
63 console.log('Running...')
64 },
65 start: function(scope_id) {
66 console.log('Starting scope id: '
67 + scope_id
68 + ', '
69 + scopes.self.scope_directory)
70 },
71 search: function(canned_query, metadata) {
72 return new scopes.lib.SearchQuery(
73 canned_query,
74 metadata,
75 // run
76 function(search_reply) {
77 var qs = canned_query.query_string();
78 if (!qs) {
79 qs = "London,uk"
80 }
81
82 var current_weather_cb = function(response) {
83 var res = '';
84
85 // Another chunk of data has been recieved, so append it to res
86 response.on('data', function(chunk) {
87 res += chunk;
88 });
89
90 // The whole response has been recieved
91 response.on('end', function() {
92 r = JSON.parse(res);
93
94 var category_renderer = new scopes.lib.CategoryRenderer(JSON.stringify(CURRENT_TEMPLATE));
95 var category = search_reply.register_category("current", r.name + ", " + r.sys.country, "", category_renderer);
96
97 var categorised_result = new scopes.lib.CategorisedResult(category);
98 categorised_result.set_uri(r.id.toString());
99 categorised_result.set_title(r.main.temp.toString() + "°C");
100 categorised_result.set_art("http://openweathermap.org/img/w/" + r.weather[0].icon + ".png");
101 categorised_result.set("subtitle", r.weather[0].description);
102 categorised_result.set("description", "A description of the result");
103
104 search_reply.push(categorised_result);
105
106 // Now call back into the API for a 7 day forecast
107 http.request({host: query_host, port: query_host_port, path: forecast_weather_path + qs}, forecase_weather_cb).end();
108 });
109 }
110
111 var forecase_weather_cb = function(response) {
112 var res = '';
113
114 // Another chunk of data has been recieved, so append it to res
115 response.on('data', function(chunk) {
116 res += chunk;
117 });
118
119 // The whole response has been recieved
120 response.on('end', function() {
121 try {
122 r = JSON.parse(res);
123
124 var category_renderer = new scopes.lib.CategoryRenderer(JSON.stringify(FORECAST_TEMPLATE));
125 var category = search_reply.register_category("forecast", "7 day forecast", "", category_renderer);
126
127 for (i = 0; i < r.list.length; i++) {
128 var categorised_result = new scopes.lib.CategorisedResult(category);
129 categorised_result.set_uri(r.list[i].weather[0].id.toString());
130 categorised_result.set_title(r.list[i].temp.min.toString() + "°C to "
131 + r.list[i].temp.max.toString() + "°C");
132 categorised_result.set_art("http://openweathermap.org/img/w/" + r.list[i].weather[0].icon + ".png");
133 categorised_result.set("subtitle", r.list[i].weather[0].description);
134 categorised_result.set("description", "A description of the result");
135
136 search_reply.push(categorised_result);
137 }
138
139 // We are done, call finished() on our search_reply
140 search_reply.finished();
141 }
142 catch(e) {
143 // Forecast not available
144 console.log("Forecast for '" + qs + "' is unavailable: " + e)
145
146 // We are done, call finished() on our search_reply
147 search_reply.finished();
148 }
149 });
150 }
151
152 http.request({host: query_host, port: query_host_port, path: current_weather_path + qs}, current_weather_cb).end();
153 },
154 // cancelled
155 function() {
156 });
157 },
158 preview: function(result, action_metadata) {
159 return new scopes.lib.PreviewQuery(
160 result,
161 action_metadata,
162 // run
163 function(preview_reply) {
164 var layout1col = new scopes.lib.ColumnLayout(1);
165 var layout2col = new scopes.lib.ColumnLayout(2);
166 var layout3col = new scopes.lib.ColumnLayout(3);
167 layout1col.add_column(["image", "header", "summary"]);
168
169 layout2col.add_column(["image"]);
170 layout2col.add_column(["header", "summary"]);
171
172 layout3col.add_column(["image"]);
173 layout3col.add_column(["header", "summary"]);
174 layout3col.add_column([]);
175
176 preview_reply.register_layout([layout1col, layout2col, layout3col]);
177
178 var header = new scopes.lib.PreviewWidget("header", "header");
179 header.add_attribute_mapping("title", "title");
180 header.add_attribute_mapping("subtitle", "subtitle");
181
182 var image = new scopes.lib.PreviewWidget("image", "image");
183 image.add_attribute_mapping("source", "art");
184
185 var description = new scopes.lib.PreviewWidget("summary", "text");
186 description.add_attribute_mapping("text", "description");
187
188 preview_reply.push([image, header, description ]);
189 preview_reply.finished();
190 },
191 // cancelled
192 function() {
193 });
194 }
195 }
196);
197
0198
=== added directory 'tests/owm_scope/tests'
=== added file 'tests/owm_scope/tests/CMakeLists.txt'
--- tests/owm_scope/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/CMakeLists.txt 2015-11-09 15:16:03 +0000
@@ -0,0 +1,22 @@
1file(GLOB_RECURSE
2 TEST_FIXTURES
3 "server/*.json"
4 "*.py"
5)
6
7# Make these files show up in QtCreator
8add_custom_target(hidden_test_fixtures ALL
9 SOURCES ${TEST_FIXTURES}
10)
11
12# Where to find the scope ini file
13set(TEST_SCOPE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../scope")
14
15# Where to find the test server binary
16set(FAKE_SERVER "${CMAKE_CURRENT_SOURCE_DIR}/server/server.py")
17
18# Register the test with CTest
19add_test(
20 owm_scope-tests
21 "${CMAKE_CURRENT_SOURCE_DIR}/test-scope.py" "owm_scope" "${TEST_SCOPE_DIRECTORY}/owm_scope.ini" "${FAKE_SERVER}"
22)
023
=== added directory 'tests/owm_scope/tests/server'
=== added directory 'tests/owm_scope/tests/server/forecast'
=== added file 'tests/owm_scope/tests/server/forecast/London,uk.json'
--- tests/owm_scope/tests/server/forecast/London,uk.json 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/server/forecast/London,uk.json 2015-11-09 15:16:03 +0000
@@ -0,0 +1,1 @@
1{"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}]}
02
=== added file 'tests/owm_scope/tests/server/forecast/Manchester,uk.json'
--- tests/owm_scope/tests/server/forecast/Manchester,uk.json 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/server/forecast/Manchester,uk.json 2015-11-09 15:16:03 +0000
@@ -0,0 +1,1 @@
1{"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}]}
02
=== added file 'tests/owm_scope/tests/server/server.py'
--- tests/owm_scope/tests/server/server.py 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/server/server.py 2015-11-09 15:16:03 +0000
@@ -0,0 +1,78 @@
1#!/usr/bin/env python3
2
3# Copyright (C) 2015 Canonical Ltd.
4
5# This library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9
10# This library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14
15# You should have received a copy of the GNU Lesser General Public
16# License along with this library; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18# MA 02110-1301 USA
19
20import http.server
21import os
22import socketserver
23import sys
24from urllib.parse import urlparse,parse_qs
25
26def read_file(path):
27 file = os.path.join(os.path.dirname(__file__), path)
28 if os.path.isfile(file):
29 with open(file, 'r') as fp:
30 content = fp.read()
31 else:
32 content = ''
33
34 return content
35
36class MyRequestHandler(http.server.BaseHTTPRequestHandler):
37 def do_GET(self):
38 sys.stderr.write("GET: %s\n" % self.path)
39 sys.stderr.flush()
40
41 parse = urlparse(self.path)
42 path = parse.path
43 query = parse_qs(parse.query)
44
45 if path == '/data/2.5/weather':
46 self.send_response(200)
47 self.send_header("Content-type", "text/html")
48 self.end_headers()
49
50 mode = 'json'
51 if 'mode' in query:
52 mode = query['mode'][0]
53
54 self.wfile.write(bytes(read_file('weather/%s.%s' % (query['q'][0], mode)), 'UTF-8'))
55 elif path == '/data/2.5/forecast/daily':
56 self.send_response(200)
57 self.send_header("Content-type", "text/html")
58 self.end_headers()
59
60 mode = 'json'
61 if 'mode' in query:
62 mode = query['mode'][0]
63
64 self.wfile.write(bytes(read_file('forecast/%s.%s' % (query['q'][0], mode)), 'UTF-8'))
65 else:
66 self.send_response(404)
67 self.send_header("Content-type", "text/html")
68 self.end_headers()
69 self.wfile.write(bytes('ERROR', 'UTF-8'))
70
71if __name__ == "__main__":
72 Handler = MyRequestHandler
73 httpd = socketserver.TCPServer(("127.0.0.1", 0), Handler)
74
75 sys.stdout.write('%d\n' % httpd.server_address[1])
76 sys.stdout.flush()
77
78 httpd.serve_forever()
079
=== added directory 'tests/owm_scope/tests/server/weather'
=== added file 'tests/owm_scope/tests/server/weather/London,uk.json'
--- tests/owm_scope/tests/server/weather/London,uk.json 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/server/weather/London,uk.json 2015-11-09 15:16:03 +0000
@@ -0,0 +1,1 @@
1{"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}
02
=== added file 'tests/owm_scope/tests/server/weather/Manchester,uk.json'
--- tests/owm_scope/tests/server/weather/Manchester,uk.json 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/server/weather/Manchester,uk.json 2015-11-09 15:16:03 +0000
@@ -0,0 +1,1 @@
1{"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}
02
=== added file 'tests/owm_scope/tests/test-scope.py'
--- tests/owm_scope/tests/test-scope.py 1970-01-01 00:00:00 +0000
+++ tests/owm_scope/tests/test-scope.py 2015-11-09 15:16:03 +0000
@@ -0,0 +1,150 @@
1#!/usr/bin/env python3
2
3# Copyright (C) 2015 Canonical Ltd.
4
5# This library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9
10# This library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14
15# You should have received a copy of the GNU Lesser General Public
16# License along with this library; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18# MA 02110-1301 USA
19
20from scope_harness import (
21 CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,
22 Parameters, ResultMatcher, ScopeHarness
23)
24from scope_harness.testing import *
25import unittest, sys, os
26from subprocess import Popen, PIPE
27
28class AppsTest (ScopeHarnessTestCase):
29 @classmethod
30 def setUpClass(cls):
31 cls.process = Popen(["/usr/bin/python3", FAKE_SERVER], stdout=PIPE)
32 port = cls.process.stdout.readline().decode("utf-8").rstrip('\n')
33 os.environ["NETWORK_SCOPE_APIROOT"] = "localhost"
34 os.environ["NETWORK_SCOPE_APIPORT"] = port
35
36 @classmethod
37 def tearDownClass(cls):
38 cls.process.terminate()
39
40
41 def start_harness(self):
42 self.harness = ScopeHarness.new_from_scope_list(Parameters([SCOPE_INI]))
43 self.view = self.harness.results_view
44 self.view.active_scope = SCOPE_NAME
45
46
47 def test_surfacing_results(self):
48 self.start_harness()
49 self.view.search_query = ''
50
51 match = CategoryListMatcher() \
52 .has_exactly(2) \
53 .mode(CategoryListMatcherMode.BY_ID) \
54 .category(CategoryMatcher("current") \
55 .title("London, GB") \
56 .has_at_least(1) \
57 .result(ResultMatcher("2643743") \
58 .title("21.83°C") \
59 .art("http://openweathermap.org/img/w/02d.png") \
60 .subtitle("few clouds") ) ) \
61 .category(CategoryMatcher("forecast") \
62 .title("7 day forecast") \
63 .has_at_least(7) \
64 .result(ResultMatcher("500") \
65 .title("18.84°C to 25.09°C") \
66 .art("http://openweathermap.org/img/w/10d.png") \
67 .subtitle("light rain") ) \
68 .result(ResultMatcher("501") \
69 .title("15.54°C to 20.86°C") \
70 .art("http://openweathermap.org/img/w/10d.png") \
71 .subtitle("moderate rain") ) \
72 .result(ResultMatcher("802") \
73 .title("13.19°C to 19.58°C") \
74 .art("http://openweathermap.org/img/w/03d.png") \
75 .subtitle("scattered clouds") ) \
76 .result(ResultMatcher("501") \
77 .title("13.46°C to 18.09°C") \
78 .art("http://openweathermap.org/img/w/10d.png") \
79 .subtitle("moderate rain") ) \
80 .result(ResultMatcher("502") \
81 .title("15.39°C to 17.38°C") \
82 .art("http://openweathermap.org/img/w/10d.png") \
83 .subtitle("heavy intensity rain") ) \
84 .result(ResultMatcher("501") \
85 .title("16.17°C to 18.44°C") \
86 .art("http://openweathermap.org/img/w/10d.png") \
87 .subtitle("moderate rain") ) \
88 .result(ResultMatcher("500") \
89 .title("16.67°C to 19.02°C") \
90 .art("http://openweathermap.org/img/w/10d.png") \
91 .subtitle("light rain") ) ) \
92 .match(self.view.categories)
93 self.assertMatchResult(match)
94
95
96 def test_search_results(self):
97 self.start_harness()
98 self.view.search_query = 'Manchester,uk'
99
100 match = CategoryListMatcher() \
101 .has_exactly(2) \
102 .mode(CategoryListMatcherMode.BY_ID) \
103 .category(CategoryMatcher("current") \
104 .title("Manchester, GB") \
105 .has_at_least(1) \
106 .result(ResultMatcher("2643123") \
107 .title("17.35°C") \
108 .art("http://openweathermap.org/img/w/03d.png") \
109 .subtitle("scattered clouds") ) ) \
110 .category(CategoryMatcher("forecast") \
111 .title("7 day forecast") \
112 .has_at_least(7) \
113 .result(ResultMatcher("800") \
114 .title("11.96°C to 18.83°C") \
115 .art("http://openweathermap.org/img/w/01d.png") \
116 .subtitle("sky is clear") ) \
117 .result(ResultMatcher("501") \
118 .title("12.33°C to 18.59°C") \
119 .art("http://openweathermap.org/img/w/10d.png") \
120 .subtitle("moderate rain") ) \
121 .result(ResultMatcher("803") \
122 .title("10.79°C to 17.11°C") \
123 .art("http://openweathermap.org/img/w/04d.png") \
124 .subtitle("broken clouds") ) \
125 .result(ResultMatcher("501") \
126 .title("12.21°C to 15.98°C") \
127 .art("http://openweathermap.org/img/w/10d.png") \
128 .subtitle("moderate rain") ) \
129 .result(ResultMatcher("500") \
130 .title("12.99°C to 15.73°C") \
131 .art("http://openweathermap.org/img/w/10d.png") \
132 .subtitle("light rain") ) \
133 .result(ResultMatcher("501") \
134 .title("14.08°C to 17.64°C") \
135 .art("http://openweathermap.org/img/w/10d.png") \
136 .subtitle("moderate rain") ) \
137 .result(ResultMatcher("501") \
138 .title("13.37°C to 15.52°C") \
139 .art("http://openweathermap.org/img/w/10d.png") \
140 .subtitle("moderate rain") ) ) \
141 .match(self.view.categories)
142 self.assertMatchResult(match)
143
144
145if __name__ == '__main__':
146 SCOPE_NAME = sys.argv[1]
147 SCOPE_INI = sys.argv[2]
148 FAKE_SERVER = sys.argv[3]
149
150 unittest.main(argv = sys.argv[:1])

Subscribers

People subscribed via source and target branches

to all changes: