Merge lp:~elopio/click-update-manager/fix1234379-autopilot_tests into lp:click-update-manager

Proposed by Leo Arias on 2013-10-04
Status: Merged
Approved by: Leo Arias on 2013-10-07
Approved revision: 34
Merged at revision: 33
Proposed branch: lp:~elopio/click-update-manager/fix1234379-autopilot_tests
Merge into: lp:click-update-manager
Diff against target: 273 lines (+93/-135)
3 files modified
tests/autopilot/click_update_manager/__init__.py (+85/-117)
tests/autopilot/click_update_manager/main/__init__.py (+0/-1)
tests/autopilot/click_update_manager/test_main.py (+8/-17)
To merge this branch: bzr merge lp:~elopio/click-update-manager/fix1234379-autopilot_tests
Reviewer Review Type Date Requested Status
Corey Goldberg (community) 2013-10-04 Approve on 2013-10-07
PS Jenkins bot (community) continuous-integration Approve on 2013-10-07
Diego Sarmentero (community) 2013-10-04 Approve on 2013-10-07
Ubuntu One hackers 2013-10-04 Pending
Review via email: mp+189245@code.launchpad.net

Commit message

Cleaned the autopilot test cases.

To post a comment you must log in.
32. By Leo Arias on 2013-10-04

Fixed pyflakes.

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
33. By Leo Arias on 2013-10-07

Fixed the install desktop path.

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Corey Goldberg (coreygoldberg) wrote :

looks very good.
one small nitpick:

