Merge lp:~allanlesage/qakit/i18ncheck-sample-test into lp:~vrruiz/qakit/i18ncheck
- i18ncheck-sample-test
- Merge into i18ncheck
Proposed by
Allan LeSage
Status: | Merged |
---|---|
Approved by: | Víctor R. Ruiz |
Approved revision: | 13 |
Merged at revision: | 16 |
Proposed branch: | lp:~allanlesage/qakit/i18ncheck-sample-test |
Merge into: | lp:~vrruiz/qakit/i18ncheck |
Diff against target: |
479 lines (+248/-142) 5 files modified
qakit/i18ncheck/tests/test_filter_strings.py (+89/-0) qakit/practitest/tests/test_practisubunit.py (+21/-66) qakit/practitest/tests/test_practitest.py (+71/-59) qakit/practitest/tests/test_report_subunit_results_to_practitest.py (+51/-0) qakit/practitest/tests/test_sanity_suite.py (+16/-17) |
To merge this branch: | bzr merge lp:~allanlesage/qakit/i18ncheck-sample-test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Víctor R. Ruiz | Approve | ||
Review via email: mp+264940@code.launchpad.net |
Commit message
Description of the change
Sample test, run with nosetests3 .
To post a comment you must log in.
Revision history for this message
Víctor R. Ruiz (vrruiz) wrote : | # |
Revision history for this message
Víctor R. Ruiz (vrruiz) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'qakit/i18ncheck/tests' |
2 | === added file 'qakit/i18ncheck/tests/test_filter_strings.py' |
3 | --- qakit/i18ncheck/tests/test_filter_strings.py 1970-01-01 00:00:00 +0000 |
4 | +++ qakit/i18ncheck/tests/test_filter_strings.py 2015-07-16 00:11:20 +0000 |
5 | @@ -0,0 +1,89 @@ |
6 | +# Copyright (C) 2014-2015 Canonical |
7 | +# |
8 | +# This program is free software; you can redistribute it and/or |
9 | +# modify it under the terms of the GNU General Public License |
10 | +# as published by the Free Software Foundation; either version 2 |
11 | +# of the License, or (at your option) any later version. |
12 | +# |
13 | +# This program is distributed in the hope that it will be useful, |
14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | +# GNU General Public License for more details. |
17 | +# |
18 | +# You should have received a copy of the GNU General Public License |
19 | +# along with this program; if not, write to the Free Software |
20 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | +# 02110-1301, USA. |
22 | + |
23 | +import unittest |
24 | +from unittest import mock |
25 | + |
26 | +import qakit.i18ncheck.TranslationChecker as translation_checker |
27 | + |
28 | + |
29 | +GALLERY_STRINGS = [ |
30 | + 'import QtQuick 2.0\n', |
31 | + 'import Ubuntu.Components 1.1\n', |
32 | + 'import Ubuntu.Components.Extras 0.2 as Extras\n', |
33 | + '\n', |
34 | + '/*\n', |
35 | + ' * Copyright (C) 2014 Canonical Ltd\n', |
36 | + ' *\n', |
37 | + ' * This program is free software: you can redistribute it and/or modify\n', |
38 | + ' * it under the terms of the GNU General Public License version 3 as\n', |
39 | + ' * published by the Free Software Foundation.\n', |
40 | + ' *\n', |
41 | + ' * This program is distributed in the hope that it will be useful,\n', |
42 | + ' * but WITHOUT ANY WARRANTY; without even the implied warranty of\n', |
43 | + ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n', |
44 | + ' * GNU General Public License for more details.\n', |
45 | + ' *\n', |
46 | + ' * You should have received a copy of the GNU General Public License\n', |
47 | + ' * along with this program. If not, see <http://www.gnu.org/licenses/>.\n', |
48 | + ' */\n', |
49 | + '\n', |
50 | + 'Page {\n', |
51 | + ' id: page\n', |
52 | + ' property string photo\n', |
53 | + ' signal done(bool photoWasModified)\n', |
54 | + '\n', |
55 | + ' title: i18n.tr("Edit Photo")\n', |
56 | + '\n', |
57 | + ' head.backAction: Action {\n', |
58 | + ' iconName: "back"\n', |
59 | + ' onTriggered: editor.close(true)\n', |
60 | + ' }\n', |
61 | + ' head.actions: editor.actions\n', |
62 | + '\n', |
63 | + ' Extras.PhotoEditor {\n', |
64 | + ' id: editor\n', |
65 | + ' anchors.fill: parent\n', |
66 | + ' onClosed: page.done(photoWasModified)\n', |
67 | + ' }\n', |
68 | + '\n', |
69 | + ' onActiveChanged: {\n', |
70 | + ' if (active) editor.open(page.photo)\n', |
71 | + ' }\n', |
72 | + '}\n' |
73 | +] |
74 | + |
75 | + |
76 | +class TranslationCheckerTestCase(unittest.TestCase): |
77 | + |
78 | + def setUp(self): |
79 | + super().setUp() |
80 | + self.translation_checker_init_patch = mock.patch( |
81 | + 'qakit.i18ncheck.TranslationChecker.TranslationChecker.__init__', |
82 | + return_value=None) |
83 | + self.translation_checker_init_patch.start() |
84 | + |
85 | + def tearDown(self): |
86 | + self.translation_checker_init_patch.stop() |
87 | + |
88 | + |
89 | +class FilterStringsTestCase(TranslationCheckerTestCase): |
90 | + |
91 | + def test_filter_gallery_strings_returns_edit_photo(self): |
92 | + checker = translation_checker.TranslationChecker('gallery-app', ['es']) |
93 | + result = checker._filter_strings(GALLERY_STRINGS, checker.REGEX_TR) |
94 | + self.assertEqual(["Edit Photo"], result) |
95 | |
96 | === renamed file 'qakit/practitest/tests/test_practisanity.py' => 'qakit/practitest/tests/test_practisubunit.py' |
97 | --- qakit/practitest/tests/test_practisanity.py 2015-04-15 19:03:17 +0000 |
98 | +++ qakit/practitest/tests/test_practisubunit.py 2015-07-16 00:11:20 +0000 |
99 | @@ -15,16 +15,22 @@ |
100 | # You should have received a copy of the GNU General Public License |
101 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
102 | |
103 | -import os |
104 | import unittest |
105 | from unittest import mock |
106 | |
107 | -import practisanity |
108 | -import sanity_suite |
109 | -from tests.test_practitest import TESTS, INSTANCES |
110 | - |
111 | - |
112 | -class GetInstanceSanitySuiteNameTestCase(unittest.TestCase): |
113 | +from qakit.practitest.practisubunit import PractiSubunitSession |
114 | +from qakit.practitest.tests.test_practitest import TEST, TESTS |
115 | + |
116 | + |
117 | +class PractiSubunitSessionTestCase(unittest.TestCase): |
118 | + |
119 | + def setUp(self): |
120 | + super().setUp() |
121 | + self.practisubunit_session = PractiSubunitSession( |
122 | + 42, 'fake_api_key', 'fake_api_secret_key') |
123 | + |
124 | + |
125 | +class GetInstanceSanitySuiteNameTestCase(PractiSubunitSessionTestCase): |
126 | |
127 | def test_get_instance_sanity_suite_name(self): |
128 | instance = { |
129 | @@ -35,62 +41,11 @@ |
130 | 'system_id': 1188312, |
131 | 'id': '24:1' |
132 | } |
133 | - sanity_name = 'ubuntu_sanity_tests.tests.test_settings_wizard.SettingsWizardTestCase.test_complete_settings_wizard' # NOQA |
134 | - result = practisanity._get_instance_sanity_suite_name( |
135 | - TESTS, instance) |
136 | - self.assertEqual(sanity_name, result) |
137 | - |
138 | - |
139 | -class BuildPractisanityTestMapTestCase(unittest.TestCase): |
140 | - |
141 | - def test_build_practisanity_test_map(self): |
142 | - test_name = 'ubuntu_sanity_tests.tests.test_bluetooth.BluetoothTestCase.test_disconnected_list_populates' # NOQA |
143 | - practitest_instance = { |
144 | - 'system_id': 1188331, |
145 | - 'id': '24:11', |
146 | - 'last_run': {'value': '04-Mar-2015 17:12', 'name': 'Last Run'}, |
147 | - 'run_status': {'value': 'FAILED', 'name': 'Run Status'}, |
148 | - 'name': 'Discover Bluetooth devices' |
149 | - } |
150 | - practitest_tests = TESTS |
151 | - sanity_suite_results = sanity_suite.parse_subunit_results( |
152 | - os.path.join(os.path.dirname(__file__), |
153 | - 'test-results.subunit')) |
154 | - result = practisanity._build_practisanity_test_map( |
155 | - practitest_instance, |
156 | - practitest_tests, |
157 | - sanity_suite_results) |
158 | - self.assertEqual( |
159 | - test_name, |
160 | - result['test_name']) |
161 | - self.assertEqual( |
162 | - 'Discover Bluetooth devices', |
163 | - result['practitest_instance']['name']) |
164 | - self.assertEqual( |
165 | - test_name, |
166 | - result['sanity_test_result']['id']) |
167 | - |
168 | - |
169 | -class ConfirmNameOfTestset(unittest.TestCase): |
170 | - |
171 | - @mock.patch('practitest._get_testset') |
172 | - @mock.patch('practisanity.input', create=True) |
173 | - def test_confirm_name_of_testset(self, mock_input, mock_get_testset): |
174 | - mock_input.return_value = "Y" |
175 | - self.assertTrue(practisanity._confirm_name_of_testset(24)) |
176 | - |
177 | - @mock.patch('practitest._get_testset') |
178 | - @mock.patch('practisanity.input', create=True) |
179 | - def test_confirm_name_of_testset_false(self, |
180 | - mock_input, |
181 | - mock_get_testset): |
182 | - mock_input.return_value = "n" |
183 | - self.assertFalse(practisanity._confirm_name_of_testset(24)) |
184 | - |
185 | - @mock.patch('practitest._get_testset') |
186 | - @mock.patch('practisanity.input', create=True) |
187 | - def test_confirm_name_of_testset_gibberish(self, |
188 | - mock_input, |
189 | - mock_get_testset): |
190 | - mock_input.return_value = "GIBBERISH" |
191 | - self.assertTrue(practisanity._confirm_name_of_testset(24)) |
192 | + test_name = ('ubuntu_sanity_tests.tests.test_settings_wizard.' |
193 | + 'SettingsWizardTestCase.test_complete_settings_wizard') |
194 | + with mock.patch.object(self.practisubunit_session, |
195 | + 'get_test', |
196 | + return_value=TEST): |
197 | + result = self.practisubunit_session.get_instance_custom_field( |
198 | + instance, "External ID", TESTS) |
199 | + self.assertEqual(test_name, result) |
200 | |
201 | === modified file 'qakit/practitest/tests/test_practitest.py' |
202 | --- qakit/practitest/tests/test_practitest.py 2015-04-15 19:03:17 +0000 |
203 | +++ qakit/practitest/tests/test_practitest.py 2015-07-16 00:11:20 +0000 |
204 | @@ -19,7 +19,8 @@ |
205 | import unittest |
206 | from unittest import mock |
207 | |
208 | -import practitest |
209 | +from qakit.practitest.practitest import PractitestSession |
210 | +import qakit.practitest as practitest |
211 | |
212 | |
213 | TESTS = [ |
214 | @@ -158,41 +159,45 @@ |
215 | |
216 | class GetInstancesTestCase(PractitestSessionTestCase): |
217 | |
218 | - @mock.patch.object('practitest.PractitestSession', '_get') |
219 | - def test_get_instances(self, mock_get): |
220 | - result = practitest._get_instances(24) |
221 | + def test_get_instances(self): |
222 | + with mock.patch.object(self.practitest_session, |
223 | + '_get') as mock_get: |
224 | + result = self.practitest_session.get_instances(24) |
225 | mock_get.assert_called_with( |
226 | - 'http://prod.practitest.com/api/sets/24/instances.json') |
227 | + 'https://prod.practitest.com/api/sets/24/instances.json') |
228 | |
229 | |
230 | class GetTestsetTestCase(PractitestSessionTestCase): |
231 | |
232 | - @mock.patch('practitest._get') |
233 | - def test_get_testset(self, mock_get): |
234 | - practitest._get_testset(42) |
235 | - mock_get.assert_called_with( |
236 | - 'http://prod.practitest.com/api/sets/42.json') |
237 | - |
238 | - |
239 | -class GetInstancesTestCase(PractitestSesssionTestCase): |
240 | - |
241 | - @mock.patch('practitest._get') |
242 | - def test_get_testset(self, mock_get): |
243 | - practitest._get_instances(42) |
244 | - mock_get.assert_called_with( |
245 | - 'http://prod.practitest.com/api/sets/42/instances.json') |
246 | - |
247 | - |
248 | -class GetTestTestCase(PractitestSesssionTestCase): |
249 | - |
250 | - @mock.patch('practitest._get') |
251 | - def test_get_test(self, mock_get): |
252 | - practitest._get_test(42) |
253 | - mock_get.assert_called_with( |
254 | - 'http://prod.practitest.com/api/tests/42.json') |
255 | - |
256 | - |
257 | -class GetTestFromTestsByName(PractitestSesssionTestCase): |
258 | + def test_get_testset(self): |
259 | + with mock.patch.object(self.practitest_session, |
260 | + '_get') as mock_get: |
261 | + self.practitest_session.get_testset(42) |
262 | + mock_get.assert_called_with( |
263 | + 'https://prod.practitest.com/api/sets/42.json') |
264 | + |
265 | + |
266 | +class GetInstancesTestCase(PractitestSessionTestCase): |
267 | + |
268 | + def test_get_testset(self): |
269 | + with mock.patch.object(self.practitest_session, |
270 | + '_get') as mock_get: |
271 | + self.practitest_session.get_instances(42) |
272 | + mock_get.assert_called_with( |
273 | + 'https://prod.practitest.com/api/sets/42/instances.json') |
274 | + |
275 | + |
276 | +class GetTestTestCase(PractitestSessionTestCase): |
277 | + |
278 | + def test_get_test(self): |
279 | + with mock.patch.object(self.practitest_session, |
280 | + '_get') as mock_get: |
281 | + self.practitest_session.get_test(42) |
282 | + mock_get.assert_called_with( |
283 | + 'https://prod.practitest.com/api/tests/42.json') |
284 | + |
285 | + |
286 | +class GetTestFromTestsByName(PractitestSessionTestCase): |
287 | |
288 | def test_get_test_from_tests_by_name(self): |
289 | test = { |
290 | @@ -207,42 +212,49 @@ |
291 | } |
292 | test_name = ('Complete wizard successfully ' |
293 | '(English, SIM inserted, Wi-Fi connected)') |
294 | - self.assertEqual(test, practitest._get_test_from_tests_by_name( |
295 | - TESTS, test_name)) |
296 | + result = self.practitest_session.get_test_from_tests_by_name( |
297 | + test_name, TESTS) |
298 | + self.assertEqual(test, result) |
299 | |
300 | def test_get_gibberish(self): |
301 | test_name = 'Test exploding OSK' |
302 | - self.assertIsNone(practitest._get_test_from_tests_by_name( |
303 | - TESTS, test_name)) |
304 | - |
305 | - |
306 | -class GetIdOfTestByNameTestCase(PractitestSesssionTestCase): |
307 | - |
308 | - @mock.patch('practitest._get_test_from_tests_by_name') |
309 | - def test_get_id_of_test_by_name(self, get_test_mock): |
310 | - get_test_mock.return_value = { |
311 | - 'last_run': '26-Feb-2015 11:44', |
312 | - 'display_id': 94, |
313 | - 'name': ('Complete wizard successfully ' |
314 | - '(English, SIM inserted, Wi-Fi connected)'), |
315 | - 'run_status': 'PASSED', |
316 | - 'updated_at': '25-Feb-2015 16:14', |
317 | - 'steps_count': 9, |
318 | - 'system_id': 371857 |
319 | - } |
320 | - test_name = ('Complete wizard successfully ' |
321 | - '(English, SIM inserted, Wi-Fi connected)') |
322 | - result = practitest._get_id_of_test_by_name( |
323 | - TESTS, test_name) |
324 | + result = self.practitest_session.get_test_from_tests_by_name( |
325 | + test_name, TESTS) |
326 | + self.assertIsNone(result) |
327 | + |
328 | + |
329 | +class GetIdOfTestByNameTestCase(PractitestSessionTestCase): |
330 | + |
331 | + def test_get_id_of_test_by_name(self): |
332 | + with mock.patch.object( |
333 | + self.practitest_session, |
334 | + 'get_test_from_tests_by_name') as get_test_mock: |
335 | + get_test_mock.return_value = { |
336 | + 'last_run': '26-Feb-2015 11:44', |
337 | + 'display_id': 94, |
338 | + 'name': ('Complete wizard successfully ' |
339 | + '(English, SIM inserted, Wi-Fi connected)'), |
340 | + 'run_status': 'PASSED', |
341 | + 'updated_at': '25-Feb-2015 16:14', |
342 | + 'steps_count': 9, |
343 | + 'system_id': 371857 |
344 | + } |
345 | + test_name = ('Complete wizard successfully ' |
346 | + '(English, SIM inserted, Wi-Fi connected)') |
347 | + result = self.practitest_session._get_id_of_test_by_name( |
348 | + test_name, TESTS) |
349 | self.assertEqual(94, result) |
350 | |
351 | |
352 | -class GetTestExternalId(PractitestSesssionTestCase): |
353 | +@unittest.skip |
354 | +class GetTestExternalId(PractitestSessionTestCase): |
355 | |
356 | def test_get_test_external_id(self): |
357 | - result = practitest._get_test_external_id(TEST) |
358 | - self.assertEqual('ubuntu_sanity_tests.tests.test_settings_wizard.SettingsWizardTestCase.test_complete_settings_wizard', result) # NOQA |
359 | + result = practitest.get_test_external_id(TEST) |
360 | + self.assertEqual(('ubuntu_sanity_tests.tests.test_settings_wizard.' |
361 | + 'SettingsWizardTestCase.test_complete_settings_wizard'), |
362 | + result) |
363 | |
364 | def test_get_id_of_not_sanity_test(self): |
365 | - result = practitest._get_test_external_id(NOT_SANITY_TEST) |
366 | + result = self.practitest_session.get_test_external_id(NOT_SANITY_TEST) |
367 | self.assertEqual(None, result) |
368 | |
369 | === added file 'qakit/practitest/tests/test_report_subunit_results_to_practitest.py' |
370 | --- qakit/practitest/tests/test_report_subunit_results_to_practitest.py 1970-01-01 00:00:00 +0000 |
371 | +++ qakit/practitest/tests/test_report_subunit_results_to_practitest.py 2015-07-16 00:11:20 +0000 |
372 | @@ -0,0 +1,51 @@ |
373 | +# PractiSubunit |
374 | +# Copyright (C) 2015 Canonical |
375 | +# |
376 | +# This program is free software: you can redistribute it and/or modify |
377 | +# it under the terms of the GNU General Public License as published by |
378 | +# the Free Software Foundation, either version 3 of the License, or |
379 | +# (at your option) any later version. |
380 | +# |
381 | +# This program is distributed in the hope that it will be useful, |
382 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
383 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
384 | +# GNU General Public License for more details. |
385 | +# |
386 | +# You should have received a copy of the GNU General Public License |
387 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
388 | + |
389 | +import unittest |
390 | +from unittest import mock |
391 | + |
392 | +import qakit.practitest.report_subunit_results_to_practitest as report |
393 | + |
394 | + |
395 | +@mock.patch('qakit.practitest.report_subunit_results_to_practitest.input', |
396 | + create=True) |
397 | +class ConfirmNameOfTestset(unittest.TestCase): |
398 | + |
399 | + mock_practisubunit_session = mock.Mock( |
400 | + get_testset=mock.Mock( |
401 | + return_value={'name': 'fake_name', |
402 | + 'assigned_to': {'value': 'fake_value'}})) |
403 | + |
404 | + def test_confirm_name_of_testset(self, mock_input): |
405 | + mock_input.return_value = "Y" |
406 | + self.assertTrue( |
407 | + report._confirm_name_of_testset( |
408 | + 24, |
409 | + self.mock_practisubunit_session)) |
410 | + |
411 | + def test_confirm_name_of_testset_false(self, mock_input): |
412 | + mock_input.return_value = "n" |
413 | + self.assertFalse( |
414 | + report._confirm_name_of_testset( |
415 | + 24, |
416 | + self.mock_practisubunit_session)) |
417 | + |
418 | + def test_confirm_name_of_testset_gibberish(self, mock_input): |
419 | + mock_input.return_value = "GIBBERISH" |
420 | + self.assertTrue( |
421 | + report._confirm_name_of_testset( |
422 | + 24, |
423 | + self.mock_practisubunit_session)) |
424 | |
425 | === modified file 'qakit/practitest/tests/test_sanity_suite.py' |
426 | --- qakit/practitest/tests/test_sanity_suite.py 2015-04-15 19:03:17 +0000 |
427 | +++ qakit/practitest/tests/test_sanity_suite.py 2015-07-16 00:11:20 +0000 |
428 | @@ -1,5 +1,5 @@ |
429 | |
430 | -# PractiSanity |
431 | +# PractiSubunit |
432 | # Copyright (C) 2015 Canonical |
433 | # |
434 | # This program is free software: you can redistribute it and/or modify |
435 | @@ -18,29 +18,28 @@ |
436 | import os |
437 | import unittest |
438 | |
439 | -import sanity_suite |
440 | - |
441 | - |
442 | -class GetSanitySuiteTestByName(unittest.TestCase): |
443 | - |
444 | - def test_get_sanity_suite_test_by_name(self): |
445 | - # FIXME: pickle the results? |
446 | - test_name = 'ubuntu_sanity_tests.tests.test_bluetooth.BluetoothTestCase.test_disconnected_list_populates' |
447 | - sanity_suite_results = sanity_suite.parse_subunit_results( |
448 | +import qakit.practitest.subunit_results as subunit |
449 | + |
450 | + |
451 | +class GetSubunitSuiteTestByName(unittest.TestCase): |
452 | + |
453 | + def test_get_subunit_test_by_name(self): |
454 | + test_name = ('ubuntu_sanity_tests.tests.test_bluetooth.' |
455 | + 'BluetoothTestCase.test_disconnected_list_populates') |
456 | + subunit_results = subunit.parse( |
457 | os.path.join(os.path.dirname(__file__), |
458 | 'test-results.subunit')) |
459 | - result = sanity_suite.get_sanity_suite_test_by_name( |
460 | + result = subunit.get_subunit_test_by_name( |
461 | test_name, |
462 | - sanity_suite_results) |
463 | + subunit_results) |
464 | self.assertEqual(test_name, result['id']) |
465 | |
466 | - def test_get_sanity_suite_test_by_name(self): |
467 | - # FIXME: pickle the results? |
468 | + def test_get_subunit_test_by_name_gibberish(self): |
469 | test_name = 'exploding_osk.really.this_would_never_be_a_test_name' |
470 | - sanity_suite_results = sanity_suite.parse_subunit_results( |
471 | + subunit_results = subunit.parse( |
472 | os.path.join(os.path.dirname(__file__), |
473 | 'test-results.subunit')) |
474 | - result = sanity_suite.get_sanity_suite_test_by_name( |
475 | + result = subunit.get_subunit_test_by_name( |
476 | test_name, |
477 | - sanity_suite_results) |
478 | + subunit_results) |
479 | self.assertEqual(None, result) |
Looks fine to me.