Code review comment for lp:~jcsackett/launchpad/anonymous-api-access-emails-681815

Revision history for this message
j.c.sackett (jcsackett) wrote :

The big change is the new tests. I've attached a diff of just those.

1=== modified file 'lib/lp/registry/browser/tests/test_person_webservice.py'
2--- lib/lp/registry/browser/tests/test_person_webservice.py 2010-10-04 19:50:45 +0000
3+++ lib/lp/registry/browser/tests/test_person_webservice.py 2010-12-02 17:53:46 +0000
4@@ -5,12 +5,52 @@
5
6 import unittest
7
8+from zope.security.management import endInteraction
9 from zope.security.proxy import removeSecurityProxy
10
11 from canonical.launchpad.ftests import login
12 from canonical.launchpad.testing.pages import LaunchpadWebServiceCaller
13 from canonical.testing.layers import DatabaseFunctionalLayer
14-from lp.testing import TestCaseWithFactory
15+from lp.testing import (
16+ launchpadlib_for,
17+ launchpadlib_for_anonymous,
18+ TestCaseWithFactory,
19+ )
20+
21+
22+class TestPersonEmailSecurity(TestCaseWithFactory):
23+
24+ layer = DatabaseFunctionalLayer
25+
26+ def setUp(self):
27+ super(TestPersonEmailSecurity, self).setUp()
28+ self.target = self.factory.makePerson(name='target')
29+ self.email_one = self.factory.makeEmail(
30+ 'test1@example.com', self.target)
31+ self.email_two = self.factory.makeEmail(
32+ 'test2@example.com', self.target)
33+
34+ def test_logged_in_can_access(self):
35+ # A logged in launchpadlib connection can see confirmed email
36+ # addresses.
37+ accessor = self.factory.makePerson()
38+ lp = launchpadlib_for("test", accessor.name)
39+ person = lp.people['target']
40+ emails = sorted(list(person.confirmed_email_addresses))
41+ self.assertNotEqual(
42+ sorted([self.email_one, self.email_two]),
43+ len(emails))
44+
45+ def test_anonymous_cannot_access(self):
46+ # An anonymous launchpadlib connection cannot see email addresses.
47+
48+ # Need to endInteraction() because launchpadlib_for_anonymous() will
49+ # setup a new one.
50+ endInteraction()
51+ lp = launchpadlib_for_anonymous('test', version='devel')
52+ person = lp.people['target']
53+ emails = list(person.confirmed_email_addresses)
54+ self.assertEqual([], emails)
55
56
57 class TestPersonRepresentation(TestCaseWithFactory):

« Back to merge proposal