Merge lp:~diegosarmentero/ubuntuone-client/fix-user-home-tests into lp:ubuntuone-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1187
Merged at revision: 1182
Proposed branch: lp:~diegosarmentero/ubuntuone-client/fix-user-home-tests
Merge into: lp:ubuntuone-client
Diff against target: 357 lines (+13/-71)
13 files modified
contrib/testing/testcase.py (+4/-5)
tests/platform/linux/eventlog/test_zg_listener.py (+0/-14)
tests/platform/linux/test_filesystem_notifications.py (+0/-1)
tests/platform/linux/test_vm.py (+4/-2)
tests/platform/test_filesystem_notifications.py (+0/-1)
tests/platform/test_os_helper.py (+3/-6)
tests/platform/test_tools.py (+0/-3)
tests/syncdaemon/test_action_queue.py (+1/-13)
tests/syncdaemon/test_eq_inotify.py (+0/-4)
tests/syncdaemon/test_eventqueue.py (+0/-1)
tests/syncdaemon/test_localrescan.py (+0/-14)
tests/syncdaemon/test_main.py (+1/-0)
tests/syncdaemon/test_vm.py (+0/-7)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-client/fix-user-home-tests
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Brian Curtin (community) Approve
Review via email: mp+88919@code.launchpad.net

Commit message

