Merge lp:~nskaggs/ubuntu-calendar-app/mock-test-env into lp:ubuntu-calendar-app

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 271
Merged at revision: 267
Proposed branch: lp:~nskaggs/ubuntu-calendar-app/mock-test-env
Merge into: lp:ubuntu-calendar-app
Diff against target: 186 lines (+76/-59)
1 file modified
tests/autopilot/calendar_app/tests/__init__.py (+76/-59)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-calendar-app/mock-test-env
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+218494@code.launchpad.net

Commit message

Properly setup / teardown AP tests by using mock and env_var

Description of the change

Properly setup / teardown AP tests by using mock and env_var

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
267. By Nicholas Skaggs

streamline and standardizing launching

268. By Nicholas Skaggs

fix typo

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
269. By Nicholas Skaggs

switch to fixtures

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
270. By Nicholas Skaggs

make xauthority copy a seperate method

271. By Nicholas Skaggs

rename setup env method

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Leo Arias (elopio) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/calendar_app/tests/__init__.py'
2--- tests/autopilot/calendar_app/tests/__init__.py 2014-03-20 16:13:43 +0000
3+++ tests/autopilot/calendar_app/tests/__init__.py 2014-05-08 17:04:50 +0000
4@@ -14,20 +14,25 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-
9-"""calendar-app autopilot tests."""
10-
11-import os.path
12+"""Calendar app autopilot tests."""
13+
14 import os
15 import shutil
16 import logging
17
18+import fixtures
19+from calendar_app import emulators
20+
21 from autopilot.input import Mouse, Touch, Pointer
22 from autopilot.platform import model
23 from autopilot.testcase import AutopilotTestCase
24+from autopilot import logging as autopilot_logging
25
26-from ubuntuuitoolkit import emulators as toolkit_emulators
27-from calendar_app import emulators
28+from ubuntuuitoolkit import (
29+ base,
30+ emulators as toolkit_emulators,
31+ fixture_setup as toolkit_fixtures
32+)
33
34 logger = logging.getLogger(__name__)
35
36@@ -43,85 +48,97 @@
37 else:
38 scenarios = [('with touch', dict(input_device_class=Touch))]
39
40- local_location = "../../calendar.qml"
41- installed_location = "/usr/share/calendar-app/calendar.qml"
42- sqlite_dir = os.path.expanduser(
43- "~/.local/share/com.ubuntu.calendar/Databases")
44- backup_dir = sqlite_dir + ".backup"
45+ local_location = os.path.dirname(os.path.dirname(os.getcwd()))
46+ local_location_qml = local_location + "/calendar.qml"
47+ installed_location_qml = "/usr/share/calendar-app/calendar.qml"
48+
49+ def get_launcher_and_type(self):
50+ if os.path.exists(self.local_location_qml):
51+ launcher = self.launch_test_local
52+ test_type = 'local'
53+ elif os.path.exists(self.installed_location_qml):
54+ launcher = self.launch_test_installed
55+ test_type = 'deb'
56+ else:
57+ launcher = self.launch_test_click
58+ test_type = 'click'
59+ return launcher, test_type
60
61 def setUp(self):
62+ launcher, self.test_type = self.get_launcher_and_type()
63+ self.home_dir = self._patch_home()
64 self.pointing_device = Pointer(self.input_device_class.create())
65 super(CalendarTestCase, self).setUp()
66- self.temp_move_sqlite_db()
67- self.addCleanup(self.restore_sqlite_db)
68
69 #turn off the OSK so it doesn't block screen elements
70 if model() != 'Desktop':
71- os.system("stop maliit-server")
72- self.addCleanup(os.system, "start maliit-server")
73+ os.system('stop maliit-server')
74+ self.addCleanup(os.system, 'start maliit-server')
75
76 # Unset the current locale to ensure locale-specific data
77 # (day and month names, first day of the week, …) doesn’t get
78 # in the way of test expectations.
79 self.patch_environment('LC_ALL', 'C')
80
81- if os.path.exists(self.local_location):
82- self.launch_test_local()
83- elif os.path.exists(self.installed_location):
84- self.launch_test_installed()
85- else:
86- self.launch_test_click()
87+ self.app = launcher()
88
89+ @autopilot_logging.log_action(logger.info)
90 def launch_test_local(self):
91- logger.debug("Running via local installation")
92- self.app = self.launch_test_application(
93- "qmlscene",
94- self.local_location,
95+ return self.launch_test_application(
96+ base.get_qmlscene_launch_command(),
97+ self.local_location_qml,
98 app_type='qt',
99 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
100
101+ @autopilot_logging.log_action(logger.info)
102 def launch_test_installed(self):
103- logger.debug("Running via installed debian package")
104- self.app = self.launch_test_application(
105- "qmlscene",
106- self.installed_location,
107+ return self.launch_test_application(
108+ base.get_qmlscene_launch_command(),
109+ self.installed_location_qml,
110 app_type='qt',
111 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
112
113+ @autopilot_logging.log_action(logger.info)
114 def launch_test_click(self):
115- logger.debug("Running via click package")
116- self.app = self.launch_click_package(
117+ return self.launch_click_package(
118 "com.ubuntu.calendar",
119 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
120
121- def temp_move_sqlite_db(self):
122- try:
123- shutil.rmtree(self.backup_dir)
124- except:
125- pass
126- else:
127- logger.warning("Prexisting backup database found and removed")
128-
129- try:
130- shutil.move(self.sqlite_dir, self.backup_dir)
131- except:
132- logger.warning("No current database found")
133- else:
134- logger.debug("Backed up database")
135-
136- def restore_sqlite_db(self):
137- if os.path.exists(self.backup_dir):
138- if os.path.exists(self.sqlite_dir):
139- try:
140- shutil.rmtree(self.sqlite_dir)
141- except:
142- logger.error("Failed to remove test database and restore" /
143- "database")
144- return
145- try:
146- shutil.move(self.backup_dir, self.sqlite_dir)
147- except:
148- logger.error("Failed to restore database")
149+ def _copy_xauthority_file(self, directory):
150+ """ Copy .Xauthority file to directory, if it exists in /home
151+ """
152+ xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
153+ if os.path.isfile(xauth):
154+ logger.debug("Copying .Xauthority to " + directory)
155+ shutil.copyfile(
156+ os.path.expanduser(os.path.join('~', '.Xauthority')),
157+ os.path.join(directory, '.Xauthority'))
158+
159+ def _patch_home(self):
160+ """ mock /home for testing purposes to preserve user data
161+ """
162+ temp_dir_fixture = fixtures.TempDir()
163+ self.useFixture(temp_dir_fixture)
164+ temp_dir = temp_dir_fixture.path
165+
166+ #If running under xvfb, as jenkins does,
167+ #xsession will fail to start without xauthority file
168+ #Thus if the Xauthority file is in the home directory
169+ #make sure we copy it to our temp home directory
170+ self._copy_xauthority_file(temp_dir)
171+
172+ #click requires using initctl env (upstart), but the desktop can set
173+ #an environment variable instead
174+ if self.test_type == 'click':
175+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
176+ HOME=temp_dir))
177+ else:
178+ self.useFixture(fixtures.EnvironmentVariable('HOME',
179+ newvalue=temp_dir))
180+
181+ logger.debug("Patched home to fake home directory " + temp_dir)
182+
183+ return temp_dir
184
185 @property
186 def main_view(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: