Merge lp:~nskaggs/reminders-app/setup-ap-env into lp:~elopio/reminders-app/test_with_account

Proposed by Nicholas Skaggs
Status: Superseded
Proposed branch: lp:~nskaggs/reminders-app/setup-ap-env
Merge into: lp:~elopio/reminders-app/test_with_account
Diff against target: 115 lines (+60/-11)
1 file modified
tests/autopilot/reminders/tests/__init__.py (+60/-11)
To merge this branch: bzr merge lp:~nskaggs/reminders-app/setup-ap-env
Reviewer Review Type Date Requested Status
Ubuntu Notes app developers Pending
Review via email: mp+218844@code.launchpad.net

Description of the change

Properly setup environment for autopilot testing by using a faked /home directory on phablet and desktop

To post a comment you must log in.
125. By Nicholas Skaggs

add _copy_xauthority_file rename setup env

Unmerged revisions

125. By Nicholas Skaggs

add _copy_xauthority_file rename setup env

124. By Nicholas Skaggs

switch to fixtures

123. By Nicholas Skaggs

setup env properly for test run

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/reminders/tests/__init__.py'
2--- tests/autopilot/reminders/tests/__init__.py 2014-04-04 06:09:17 +0000
3+++ tests/autopilot/reminders/tests/__init__.py 2014-05-08 17:05:14 +0000
4@@ -17,7 +17,7 @@
5 """Reminders app autopilot tests."""
6
7 import os
8-import os.path
9+import shutil
10 import logging
11
12 import fixtures
13@@ -25,7 +25,10 @@
14 from autopilot.input import Mouse, Touch, Pointer
15 from autopilot.platform import model
16 from autopilot.testcase import AutopilotTestCase
17-from ubuntuuitoolkit import emulators as toolkit_emulators
18+from ubuntuuitoolkit import (
19+ emulators as toolkit_emulators,
20+ fixture_setup as toolkit_fixtures
21+)
22
23 import reminders
24
25@@ -41,22 +44,67 @@
26 else:
27 scenarios = [('with touch', dict(input_device_class=Touch))]
28
29- local_location_binary = '../../src/app/reminders'
30+ local_location = os.path.dirname(os.path.dirname(os.getcwd()))
31+ local_location_qml = local_location + "/reminders.qml"
32+ local_location_binary = os.path.join(local_location, 'src/app/reminders')
33 installed_location_binary = '/usr/bin/reminders'
34 installed_location_qml = '/usr/share/reminders/qml/reminders.qml'
35
36+ def get_launcher_and_type(self):
37+ if os.path.exists(self.local_location_qml):
38+ launcher = self.launch_test_local
39+ test_type = 'local'
40+ elif os.path.exists(self.installed_location_qml):
41+ launcher = self.launch_test_installed
42+ test_type = 'deb'
43+ else:
44+ launcher = self.launch_test_click
45+ test_type = 'click'
46+ return launcher, test_type
47+
48 def setUp(self):
49+ launcher, self.test_type = self.get_launcher_and_type()
50+ self.home_dir = self._patch_home()
51 self.pointing_device = Pointer(self.input_device_class.create())
52 super(RemindersAppTestCase, self).setUp()
53
54- if os.path.exists(self.local_location_binary):
55- app_proxy = self.launch_test_local()
56- elif os.path.exists(self.installed_location_binary):
57- app_proxy = self.launch_test_installed()
58+ self.app = reminders.RemindersApp(launcher())
59+
60+ def _copy_xauthority_file(self, directory):
61+ """ Copy .Xauthority file to directory, if it exists in /home
62+ """
63+ xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
64+ if os.path.isfile(xauth):
65+ logger.debug("Copying .Xauthority to " + directory)
66+ shutil.copyfile(
67+ os.path.expanduser(os.path.join('~', '.Xauthority')),
68+ os.path.join(directory, '.Xauthority'))
69+
70+ def _patch_home(self):
71+ """ mock /home for testing purposes to preserve user data
72+ """
73+ temp_dir_fixture = fixtures.TempDir()
74+ self.useFixture(temp_dir_fixture)
75+ temp_dir = temp_dir_fixture.path
76+
77+ #If running under xvfb, as jenkins does,
78+ #xsession will fail to start without xauthority file
79+ #Thus if the Xauthority file is in the home directory
80+ #make sure we copy it to our temp home directory
81+ self._copy_xauthority_file(temp_dir)
82+
83+ #click requires using initctl env (upstart), but the desktop can set
84+ #an environment variable instead
85+ if self.test_type == 'click':
86+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
87+ HOME=temp_dir))
88 else:
89- app_proxy = self.launch_test_click()
90-
91- self.app = reminders.RemindersApp(app_proxy)
92+ self.useFixture(fixtures.EnvironmentVariable('HOME',
93+ newvalue=temp_dir))
94+
95+ logger.debug("Patched home to fake home directory " + temp_dir)
96+
97+ return temp_dir
98
99 @autopilot_logging.log_action(logger.info)
100 def launch_test_local(self):
101@@ -64,6 +112,7 @@
102 'QML2_IMPORT_PATH', newvalue='../../src/plugin'))
103 return self.launch_test_application(
104 self.local_location_binary,
105+ '-q', self.local_location_qml,
106 app_type='qt',
107 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
108
109@@ -80,5 +129,5 @@
110 @autopilot_logging.log_action(logger.info)
111 def launch_test_click(self):
112 return self.launch_click_package(
113- 'com.ubuntu.reminders-app',
114+ 'com.ubuntu.reminders',
115 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)

Subscribers

People subscribed via source and target branches

to all changes: