Merge lp:~ralsina/ubuntuone-client/fix_904300 into lp:ubuntuone-client

Proposed by Roberto Alsina
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1176
Merged at revision: 1175
Proposed branch: lp:~ralsina/ubuntuone-client/fix_904300
Merge into: lp:ubuntuone-client
Diff against target: 52 lines (+17/-3)
2 files modified
tests/platform/windows/test_os_helper.py (+13/-1)
ubuntuone/platform/windows/os_helper.py (+4/-2)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-client/fix_904300
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+87073@code.launchpad.net

Commit message

Implement is_root for windows.

Description of the change

Implement is_root for windows.

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

Can you please add a test for this, patching the shell.IsUserAnAdmin? Thanks!

review: Needs Fixing
Revision history for this message
Roberto Alsina (ralsina) wrote :

> Can you please add a test for this, patching the shell.IsUserAnAdmin? Thanks!

Sure, added!

1174. By Roberto Alsina

test

1175. By Roberto Alsina

merged trunk

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

Thanks a lot for adding the test, though you should note that if you remove the "return" under the is_root implementation, the test will keep passing.

You can simplify and improve the test by doing something like:

def test_isanadmin_called(self):
    """Test that shell.IsUserAnAdmin is called."""
    expected = object()
    self.patch(os_helper.shell, 'IsUserAnAdmin', lambda: expected)
    actual = os_helper.is_root()
    self.assertEqual(expected, actual)

(and remove the set_called def).

What do you think?

review: Needs Fixing
Revision history for this message
Roberto Alsina (ralsina) wrote :

> Thanks a lot for adding the test, though you should note that if you remove
> the "return" under the is_root implementation, the test will keep passing.
>
> You can simplify and improve the test by doing something like:
>
> def test_isanadmin_called(self):
> """Test that shell.IsUserAnAdmin is called."""
> expected = object()
> self.patch(os_helper.shell, 'IsUserAnAdmin', lambda: expected)
> actual = os_helper.is_root()
> self.assertEqual(expected, actual)
>
> (and remove the set_called def).
>
> What do you think?

Much better, thanks! Pushed in revno 1176

1176. By Roberto Alsina

improved test as suggested by nessita

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 'tests/platform/windows/test_os_helper.py'
2--- tests/platform/windows/test_os_helper.py 2011-12-14 13:17:30 +0000
3+++ tests/platform/windows/test_os_helper.py 2012-01-03 13:09:25 +0000
4@@ -301,6 +301,7 @@
5 self.assertEqual(errno.ENOENT, exc.errno,
6 'Errno should be file not found.')
7
8+
9 class DecoratorsTestCase(TestCase):
10 """Test case for all the validators and transformers."""
11
12@@ -428,7 +429,6 @@
13 attrs = attrs | FILE_ATTRIBUTE_SYSTEM
14 SetFileAttributesW(path, attrs)
15
16-
17 def test_os_listdir(self):
18 """Test the list dir."""
19 expected_result = self.dirs + self.files
20@@ -466,3 +466,15 @@
21
22 self.patch(os_helper, 'GetFileAttributesW', fake_get_attrs)
23 self.assertFalse(os_helper.native_is_system_path(self.temp))
24+
25+
26+class TestIsRoot(TestCase):
27+
28+ """Tests for the is_root function."""
29+
30+ def test_isanadmin_called(self):
31+ """Test that shell.IsUserAnAdmin is called."""
32+ expected = object()
33+ self.patch(os_helper.shell, 'IsUserAnAdmin', lambda: expected)
34+ actual = os_helper.is_root()
35+ self.assertEqual(expected, actual)
36
37=== modified file 'ubuntuone/platform/windows/os_helper.py'
38--- ubuntuone/platform/windows/os_helper.py 2011-12-13 17:06:17 +0000
39+++ ubuntuone/platform/windows/os_helper.py 2012-01-03 13:09:25 +0000
40@@ -859,8 +859,10 @@
41
42 def is_root():
43 """Return if the user is running as root."""
44- # TODO: Do check if we are running as admin
45- return False
46+ # This solution works on Windows XP, Vista and 7
47+ # The MSDN docs say this may go away in a later version, but look at what
48+ # the alternative is: http://bit.ly/rXbIwc
49+ return shell.IsUserAnAdmin()
50
51
52 @windowspath()

Subscribers

People subscribed via source and target branches