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
=== modified file 'tests/autopilot/reminders/tests/__init__.py'
--- tests/autopilot/reminders/tests/__init__.py 2014-04-04 06:09:17 +0000
+++ tests/autopilot/reminders/tests/__init__.py 2014-05-08 17:05:14 +0000
@@ -17,7 +17,7 @@
17"""Reminders app autopilot tests."""17"""Reminders app autopilot tests."""
1818
19import os19import os
20import os.path20import shutil
21import logging21import logging
2222
23import fixtures23import fixtures
@@ -25,7 +25,10 @@
25from autopilot.input import Mouse, Touch, Pointer25from autopilot.input import Mouse, Touch, Pointer
26from autopilot.platform import model26from autopilot.platform import model
27from autopilot.testcase import AutopilotTestCase27from autopilot.testcase import AutopilotTestCase
28from ubuntuuitoolkit import emulators as toolkit_emulators28from ubuntuuitoolkit import (
29 emulators as toolkit_emulators,
30 fixture_setup as toolkit_fixtures
31)
2932
30import reminders33import reminders
3134
@@ -41,22 +44,67 @@
41 else:44 else:
42 scenarios = [('with touch', dict(input_device_class=Touch))]45 scenarios = [('with touch', dict(input_device_class=Touch))]
4346
44 local_location_binary = '../../src/app/reminders'47 local_location = os.path.dirname(os.path.dirname(os.getcwd()))
48 local_location_qml = local_location + "/reminders.qml"
49 local_location_binary = os.path.join(local_location, 'src/app/reminders')
45 installed_location_binary = '/usr/bin/reminders'50 installed_location_binary = '/usr/bin/reminders'
46 installed_location_qml = '/usr/share/reminders/qml/reminders.qml'51 installed_location_qml = '/usr/share/reminders/qml/reminders.qml'
4752
53 def get_launcher_and_type(self):
54 if os.path.exists(self.local_location_qml):
55 launcher = self.launch_test_local
56 test_type = 'local'
57 elif os.path.exists(self.installed_location_qml):
58 launcher = self.launch_test_installed
59 test_type = 'deb'
60 else:
61 launcher = self.launch_test_click
62 test_type = 'click'
63 return launcher, test_type
64
48 def setUp(self):65 def setUp(self):
66 launcher, self.test_type = self.get_launcher_and_type()
67 self.home_dir = self._patch_home()
49 self.pointing_device = Pointer(self.input_device_class.create())68 self.pointing_device = Pointer(self.input_device_class.create())
50 super(RemindersAppTestCase, self).setUp()69 super(RemindersAppTestCase, self).setUp()
5170
52 if os.path.exists(self.local_location_binary):71 self.app = reminders.RemindersApp(launcher())
53 app_proxy = self.launch_test_local()72
54 elif os.path.exists(self.installed_location_binary):73 def _copy_xauthority_file(self, directory):
55 app_proxy = self.launch_test_installed()74 """ Copy .Xauthority file to directory, if it exists in /home
75 """
76 xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
77 if os.path.isfile(xauth):
78 logger.debug("Copying .Xauthority to " + directory)
79 shutil.copyfile(
80 os.path.expanduser(os.path.join('~', '.Xauthority')),
81 os.path.join(directory, '.Xauthority'))
82
83 def _patch_home(self):
84 """ mock /home for testing purposes to preserve user data
85 """
86 temp_dir_fixture = fixtures.TempDir()
87 self.useFixture(temp_dir_fixture)
88 temp_dir = temp_dir_fixture.path
89
90 #If running under xvfb, as jenkins does,
91 #xsession will fail to start without xauthority file
92 #Thus if the Xauthority file is in the home directory
93 #make sure we copy it to our temp home directory
94 self._copy_xauthority_file(temp_dir)
95
96 #click requires using initctl env (upstart), but the desktop can set
97 #an environment variable instead
98 if self.test_type == 'click':
99 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
100 HOME=temp_dir))
56 else:101 else:
57 app_proxy = self.launch_test_click()102 self.useFixture(fixtures.EnvironmentVariable('HOME',
58103 newvalue=temp_dir))
59 self.app = reminders.RemindersApp(app_proxy)104
105 logger.debug("Patched home to fake home directory " + temp_dir)
106
107 return temp_dir
60108
61 @autopilot_logging.log_action(logger.info)109 @autopilot_logging.log_action(logger.info)
62 def launch_test_local(self):110 def launch_test_local(self):
@@ -64,6 +112,7 @@
64 'QML2_IMPORT_PATH', newvalue='../../src/plugin'))112 'QML2_IMPORT_PATH', newvalue='../../src/plugin'))
65 return self.launch_test_application(113 return self.launch_test_application(
66 self.local_location_binary,114 self.local_location_binary,
115 '-q', self.local_location_qml,
67 app_type='qt',116 app_type='qt',
68 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)117 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
69118
@@ -80,5 +129,5 @@
80 @autopilot_logging.log_action(logger.info)129 @autopilot_logging.log_action(logger.info)
81 def launch_test_click(self):130 def launch_test_click(self):
82 return self.launch_click_package(131 return self.launch_click_package(
83 'com.ubuntu.reminders-app',132 'com.ubuntu.reminders',
84 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)133 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)

Subscribers

People subscribed via source and target branches

to all changes: