Merge lp:~jcsackett/launchpad/get-rid-of-launchpadlib_for_anonymous-683748 into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 12134
Proposed branch: lp:~jcsackett/launchpad/get-rid-of-launchpadlib_for_anonymous-683748
Merge into: lp:launchpad
Diff against target: 109 lines (+10/-25)
4 files modified
lib/lp/blueprints/tests/test_webservice.py (+1/-2)
lib/lp/registry/browser/tests/test_person_webservice.py (+2/-3)
lib/lp/testing/__init__.py (+0/-1)
lib/lp/testing/_webservice.py (+7/-19)
To merge this branch: bzr merge lp:~jcsackett/launchpad/get-rid-of-launchpadlib_for_anonymous-683748
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+44115@code.launchpad.net

Commit message

[r=sinzui][ui=none][bug=683748] Replaces launchpadlib_for_anonymous with an extension of launchpadlib_for

Description of the change

Summary
=======

A few weeks ago a method was created to allow use of anonymous launchpadlib connections in tests. This method, launchpadlib_for_anonymous, was largely redundant, and its function is better expressed as a modification to launchpadlib_for.

Implementation
==============

* lib/lp/testing/_webservice.py: launchpadlib_for is modified to accept None as a parameter for person. If none is passed in for person, the method sets up a connection with anonymous credentials in the same way that launchpadlib_for_anonymous previously did.

Tests
=====

bin/test -t IHasSpecificationTests
bin/test -t PersonEmailSecurity

Lint
====

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/blueprints/tests/test_webservice.py
  lib/lp/registry/browser/tests/test_person_webservice.py
  lib/lp/testing/__init__.py
  lib/lp/testing/_webservice.py

./lib/lp/testing/__init__.py
     135: 'anonymous_logged_in' imported but unused
     135: 'with_anonymous_login' imported but unused
     154: 'launchpadlib_for' imported but unused
     154: 'launchpadlib_credentials_for' imported but unused
     135: 'person_logged_in' imported but unused
     154: 'oauth_access_token_for' imported but unused
     135: 'login_celebrity' imported but unused
     135: 'with_celebrity_logged_in' imported but unused
     153: 'test_tales' imported but unused
     135: 'celebrity_logged_in' imported but unused
     135: 'run_with_login' imported but unused
     135: 'is_logged_in' imported but unused
     135: 'with_person_logged_in' imported but unused
     135: 'login_team' imported but unused
     135: 'login_person' imported but unused
     135: 'login_as' imported but unused
     502: E231 missing whitespace after ':'
     707: E203 whitespace before ','
     707: E231 missing whitespace after ','
     920: E302 expected 2 blank lines, found 1
     996: E302 expected 2 blank lines, found 1
./lib/lp/testing/_webservice.py
     155: Line exceeds 78 characters.

I will clean up the lint errors; I didn't want to pollute the diff with lint removals unrelated to the change. The various imports will remain as they exist to enable "from lp.testing import login_as" &c.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

This looks good to land

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/blueprints/tests/test_webservice.py'
2--- lib/lp/blueprints/tests/test_webservice.py 2010-12-02 15:13:58 +0000
3+++ lib/lp/blueprints/tests/test_webservice.py 2010-12-21 15:16:42 +0000
4@@ -14,7 +14,6 @@
5 )
6 from lp.testing import (
7 launchpadlib_for,
8- launchpadlib_for_anonymous,
9 person_logged_in,
10 TestCaseWithFactory,
11 ws_object,
12@@ -237,7 +236,7 @@
13 # Need to endInteraction() because launchpadlib_for_anonymous() will
14 # setup a new one.
15 endInteraction()
16- lplib = launchpadlib_for_anonymous('lplib-test', version='devel')
17+ lplib = launchpadlib_for('lplib-test', person=None, version='devel')
18 ws_product = ws_object(lplib, product)
19 self.assertNamesOfSpecificationsAre(
20 ["spec1", "spec2"], ws_product.all_specifications)
21
22=== modified file 'lib/lp/registry/browser/tests/test_person_webservice.py'
23--- lib/lp/registry/browser/tests/test_person_webservice.py 2010-12-02 17:53:57 +0000
24+++ lib/lp/registry/browser/tests/test_person_webservice.py 2010-12-21 15:16:42 +0000
25@@ -13,7 +13,6 @@
26 from canonical.testing.layers import DatabaseFunctionalLayer
27 from lp.testing import (
28 launchpadlib_for,
29- launchpadlib_for_anonymous,
30 TestCaseWithFactory,
31 )
32
33@@ -44,10 +43,10 @@
34 def test_anonymous_cannot_access(self):
35 # An anonymous launchpadlib connection cannot see email addresses.
36
37- # Need to endInteraction() because launchpadlib_for_anonymous() will
38+ # Need to endInteraction() because launchpadlib_for() will
39 # setup a new one.
40 endInteraction()
41- lp = launchpadlib_for_anonymous('test', version='devel')
42+ lp = launchpadlib_for('test', person=None, version='devel')
43 person = lp.people['target']
44 emails = list(person.confirmed_email_addresses)
45 self.assertEqual([], emails)
46
47=== modified file 'lib/lp/testing/__init__.py'
48--- lib/lp/testing/__init__.py 2010-12-14 20:53:23 +0000
49+++ lib/lp/testing/__init__.py 2010-12-21 15:16:42 +0000
50@@ -154,7 +154,6 @@
51 from lp.testing._webservice import (
52 launchpadlib_credentials_for,
53 launchpadlib_for,
54- launchpadlib_for_anonymous,
55 oauth_access_token_for,
56 )
57 from lp.testing.fixture import ZopeEventHandlerFixture
58
59=== modified file 'lib/lp/testing/_webservice.py'
60--- lib/lp/testing/_webservice.py 2010-12-01 12:00:00 +0000
61+++ lib/lp/testing/_webservice.py 2010-12-21 15:16:42 +0000
62@@ -8,7 +8,6 @@
63 __all__ = [
64 'launchpadlib_credentials_for',
65 'launchpadlib_for',
66- 'launchpadlib_for_anonymous',
67 'oauth_access_token_for',
68 ]
69
70@@ -120,23 +119,8 @@
71 shutil.rmtree(cache, ignore_errors=True)
72
73
74-def launchpadlib_for_anonymous(
75- consumer_name, version=None, service_root="http://api.launchpad.dev/"):
76- """Create a Launchpad object for the anonymous user.
77-
78- :param consumer_name: An OAuth consumer name.
79- :param version: The version of the web service to access.
80- :param service_root: The root URL of the web service to access.
81-
82- :return: A launchpadlib.Launchpad object.
83- """
84- token = AnonymousAccessToken()
85- credentials = Credentials(consumer_name, access_token=token)
86- return Launchpad(credentials, service_root, version=version)
87-
88-
89 def launchpadlib_for(
90- consumer_name, person, permission=OAuthPermission.WRITE_PRIVATE,
91+ consumer_name, person=None, permission=OAuthPermission.WRITE_PRIVATE,
92 context=None, version=None, service_root="http://api.launchpad.dev/"):
93 """Create a Launchpad object for the given person.
94
95@@ -151,8 +135,12 @@
96
97 :return: A launchpadlib Launchpad object.
98 """
99- credentials = launchpadlib_credentials_for(
100- consumer_name, person, permission, context)
101+ if person is None:
102+ token = AnonymousAccessToken()
103+ credentials = Credentials(consumer_name, access_token=token)
104+ else:
105+ credentials = launchpadlib_credentials_for(
106+ consumer_name, person, permission, context)
107 transaction.commit()
108 version = version or Launchpad.DEFAULT_VERSION
109 cache = tempfile.mkdtemp(prefix='launchpadlib-cache-')