197 + self.app = self.launch_test_application(
198 + '/usr/lib/' + arch + '/qt5/bin/qmlscene',
199 + "-I" + _get_module_include_path(),

... should probably use os.path.join() instead of appending strings so it matches the rest of code style.

34. By Leo Arias on 2013-10-07

Used os.path.join for the qmlscene path, as suggested by cgoldberg.

Corey Goldberg (coreygoldberg) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/click_update_manager/__init__.py'
2--- tests/autopilot/click_update_manager/__init__.py 2013-10-01 21:01:04 +0000
3+++ tests/autopilot/click_update_manager/__init__.py 2013-10-07 15:10:34 +0000
4@@ -2,128 +2,96 @@
5
6 """Ubuntu Touch App autopilot tests."""
7
8-from os import remove
9-import os.path
10+import os
11+import shutil
12 import subprocess
13-from tempfile import mktemp
14
15-from autopilot.input import Mouse, Touch, Pointer
16+from autopilot.input import Pointer
17 from autopilot.matchers import Eventually
18-from autopilot.platform import model
19-from autopilot.testcase import AutopilotTestCase
20-from testtools.matchers import Is, Not, Equals
21-
22-
23-def get_module_include_path():
24+from testtools.matchers import Equals
25+from ubuntuuitoolkit import base, emulators
26+
27+
28+def _get_module_include_path():
29+ return os.path.join(_get_path_to_source_root(), 'modules')
30+
31+
32+def _get_path_to_source_root():
33 return os.path.abspath(
34 os.path.join(
35- os.path.dirname(__file__),
36- '..',
37- '..',
38- '..',
39- '..',
40- 'modules')
41- )
42-
43-
44-class UbuntuTouchAppTestCase(AutopilotTestCase):
45- """A common test case class that provides several
46- useful methods for the tests.
47- """
48-
49- if model() == 'Desktop':
50- scenarios = [
51- ('with mouse', dict(input_device_class=Mouse))
52- ]
53- else:
54- scenarios = [
55- ('with touch', dict(input_device_class=Touch))
56- ]
57-
58- @property
59- def main_window(self):
60- return MainWindow(self.app)
61+ os.path.dirname(__file__), '..', '..', '..'))
62+
63+
64+def _get_local_desktop_file_directory():
65+ return os.path.join(os.environ['HOME'], '.local', 'share', 'applications')
66+
67+
68+class ClickUpdateManagerTestCase(base.UbuntuUIToolkitAppTestCase):
69+
70+ qml_file_name = 'updatemanager.qml'
71+ path_to_installed_app = '/usr/share/click-update-manager/'
72+ desktop_file_name = 'click-update-manager.desktop'
73+ path_to_installed_desktop_file = '/usr/share/applications/'
74+ local_desktop_file_path = None
75
76 def setUp(self):
77- super(UbuntuTouchAppTestCase, self).setUp()
78+ super(ClickUpdateManagerTestCase, self).setUp()
79 self.pointing_device = Pointer(self.input_device_class.create())
80- self.launch_test_qml()
81-
82- def launch_test_qml(self):
83- # If the test class has defined a 'test_qml' class attribute then we
84- # write it to disk and launch it inside the QML Scene. If not, then we
85- # silently do nothing (presumably the test has something else planned).
86- arch = subprocess.check_output(["dpkg-architecture",
87- "-qDEB_HOST_MULTIARCH"]).strip()
88- if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
89- qml_path = mktemp(suffix='.qml')
90- with open(qml_path, 'w') as f:
91- f.write(self.test_qml)
92- self.addCleanup(remove, qml_path)
93-
94- self.app = self.launch_test_application(
95- "/usr/lib/" + arch + "/qt5/bin/qmlscene",
96- "-I", get_module_include_path(),
97- qml_path,
98- app_type='qt')
99-
100- if hasattr(self, 'test_qml_file') and \
101- isinstance(self.test_qml_file, basestring):
102- qml_path = self.test_qml_file
103- self.app = self.launch_test_application(
104- "/usr/lib/" + arch + "/qt5/bin/qmlscene",
105- "-I", get_module_include_path(),
106- qml_path,
107- app_type='qt')
108-
109- self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
110-
111- def get_qml_view(self):
112- """Get the main QML view"""
113-
114- return self.app.select_single("QQuickView")
115-
116- def get_mainview(self):
117- """Get the QML MainView"""
118-
119- mainView = self.app.select_single("MainView")
120- self.assertThat(mainView, Not(Is(None)))
121- return mainView
122-
123- def get_object(self, objectName):
124- """Get a object based on the objectName"""
125-
126- obj = self.app.select_single(objectName=objectName)
127- self.assertThat(obj, Not(Is(None)))
128- return obj
129-
130- def mouse_click(self, objectName):
131- """Move mouse on top of the object and click on it"""
132-
133- obj = self.get_object(objectName)
134- self.pointing_device.move_to_object(obj)
135- self.pointing_device.click()
136-
137- def mouse_press(self, objectName):
138- """Move mouse on top of the object and press
139- mouse button (without releasing it)
140- """
141-
142- obj = self.get_object(objectName)
143- self.pointing_device.move_to_object(obj)
144- self.pointing_device.press()
145-
146- def mouse_release(self):
147- """Release mouse button"""
148-
149- self.pointing_device.release()
150-
151- def type_string(self, string):
152- """Type a string with keyboard"""
153-
154- self.keyboard.type(string)
155-
156- def type_key(self, key):
157- """Type a single key with keyboard"""
158-
159- self.keyboard.key(key)
160+ self.app_qml_source_path = os.path.join(
161+ _get_path_to_source_root(), self.qml_file_name)
162+ self.test_qml_file_path = self._get_test_qml_file_path()
163+ self.desktop_file_path = self._get_desktop_file_path()
164+ self.launch_application()
165+
166+ def _get_test_qml_file_path(self):
167+ if self._application_source_exists():
168+ return self.app_qml_source_path
169+ else:
170+ return os.path.join(
171+ self.path_to_installed_app, self.qml_file_name)
172+
173+ def _application_source_exists(self):
174+ return os.path.exists(self.app_qml_source_path)
175+
176+ def _get_desktop_file_path(self):
177+ if self._application_source_exists():
178+ local_desktop_file_dir = _get_local_desktop_file_directory()
179+ if not os.path.exists(local_desktop_file_dir):
180+ os.makedirs(local_desktop_file_dir)
181+ source_desktop_file_path = os.path.join(
182+ _get_path_to_source_root(), self.desktop_file_name)
183+ local_desktop_file_path = os.path.join(
184+ local_desktop_file_dir, self.desktop_file_name)
185+ shutil.copy(source_desktop_file_path, local_desktop_file_path)
186+ # We can't delete the desktop file before we close the application,
187+ # so we save it on an attribute to be deleted on tear down.
188+ self.local_desktop_file_path = local_desktop_file_path
189+ return local_desktop_file_path
190+ else:
191+ return os.path.join(
192+ self.path_to_installed_desktop_file, self.desktop_file_name)
193+
194+ def launch_application(self):
195+ arch = subprocess.check_output(
196+ ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
197+ self.app = self.launch_test_application(
198+ os.path.join('/usr/lib', arch, 'qt5/bin/qmlscene'),
199+ '-I' + _get_module_include_path(),
200+ self.test_qml_file_path,
201+ '--desktop_file_hint={0}'.format(self.desktop_file_path),
202+ emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
203+ app_type='qt')
204+
205+ self.assertThat(
206+ self.main_view.visible, Eventually(Equals(True)))
207+
208+ def tearDown(self):
209+ super(ClickUpdateManagerTestCase, self).tearDown()
210+ # We can't delete the desktop file before we close the application,
211+ # so we save it on an attribute to be deleted on tear down.
212+ if self.local_desktop_file_path is not None:
213+ os.remove(self.local_desktop_file_path)
214+
215+ @property
216+ def main_view(self):
217+ return self.app.select_single(emulators.MainView)
218
219=== removed directory 'tests/autopilot/click_update_manager/main'
220=== removed file 'tests/autopilot/click_update_manager/main/__init__.py'
221--- tests/autopilot/click_update_manager/main/__init__.py 2013-09-20 20:11:40 +0000
222+++ tests/autopilot/click_update_manager/main/__init__.py 1970-01-01 00:00:00 +0000
223@@ -1,1 +0,0 @@
224-""" Update Manager test suite """
225
226=== renamed file 'tests/autopilot/click_update_manager/main/test_main.py' => 'tests/autopilot/click_update_manager/test_main.py'
227--- tests/autopilot/click_update_manager/main/test_main.py 2013-10-02 20:30:41 +0000
228+++ tests/autopilot/click_update_manager/test_main.py 2013-10-07 15:10:34 +0000
229@@ -2,36 +2,27 @@
230
231 """Tests for PageUpdate"""
232
233-import os
234-
235 from autopilot.matchers import Eventually
236 from testtools.matchers import Equals
237
238-from click_update_manager import UbuntuTouchAppTestCase
239-
240-
241-class PageUpdateTests(UbuntuTouchAppTestCase):
242+import click_update_manager
243+
244+
245+class PageUpdateTestCase(click_update_manager.ClickUpdateManagerTestCase):
246 """Page Update Tests."""
247
248- test_qml_file = "/usr/share/click-update-manager/updatemanager.qml"
249-
250- def test_UI_is_loaded(self):
251- """Must be able to see the mainview."""
252-
253- mainView = self.get_mainview()
254- self.assertThat(mainView.visible, Eventually(Equals(True)))
255-
256 def test_loading_disappear(self):
257 """Check the loading indicator disappears"""
258
259- loading = self.get_object(objectName="loadingIndicator")
260+ loading = self.main_view.select_single(objectName="loadingIndicator")
261 self.assertThat(loading.visible, Eventually(Equals(False)))
262
263 def test_check_again(self):
264 """Check the loading indicator disappears"""
265
266- loading = self.get_object(objectName="loadingIndicator")
267+ loading = self.main_view.select_single(objectName="loadingIndicator")
268 self.assertThat(loading.visible, Eventually(Equals(False)))
269- self.mouse_click(objectName="retryButton")
270+ retry_button = self.main_view.select_single(objectName="retryButton")
271+ self.pointing_device.click_object(retry_button)
272 self.assertThat(loading.visible, Eventually(Equals(True)))
273 self.assertThat(loading.visible, Eventually(Equals(False)))

Subscribers

People subscribed via source and target branches

to all changes: