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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
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) Approve
PS Jenkins bot (community) continuous-integration Approve
Diego Sarmentero (community) Approve
Ubuntu One hackers 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

Fixed pyflakes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
33. By Leo Arias

Fixed the install desktop path.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
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

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

Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/click_update_manager/__init__.py'
--- tests/autopilot/click_update_manager/__init__.py 2013-10-01 21:01:04 +0000
+++ tests/autopilot/click_update_manager/__init__.py 2013-10-07 15:10:34 +0000
@@ -2,128 +2,96 @@
22
3"""Ubuntu Touch App autopilot tests."""3"""Ubuntu Touch App autopilot tests."""
44
5from os import remove5import os
6import os.path6import shutil
7import subprocess7import subprocess
8from tempfile import mktemp
98
10from autopilot.input import Mouse, Touch, Pointer9from autopilot.input import Pointer
11from autopilot.matchers import Eventually10from autopilot.matchers import Eventually
12from autopilot.platform import model11from testtools.matchers import Equals
13from autopilot.testcase import AutopilotTestCase12from ubuntuuitoolkit import base, emulators
14from testtools.matchers import Is, Not, Equals13
1514
1615def _get_module_include_path():
17def get_module_include_path():16 return os.path.join(_get_path_to_source_root(), 'modules')
17
18
19def _get_path_to_source_root():
18 return os.path.abspath(20 return os.path.abspath(
19 os.path.join(21 os.path.join(
20 os.path.dirname(__file__),22 os.path.dirname(__file__), '..', '..', '..'))
21 '..',23
22 '..',24
23 '..',25def _get_local_desktop_file_directory():
24 '..',26 return os.path.join(os.environ['HOME'], '.local', 'share', 'applications')
25 'modules')27
26 )28
2729class ClickUpdateManagerTestCase(base.UbuntuUIToolkitAppTestCase):
2830
29class UbuntuTouchAppTestCase(AutopilotTestCase):31 qml_file_name = 'updatemanager.qml'
30 """A common test case class that provides several32 path_to_installed_app = '/usr/share/click-update-manager/'
31 useful methods for the tests.33 desktop_file_name = 'click-update-manager.desktop'
32 """34 path_to_installed_desktop_file = '/usr/share/applications/'
3335 local_desktop_file_path = None
34 if model() == 'Desktop':
35 scenarios = [
36 ('with mouse', dict(input_device_class=Mouse))
37 ]
38 else:
39 scenarios = [
40 ('with touch', dict(input_device_class=Touch))
41 ]
42
43 @property
44 def main_window(self):
45 return MainWindow(self.app)
4636
47 def setUp(self):37 def setUp(self):
48 super(UbuntuTouchAppTestCase, self).setUp()38 super(ClickUpdateManagerTestCase, self).setUp()
49 self.pointing_device = Pointer(self.input_device_class.create())39 self.pointing_device = Pointer(self.input_device_class.create())
50 self.launch_test_qml()40 self.app_qml_source_path = os.path.join(
5141 _get_path_to_source_root(), self.qml_file_name)
52 def launch_test_qml(self):42 self.test_qml_file_path = self._get_test_qml_file_path()
53 # If the test class has defined a 'test_qml' class attribute then we43 self.desktop_file_path = self._get_desktop_file_path()
54 # write it to disk and launch it inside the QML Scene. If not, then we44 self.launch_application()
55 # silently do nothing (presumably the test has something else planned).45
56 arch = subprocess.check_output(["dpkg-architecture",46 def _get_test_qml_file_path(self):
57 "-qDEB_HOST_MULTIARCH"]).strip()47 if self._application_source_exists():
58 if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):48 return self.app_qml_source_path
59 qml_path = mktemp(suffix='.qml')49 else:
60 with open(qml_path, 'w') as f:50 return os.path.join(
61 f.write(self.test_qml)51 self.path_to_installed_app, self.qml_file_name)
62 self.addCleanup(remove, qml_path)52
6353 def _application_source_exists(self):
64 self.app = self.launch_test_application(54 return os.path.exists(self.app_qml_source_path)
65 "/usr/lib/" + arch + "/qt5/bin/qmlscene",55
66 "-I", get_module_include_path(),56 def _get_desktop_file_path(self):
67 qml_path,57 if self._application_source_exists():
68 app_type='qt')58 local_desktop_file_dir = _get_local_desktop_file_directory()
6959 if not os.path.exists(local_desktop_file_dir):
70 if hasattr(self, 'test_qml_file') and \60 os.makedirs(local_desktop_file_dir)
71 isinstance(self.test_qml_file, basestring):61 source_desktop_file_path = os.path.join(
72 qml_path = self.test_qml_file62 _get_path_to_source_root(), self.desktop_file_name)
73 self.app = self.launch_test_application(63 local_desktop_file_path = os.path.join(
74 "/usr/lib/" + arch + "/qt5/bin/qmlscene",64 local_desktop_file_dir, self.desktop_file_name)
75 "-I", get_module_include_path(),65 shutil.copy(source_desktop_file_path, local_desktop_file_path)
76 qml_path,66 # We can't delete the desktop file before we close the application,
77 app_type='qt')67 # so we save it on an attribute to be deleted on tear down.
7868 self.local_desktop_file_path = local_desktop_file_path
79 self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))69 return local_desktop_file_path
8070 else:
81 def get_qml_view(self):71 return os.path.join(
82 """Get the main QML view"""72 self.path_to_installed_desktop_file, self.desktop_file_name)
8373
84 return self.app.select_single("QQuickView")74 def launch_application(self):
8575 arch = subprocess.check_output(
86 def get_mainview(self):76 ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
87 """Get the QML MainView"""77 self.app = self.launch_test_application(
8878 os.path.join('/usr/lib', arch, 'qt5/bin/qmlscene'),
89 mainView = self.app.select_single("MainView")79 '-I' + _get_module_include_path(),
90 self.assertThat(mainView, Not(Is(None)))80 self.test_qml_file_path,
91 return mainView81 '--desktop_file_hint={0}'.format(self.desktop_file_path),
9282 emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
93 def get_object(self, objectName):83 app_type='qt')
94 """Get a object based on the objectName"""84
9585 self.assertThat(
96 obj = self.app.select_single(objectName=objectName)86 self.main_view.visible, Eventually(Equals(True)))
97 self.assertThat(obj, Not(Is(None)))87
98 return obj88 def tearDown(self):
9989 super(ClickUpdateManagerTestCase, self).tearDown()
100 def mouse_click(self, objectName):90 # We can't delete the desktop file before we close the application,
101 """Move mouse on top of the object and click on it"""91 # so we save it on an attribute to be deleted on tear down.
10292 if self.local_desktop_file_path is not None:
103 obj = self.get_object(objectName)93 os.remove(self.local_desktop_file_path)
104 self.pointing_device.move_to_object(obj)94
105 self.pointing_device.click()95 @property
10696 def main_view(self):
107 def mouse_press(self, objectName):97 return self.app.select_single(emulators.MainView)
108 """Move mouse on top of the object and press
109 mouse button (without releasing it)
110 """
111
112 obj = self.get_object(objectName)
113 self.pointing_device.move_to_object(obj)
114 self.pointing_device.press()
115
116 def mouse_release(self):
117 """Release mouse button"""
118
119 self.pointing_device.release()
120
121 def type_string(self, string):
122 """Type a string with keyboard"""
123
124 self.keyboard.type(string)
125
126 def type_key(self, key):
127 """Type a single key with keyboard"""
128
129 self.keyboard.key(key)
13098
=== removed directory 'tests/autopilot/click_update_manager/main'
=== removed file 'tests/autopilot/click_update_manager/main/__init__.py'
--- tests/autopilot/click_update_manager/main/__init__.py 2013-09-20 20:11:40 +0000
+++ tests/autopilot/click_update_manager/main/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1""" Update Manager test suite """
20
=== renamed file 'tests/autopilot/click_update_manager/main/test_main.py' => 'tests/autopilot/click_update_manager/test_main.py'
--- tests/autopilot/click_update_manager/main/test_main.py 2013-10-02 20:30:41 +0000
+++ tests/autopilot/click_update_manager/test_main.py 2013-10-07 15:10:34 +0000
@@ -2,36 +2,27 @@
22
3"""Tests for PageUpdate"""3"""Tests for PageUpdate"""
44
5import os
6
7from autopilot.matchers import Eventually5from autopilot.matchers import Eventually
8from testtools.matchers import Equals6from testtools.matchers import Equals
97
10from click_update_manager import UbuntuTouchAppTestCase8import click_update_manager
119
1210
13class PageUpdateTests(UbuntuTouchAppTestCase):11class PageUpdateTestCase(click_update_manager.ClickUpdateManagerTestCase):
14 """Page Update Tests."""12 """Page Update Tests."""
1513
16 test_qml_file = "/usr/share/click-update-manager/updatemanager.qml"
17
18 def test_UI_is_loaded(self):
19 """Must be able to see the mainview."""
20
21 mainView = self.get_mainview()
22 self.assertThat(mainView.visible, Eventually(Equals(True)))
23
24 def test_loading_disappear(self):14 def test_loading_disappear(self):
25 """Check the loading indicator disappears"""15 """Check the loading indicator disappears"""
2616
27 loading = self.get_object(objectName="loadingIndicator")17 loading = self.main_view.select_single(objectName="loadingIndicator")
28 self.assertThat(loading.visible, Eventually(Equals(False)))18 self.assertThat(loading.visible, Eventually(Equals(False)))
2919
30 def test_check_again(self):20 def test_check_again(self):
31 """Check the loading indicator disappears"""21 """Check the loading indicator disappears"""
3222
33 loading = self.get_object(objectName="loadingIndicator")23 loading = self.main_view.select_single(objectName="loadingIndicator")
34 self.assertThat(loading.visible, Eventually(Equals(False)))24 self.assertThat(loading.visible, Eventually(Equals(False)))
35 self.mouse_click(objectName="retryButton")25 retry_button = self.main_view.select_single(objectName="retryButton")
26 self.pointing_device.click_object(retry_button)
36 self.assertThat(loading.visible, Eventually(Equals(True)))27 self.assertThat(loading.visible, Eventually(Equals(True)))
37 self.assertThat(loading.visible, Eventually(Equals(False)))28 self.assertThat(loading.visible, Eventually(Equals(False)))

Subscribers

People subscribed via source and target branches

to all changes: