Merge lp:~ddstreet/launchpadlib/sudotests into lp:launchpadlib

Proposed by Dan Streetman on 2020-04-18
Status: Merged
Merged at revision: 182
Proposed branch: lp:~ddstreet/launchpadlib/sudotests
Merge into: lp:launchpadlib
Diff against target: 61 lines (+16/-0)
1 file modified
src/launchpadlib/tests/test_launchpad.py (+16/-0)
To merge this branch: bzr merge lp:~ddstreet/launchpadlib/sudotests
Reviewer Review Type Date Requested Status
Colin Watson 2020-04-18 Approve on 2020-04-19
Review via email: mp+382542@code.launchpad.net
To post a comment you must log in.
Dan Streetman (ddstreet) wrote :
Colin Watson (cjwatson) wrote :

Ah, right, that makes sense. Will merge, thanks!

review: Approve
Colin Watson (cjwatson) wrote :

The packaging change can be avoided by using the standard library unittest.mock instead in the Python 3 case. I'll do that as part of the merge.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/tests/test_launchpad.py'
2--- src/launchpadlib/tests/test_launchpad.py 2019-11-07 17:40:56 +0000
3+++ src/launchpadlib/tests/test_launchpad.py 2020-04-18 20:15:43 +0000
4@@ -19,6 +19,7 @@
5 __metaclass__ = type
6
7 from contextlib import contextmanager
8+from mock import patch
9 import os
10 import shutil
11 import socket
12@@ -612,6 +613,7 @@
13 launchpadlib.launchpad.socket = socket
14 shutil.rmtree(self.temp_dir)
15
16+ @patch.object(NoNetworkLaunchpad, '_is_sudo', lambda: False)
17 def test_credentials_save_failed(self):
18 # If saving the credentials did not succeed and a callback was
19 # provided, it is called.
20@@ -631,6 +633,7 @@
21 credential_save_failed=callback)
22 self.assertEqual(len(callback_called), 1)
23
24+ @patch.object(NoNetworkLaunchpad, '_is_sudo', lambda: False)
25 def test_default_credentials_save_failed_is_to_raise_exception(self):
26 # If saving the credentials did not succeed and no callback was
27 # provided, the underlying exception is raised.
28@@ -643,6 +646,17 @@
29 'not important', service_root=service_root,
30 launchpadlib_dir=launchpadlib_dir)
31
32+ @patch.object(NoNetworkLaunchpad, '_is_sudo', lambda: True)
33+ def test_credentials_save_fail_under_sudo_does_not_raise_exception(self):
34+ # When running under sudo, Launchpad will not attempt to use
35+ # the keyring, so credential save failure will never happen
36+ launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
37+ service_root = "http://api.example.com/"
38+ with fake_keyring(BadSaveKeyring()):
39+ NoNetworkLaunchpad.login_with(
40+ 'not important', service_root=service_root,
41+ launchpadlib_dir=launchpadlib_dir)
42+
43
44 class TestMultipleSites(unittest.TestCase):
45 # If the same application name (consumer name) is used to access more than
46@@ -660,6 +674,7 @@
47 launchpadlib.launchpad.socket = socket
48 shutil.rmtree(self.temp_dir)
49
50+ @patch.object(NoNetworkLaunchpad, '_is_sudo', lambda: False)
51 def test_components_of_application_key(self):
52 launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
53 keyring = InMemoryKeyring()
54@@ -684,6 +699,7 @@
55 # "forgotten").
56 self.assertEqual(application_key, consumer_name + '@' + service_root)
57
58+ @patch.object(NoNetworkLaunchpad, '_is_sudo', lambda: False)
59 def test_same_app_different_servers(self):
60 launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
61 keyring = InMemoryKeyring()

Subscribers

People subscribed via source and target branches