Merge lp:~nskaggs/ubuntu-filemanager-app/fix-1367453 into lp:ubuntu-filemanager-app

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Alan Pope 🍺🐧🐱 πŸ¦„
Approved revision: 294
Merged at revision: 296
Proposed branch: lp:~nskaggs/ubuntu-filemanager-app/fix-1367453
Merge into: lp:ubuntu-filemanager-app
Diff against target: 131 lines (+101/-6)
1 file modified
tests/autopilot/filemanager/tests/__init__.py (+101/-6)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-filemanager-app/fix-1367453
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Ubuntu File Manager Developers Pending
Review via email: mp+236628@code.launchpad.net

Commit message

Finish fixing bug 1367453

Description of the change

Finish fixing bug 1367453

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)
294. By Nicholas Skaggs

flake8 love

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/filemanager/tests/__init__.py'
2--- tests/autopilot/filemanager/tests/__init__.py 2014-09-22 22:52:54 +0000
3+++ tests/autopilot/filemanager/tests/__init__.py 2014-09-30 22:38:46 +0000
4@@ -29,6 +29,7 @@
5 from autopilot.testcase import AutopilotTestCase
6 from testtools.matchers import Equals
7 import ubuntuuitoolkit
8+from ubuntuuitoolkit import fixture_setup as toolkit_fixtures
9
10 import filemanager
11 from filemanager import fixture_setup as fm_fixtures
12@@ -197,19 +198,113 @@
13 def _patch_home(self):
14 """ mock /home for testing purposes to preserve user data
15 """
16- temp_dir_fixture = fixtures.TempDir()
17+
18+ original_home = os.environ.get('HOME')
19+ original_app_launch = os.environ.get('UBUNTU_APP_LAUNCH_LINK_FARM')
20+ original_xdg_config_home = os.environ.get('XDG_CONFIG_HOME')
21+
22+ # click requires apparmor profile, and writing to special dir
23+ # but the desktop can write to a traditional /tmp directory
24+ if self.test_type == 'click':
25+ env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',
26+ 'fakeenv')
27+
28+ if not os.path.exists(env_dir):
29+ os.makedirs(env_dir)
30+
31+ temp_dir_fixture = fixtures.TempDir(env_dir)
32+ else:
33+ temp_dir_fixture = fixtures.TempDir()
34+
35+ # setup fixture paths
36 self.useFixture(temp_dir_fixture)
37 temp_dir = temp_dir_fixture.path
38 temp_xdg_config_home = os.path.join(temp_dir, '.config')
39+ temp_app_launch = os.path.join(temp_dir, '.cache',
40+ 'ubuntu-app-launch', 'desktop')
41+
42+ # create the needed directores
43+ if not os.path.exists(temp_xdg_config_home):
44+ os.makedirs(temp_xdg_config_home)
45+ if not os.path.exists(temp_app_launch):
46+ os.makedirs(temp_app_launch)
47+
48+ # for click, we need to create additional directories
49+ # apparmor doesn't allow the app to create needed directories,
50+ # so we create them now
51+ if self.test_type == 'click':
52+ temp_dir_cache = os.path.join(temp_dir, '.cache')
53+ temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
54+ temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
55+ temp_dir_cache_write = os.path.join(temp_dir_cache,
56+ 'tncache-write-text.null')
57+ temp_dir_config = os.path.join(temp_dir, '.config')
58+ temp_dir_toolkit = os.path.join(temp_dir_config,
59+ 'ubuntu-ui-toolkit')
60+ temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
61+ temp_dir_local = os.path.join(temp_dir, '.local', 'share')
62+ temp_dir_confined = os.path.join(temp_dir, 'confined')
63+
64+ if not os.path.exists(temp_dir_cache):
65+ os.makedirs(temp_dir_cache)
66+ if not os.path.exists(temp_dir_cache_font):
67+ os.makedirs(temp_dir_cache_font)
68+ if not os.path.exists(temp_dir_cache_media):
69+ os.makedirs(temp_dir_cache_media)
70+ if not os.path.exists(temp_dir_cache_write):
71+ os.makedirs(temp_dir_cache_write)
72+ if not os.path.exists(temp_dir_config):
73+ os.makedirs(temp_dir_config)
74+ if not os.path.exists(temp_dir_toolkit):
75+ os.makedirs(temp_dir_toolkit)
76+ if not os.path.exists(temp_dir_font):
77+ os.makedirs(temp_dir_font)
78+ if not os.path.exists(temp_dir_local):
79+ os.makedirs(temp_dir_local)
80+ if not os.path.exists(temp_dir_confined):
81+ os.makedirs(temp_dir_confined)
82
83 # before we set fixture, copy xauthority if needed
84 self._copy_xauthority_file(temp_dir)
85
86- self.useFixture(
87- fixtures.EnvironmentVariable('HOME', newvalue=temp_dir))
88- self.useFixture(
89- fixtures.EnvironmentVariable(
90- 'XDG_CONFIG_HOME', newvalue=temp_xdg_config_home))
91+ # set the fixture
92+ # for click, use initctl, otherwise set env directly
93+ if self.test_type == 'click':
94+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
95+ HOME=temp_dir))
96+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
97+ XDG_CONFIG_HOME=temp_xdg_config_home))
98+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
99+ UBUNTU_APP_LAUNCH_LINK_FARM=temp_app_launch))
100+
101+ else:
102+ self.useFixture(fixtures.EnvironmentVariable('HOME',
103+ newvalue=temp_dir))
104+ self.useFixture(fixtures.EnvironmentVariable(
105+ 'XDG_CONFIG_HOME', newvalue=temp_xdg_config_home))
106+ self.useFixture(fixtures.EnvironmentVariable(
107+ 'UBUNTU_APP_LAUNCH_LINK_FARM', newvalue=temp_app_launch))
108+
109+ # For now, blow away actual env vars and restore
110+ # TODO: Remove code once pad.lv/1370800 is fixed
111+ def undo_patch(key, value):
112+ logging.info(
113+ "Resetting environment variable '%s' to '%s'",
114+ key,
115+ value
116+ )
117+
118+ os.environ[key] = value
119+
120+ os.environ['HOME'] = temp_dir
121+ os.environ['XDG_CONFIG_HOME'] = temp_xdg_config_home
122+ os.environ['UBUNTU_APP_LAUNCH_LINK_FARM'] = temp_app_launch
123+
124+ self.addCleanup(undo_patch, 'HOME', original_home)
125+ self.addCleanup(undo_patch, 'UBUNTU_APP_LAUNCH_LINK_FARM',
126+ original_app_launch or '')
127+ self.addCleanup(undo_patch, 'XDG_CONFIG_HOME',
128+ original_xdg_config_home or '')
129
130 logger.debug("Patched home to fake home directory %s" % temp_dir)
131 return temp_dir

Subscribers

People subscribed via source and target branches