- Fixed: tests are now not modifying the real user home (LP: #915380).

Description of the change

Just some fixes in the tests.

To post a comment you must log in.
1181. By Diego Sarmentero

Tests Fixed. Home patching made in BaseTwistedTestCase

1182. By Diego Sarmentero

fixed tests.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

* Though FakeMainTestCase used to use self.tmpdir as homke dir, it is more correct to use a dedicated dir for that, so we can isolate home data into a dir (we may need that to debug a test).

Can you please make self.home_dir = self.mktemp('ubuntuonehacker')?

* Also, in tests/syncdaemon/test_action_queue.py you're removing the patch os.environ['HOME'] = self.home, which is great, but the self.home variable should point to the same home that the base test case is using to patch the xdg_home var. So, I would guess that in BasicTestCase we need to change:

        self.home = self.mktemp('home')

for

        self.home = self.home_dir

(please confirm this makes sense before changing it, I did not reviewed the whole test module).

* There are several tests that are re-defining self.home_dir and re-patching xdg_home... can you please remove that? (we need to confirm they all inherit from BaseTwistedTestCase either directly or by some inheritance chain). A quick grep gives me:

nessita@dali:~/canonical/client/review_fix-user-home-tests$ grep -rn --color "patch.*xdg_home" *
contrib/testing/testcase.py:383: self.patch(platform, "xdg_home", self.home_dir)
tests/syncdaemon/test_localrescan.py:134: self.patch(platform, 'xdg_home', self.home_dir)
tests/syncdaemon/test_localrescan.py:374: self.patch(platform, 'xdg_home', self.home_dir)
tests/syncdaemon/test_localrescan.py:2021: self.patch(platform, 'xdg_home', self.home_dir)
tests/syncdaemon/test_localrescan.py:2260: self.patch(platform, 'xdg_home', self.home_dir)
tests/syncdaemon/test_config.py:534: self.patch(platform, 'xdg_home', homedir)
tests/syncdaemon/test_main.py:267: self.patch(main_mod, "xdg_home", self.home_dir)
tests/syncdaemon/test_eq_inotify.py:664: self.patch(platform, 'xdg_home', self.home_dir)
tests/platform/test_os_helper.py:95: self.patch(platform, "xdg_home", self.my_home)
nessita@dali:~/canonical/client/review_fix-user-home-tests$

nessita@dali:~/canonical/client/review_fix-user-home-tests$ grep -rn --color "self\.home_dir =" *
contrib/testing/testcase.py:382: self.home_dir = self.tmpdir
tests/syncdaemon/test_vm.py:3739: self.home_dir = self.mktemp('ubuntuonehacker')
tests/syncdaemon/test_localrescan.py:126: self.home_dir = self.mktemp('ubuntuonehacker')
tests/syncdaemon/test_eventqueue.py:46: self.home_dir = self.mktemp('home_dir')
tests/syncdaemon/test_eq_inotify.py:649: self.home_dir = self.mktemp('ubuntuonehacker')
tests/platform/linux/test_vm.py:464: self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker')
tests/platform/linux/test_filesystem_notifications.py:102: self.home_dir = self.mktemp('home_dir')
tests/platform/test_filesystem_notifications.py:102: self.home_dir = self.mktemp('home_dir')
nessita@dali:~/canonical/client/review_fix-user-home-tests$

review: Needs Fixing
1183. By Diego Sarmentero

Refactor involving home_dir

1184. By Diego Sarmentero

Remove commented lines

1185. By Diego Sarmentero

merge

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I'm getting all these failures in Linux http://pastebin.ubuntu.com/809586/

review: Needs Fixing
1186. By Diego Sarmentero

merge

1187. By Diego Sarmentero

Tests fixed

Revision history for this message
Brian Curtin (brian.curtin) wrote :

This looks better to me.

Revision history for this message
Brian Curtin (brian.curtin) wrote :

(forgot to approve)

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/testing/testcase.py'
2--- contrib/testing/testcase.py 2011-12-29 14:44:10 +0000
3+++ contrib/testing/testcase.py 2012-01-23 20:01:25 +0000
4@@ -48,6 +48,7 @@
5 tritcask,
6 )
7 from ubuntuone.syncdaemon import logger
8+from ubuntuone import platform
9 from ubuntuone.platform import (
10 can_write,
11 make_dir,
12@@ -377,6 +378,9 @@
13 self.log = logging.getLogger("ubuntuone.SyncDaemon.TEST")
14 self.log.info("starting test %s.%s", self.__class__.__name__,
15 self._testMethodName)
16+ # Patch the user home
17+ self.home_dir = self.mktemp('ubuntuonehacker')
18+ self.patch(platform, "xdg_home", self.home_dir)
19
20
21 class FakeMainTestCase(BaseTwistedTestCase):
22@@ -389,11 +393,6 @@
23 """Setup the infrastructure for the test."""
24 yield super(FakeMainTestCase, self).setUp()
25
26- self.home_dir = self.tmpdir
27- old_home = os.environ['HOME']
28- os.environ['HOME'] = self.home_dir
29- self.addCleanup(os.environ.__setitem__, 'HOME', old_home)
30-
31 self.data_dir = self.mktemp('data_dir')
32 self.partials_dir = self.mktemp('partials')
33 self.root_dir = self.mktemp('root_dir')
34
35=== modified file 'tests/platform/linux/eventlog/test_zg_listener.py'
36--- tests/platform/linux/eventlog/test_zg_listener.py 2011-11-09 20:03:15 +0000
37+++ tests/platform/linux/eventlog/test_zg_listener.py 2012-01-23 20:01:25 +0000
38@@ -368,20 +368,6 @@
39 class ZeitgeistUDFsTestCase(ZeitgeistListenerTestCase):
40 """Tests for all UDFs-related zeitgeist events."""
41
42- @defer.inlineCallbacks
43- def setUp(self):
44- """Initialize this test instance."""
45- yield super(ZeitgeistUDFsTestCase, self).setUp()
46- self.home_dir = self.mktemp('ubuntuonehacker')
47- self._old_home = os.environ['HOME']
48- os.environ['HOME'] = self.home_dir
49-
50- @defer.inlineCallbacks
51- def tearDown(self):
52- """Finalize this test instance."""
53- os.environ['HOME'] = self._old_home
54- yield super(ZeitgeistUDFsTestCase, self).tearDown()
55-
56 def _create_udf(self, id, node_id, suggested_path, subscribed=True):
57 """Create an UDF and returns it and the volume."""
58 path = get_udf_path(suggested_path)
59
60=== modified file 'tests/platform/linux/test_filesystem_notifications.py'
61--- tests/platform/linux/test_filesystem_notifications.py 2011-09-02 16:09:41 +0000
62+++ tests/platform/linux/test_filesystem_notifications.py 2012-01-23 20:01:25 +0000
63@@ -99,7 +99,6 @@
64 fsmdir = self.mktemp('fsmdir')
65 partials_dir = self.mktemp('partials_dir')
66 self.root_dir = self.mktemp('root_dir')
67- self.home_dir = self.mktemp('home_dir')
68 self.vm = testcase.FakeVolumeManager(self.root_dir)
69 self.tritcask_dir = self.mktemp("tritcask_dir")
70 self.db = Tritcask(self.tritcask_dir)
71
72=== modified file 'tests/platform/linux/test_vm.py'
73--- tests/platform/linux/test_vm.py 2011-11-17 19:19:08 +0000
74+++ tests/platform/linux/test_vm.py 2012-01-23 20:01:25 +0000
75@@ -459,9 +459,11 @@
76 @defer.inlineCallbacks
77 def setUp(self):
78 yield super(MetadataNewLayoutTests, self).setUp()
79- self.share_md_dir = os.path.join(self.vm_data_dir, 'shares')
80- self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared')
81+ # We need to define home_dir here to add 'home' to the path
82+ # and avoid crashes between existing paths.
83 self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker')
84+ self.share_md_dir = os.path.join(self.vm_data_dir, 'shares')
85+ self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared')
86 self.u1_dir = os.path.join(self.home_dir, os.path.split(self.u1_dir)[1])
87 self.root_dir = self.u1_dir
88 self.shares_dir = os.path.join(self.tmpdir, 'shares')
89
90=== modified file 'tests/platform/test_filesystem_notifications.py'
91--- tests/platform/test_filesystem_notifications.py 2011-10-21 13:40:09 +0000
92+++ tests/platform/test_filesystem_notifications.py 2012-01-23 20:01:25 +0000
93@@ -99,7 +99,6 @@
94 fsmdir = self.mktemp('fsmdir')
95 partials_dir = self.mktemp('partials_dir')
96 self.root_dir = self.mktemp('root_dir')
97- self.home_dir = self.mktemp('home_dir')
98 self.vm = FakeVolumeManager(self.root_dir)
99 self.tritcask_dir = self.mktemp("tritcask_dir")
100 self.db = Tritcask(self.tritcask_dir)
101
102=== modified file 'tests/platform/test_os_helper.py'
103--- tests/platform/test_os_helper.py 2012-01-12 14:01:38 +0000
104+++ tests/platform/test_os_helper.py 2012-01-23 20:01:25 +0000
105@@ -28,7 +28,6 @@
106 BaseTwistedTestCase,
107 skip_if_win32_and_uses_readonly,
108 )
109-from ubuntuone import platform
110 from ubuntuone.platform import (
111 access,
112 allow_writes,
113@@ -91,8 +90,6 @@
114 yield super(OSWrapperTests, self).setUp(
115 test_dir_name=test_dir_name, test_file_name=test_file_name,
116 valid_file_path_builder=valid_file_path_builder)
117- self.my_home = 'myhome'
118- self.patch(platform, "xdg_home", self.my_home)
119 # make sure the file exists
120 open_file(self.testfile, 'w').close()
121
122@@ -395,21 +392,21 @@
123 """Test the expand_user function with a path like: ~/userpath."""
124 path = os.path.join('~', 'userpath')
125 result = expand_user(path)
126- expected = os.path.join(self.my_home, 'userpath')
127+ expected = os.path.join(self.home_dir, 'userpath')
128 self.assertEqual(expected, result)
129
130 def test_expand_user_tilde_and_backslash(self):
131 """Test the expand_user function with tilde and backslash."""
132 tilde = '~' + os.path.sep
133 result = expand_user(tilde)
134- expected = self.my_home + os.path.sep
135+ expected = self.home_dir + os.path.sep
136 self.assertEqual(expected, result)
137
138 def test_expand_user_only_tilde(self):
139 """Test the expand_user function returns with only tilde input."""
140 tilde = '~'
141 result = expand_user(tilde)
142- self.assertEqual(self.my_home, result)
143+ self.assertEqual(self.home_dir, result)
144 self.assertFalse(result.endswith(os.path.sep))
145
146 def test_expand_user_fails_if_not_bytes(self):
147
148=== modified file 'tests/platform/test_tools.py'
149--- tests/platform/test_tools.py 2012-01-11 21:40:51 +0000
150+++ tests/platform/test_tools.py 2012-01-23 20:01:25 +0000
151@@ -31,7 +31,6 @@
152 states,
153 volume_manager,
154 )
155-from ubuntuone import platform
156 from ubuntuone.platform import tools
157 from tests.platform import IPCTestCase
158
159@@ -533,7 +532,6 @@
160 @defer.inlineCallbacks
161 def test_create_folder(self):
162 """Test for Folders.create."""
163- self.patch(platform, 'xdg_home', self.home_dir)
164 path = os.path.join(self.home_dir, u'ñoño')
165 volume_id = 'volume_id'
166 node_id = 'node_id'
167@@ -552,7 +550,6 @@
168 @defer.inlineCallbacks
169 def test_create_folder_error(self):
170 """Test for Folders.create with error."""
171- self.patch(platform, 'xdg_home', self.home_dir)
172 path = os.path.join(self.home_dir, u'ñoño')
173
174 def create_udf(path, name, marker):
175
176=== modified file 'tests/syncdaemon/test_action_queue.py'
177--- tests/syncdaemon/test_action_queue.py 2011-12-20 10:58:38 +0000
178+++ tests/syncdaemon/test_action_queue.py 2012-01-23 20:01:25 +0000
179@@ -219,8 +219,8 @@
180 """Init."""
181 yield super(BasicTestCase, self).setUp()
182
183+ self.home = self.home_dir
184 self.root = self.mktemp('root')
185- self.home = self.mktemp('home')
186 self.data = self.mktemp('data')
187 self.shares = self.mktemp('shares')
188 self.partials = self.mktemp('partials')
189@@ -2532,18 +2532,6 @@
190 """Init."""
191 yield super(FilterEventsTestCase, self).setUp()
192 self.vm = self.main.vm
193- self.old_home = os.environ.get('HOME', None)
194- os.environ['HOME'] = self.home
195-
196- @defer.inlineCallbacks
197- def tearDown(self):
198- """Clean up."""
199- if self.old_home is None:
200- os.environ.pop('HOME')
201- else:
202- os.environ['HOME'] = self.old_home
203-
204- yield super(FilterEventsTestCase, self).tearDown()
205
206
207 class ChangePublicAccessTests(ConnectedBaseTestCase):
208
209=== modified file 'tests/syncdaemon/test_eq_inotify.py'
210--- tests/syncdaemon/test_eq_inotify.py 2011-11-30 19:54:45 +0000
211+++ tests/syncdaemon/test_eq_inotify.py 2012-01-23 20:01:25 +0000
212@@ -34,7 +34,6 @@
213 skip_if_win32_missing_fs_event,
214 )
215 from tests.syncdaemon.test_eventqueue import BaseEQTestCase
216-from ubuntuone import platform
217 from ubuntuone.platform import (
218 make_link,
219 make_dir,
220@@ -646,7 +645,6 @@
221 """Init."""
222 yield super(AncestorsUDFTestCase, self).setUp()
223 self._deferred = defer.Deferred()
224- self.home_dir = self.mktemp('ubuntuonehacker')
225 self.root_dir = self.mktemp('root_dir')
226 self.data_dir = self.mktemp('data_dir')
227 self.shares_dir = self.mktemp('shares_dir')
228@@ -661,8 +659,6 @@
229 self.eq.subscribe(self.listener)
230 self.addCleanup(self.eq.unsubscribe, self.listener)
231
232- self.patch(platform, 'xdg_home', self.home_dir)
233-
234 # create UDF
235 suggested_path = u'~/Documents/Reading/Books/PDFs'
236 udf_id, node_id = 'udf_id', 'node_id'
237
238=== modified file 'tests/syncdaemon/test_eventqueue.py'
239--- tests/syncdaemon/test_eventqueue.py 2011-08-17 13:11:06 +0000
240+++ tests/syncdaemon/test_eventqueue.py 2012-01-23 20:01:25 +0000
241@@ -43,7 +43,6 @@
242 self.fsmdir = self.mktemp('fsmdir')
243 self.partials_dir = self.mktemp('partials_dir')
244 self.root_dir = self.mktemp('root_dir')
245- self.home_dir = self.mktemp('home_dir')
246 self.vm = FakeVolumeManager(self.root_dir)
247 self.db = tritcask.Tritcask(self.mktemp('tritcask'))
248 self.addCleanup(self.db.shutdown)
249
250=== modified file 'tests/syncdaemon/test_localrescan.py'
251--- tests/syncdaemon/test_localrescan.py 2011-11-30 19:54:45 +0000
252+++ tests/syncdaemon/test_localrescan.py 2012-01-23 20:01:25 +0000
253@@ -33,7 +33,6 @@
254 FakeVolumeManager,
255 skip_if_win32_and_uses_readonly,
256 )
257-from ubuntuone import platform
258 from ubuntuone.platform import (
259 make_dir,
260 make_link,
261@@ -123,16 +122,12 @@
262 def setUp(self):
263 """ Setup the test """
264 yield super(BaseTestCase, self).setUp()
265- self.home_dir = self.mktemp('ubuntuonehacker')
266 self.shares_dir = self.mktemp('shares')
267 usrdir = self.mktemp("usrdir")
268 self.fsmdir = self.mktemp("fsmdir")
269 self.partials_dir = self.mktemp("partials")
270 self.tritcask_dir = self.mktemp("tritcask")
271
272- # set the home for the tests
273- self.patch(platform, 'xdg_home', self.home_dir)
274-
275 self.vm = FakeVolumeManager(usrdir)
276 self.db = Tritcask(self.tritcask_dir)
277 self.addCleanup(self.db.shutdown)
278@@ -371,8 +366,6 @@
279 """Init."""
280 yield super(VolumeTestCase, self).setUp()
281
282- self.patch(platform, 'xdg_home', self.home_dir)
283-
284 self.lr = local_rescan.LocalRescan(self.vm, self.fsm, self.eq, self.aq)
285
286 self.volumes = []
287@@ -2016,11 +2009,6 @@
288 """Test what happens with volume roots left in a bad state last time."""
289
290 @defer.inlineCallbacks
291- def setUp(self):
292- yield super(RootBadStateTests, self).setUp()
293- self.patch(platform, 'xdg_home', self.home_dir)
294-
295- @defer.inlineCallbacks
296 def _test_it(self, volume):
297 """Run the bad state test for a specific volume."""
298 path = volume.path
299@@ -2257,8 +2245,6 @@
300
301 self.lr = local_rescan.LocalRescan(self.vm, self.fsm, self.eq, self.aq)
302
303- self.patch(platform, 'xdg_home', self.home_dir)
304-
305 # create UDF
306 suggested_path = u'~/Documents/Reading/Books/PDFs'
307 udf_id, node_id = 'udf_id', 'node_id'
308
309=== modified file 'tests/syncdaemon/test_main.py'
310--- tests/syncdaemon/test_main.py 2012-01-03 12:40:04 +0000
311+++ tests/syncdaemon/test_main.py 2012-01-23 20:01:25 +0000
312@@ -264,6 +264,7 @@
313
314 def test_get_homedir(self):
315 """The get_homedir returns the root dir."""
316+ self.patch(main_mod, "xdg_home", self.home_dir)
317 expected = expand_user('~')
318 main = self.build_main()
319 self.assertEqual(main.get_homedir(), expected)
320
321=== modified file 'tests/syncdaemon/test_vm.py'
322--- tests/syncdaemon/test_vm.py 2011-12-12 19:32:25 +0000
323+++ tests/syncdaemon/test_vm.py 2012-01-23 20:01:25 +0000
324@@ -91,14 +91,12 @@
325 self.log = logging.getLogger("ubuntuone.SyncDaemon.TEST")
326 self.log.info("starting test %s.%s", self.__class__.__name__,
327 self._testMethodName)
328- self.home_dir = self.mktemp('ubuntuonehacker')
329 self.root_dir = self.mktemp(os.path.join('ubuntuonehacker', 'root_dir'))
330 self.data_dir = self.mktemp('data_dir')
331 self.shares_dir = self.mktemp('shares_dir')
332 self.partials_dir = self.mktemp('partials_dir')
333 self.main = FakeMain(self.root_dir, self.shares_dir,
334 self.data_dir, self.partials_dir)
335- self.patch(platform, 'xdg_home', self.home_dir)
336
337 self.watches = set() # keep track of added watches
338
339@@ -124,10 +122,6 @@
340 self.vm.log.addHandler(self.handler)
341 self.addCleanup(self.vm.log.removeHandler, self.handler)
342
343- old_home = os.environ['HOME']
344- os.environ['HOME'] = self.home_dir
345- self.addCleanup(os.environ.__setitem__, 'HOME', old_home)
346-
347 @defer.inlineCallbacks
348 def tearDown(self):
349 """ cleanup main and remove the temp dir """
350@@ -3742,7 +3736,6 @@
351 def setUp(self):
352 """Create some directories."""
353 yield super(MetadataTestCase, self).setUp()
354- self.home_dir = self.mktemp('ubuntuonehacker')
355 self.root_dir = self.mktemp(
356 os.path.join('ubuntuonehacker', 'Ubuntu One'))
357 self.data_dir = os.path.join(self.tmpdir, 'data_dir')

Subscribers

People subscribed via source and target branches