~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/webservice/tests/test_marshallers.py

  • Committer: Julian Edwards
  • Date: 2011-07-28 20:46:18 UTC
  • mfrom: (13553 devel)
  • mto: This revision was merged to the branch mainline in revision 13555.
  • Revision ID: julian.edwards@canonical.com-20110728204618-tivj2wx2oa9s32bx
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__metaclass__ = type
7
7
 
8
8
import transaction
9
 
from zope.component import getUtility
10
9
 
11
10
from canonical.launchpad.testing.pages import (
12
11
    LaunchpadWebServiceCaller,
13
12
    webservice_for_person,
14
13
    )
15
 
from canonical.launchpad.webapp.interfaces import IPlacelessAuthUtility
16
14
from canonical.launchpad.webapp.servers import WebServiceTestRequest
17
15
from canonical.testing.layers import DatabaseFunctionalLayer
18
16
from lp.app.webservice.marshallers import TextFieldMarshaller
19
 
from lp.testing import logout, TestCaseWithFactory
 
17
from lp.testing import (
 
18
    logout,
 
19
    person_logged_in,
 
20
    TestCaseWithFactory,
 
21
    )
20
22
 
21
23
 
22
24
def ws_url(bug):
28
30
 
29
31
    layer = DatabaseFunctionalLayer
30
32
 
31
 
    def _makeRequest(self, is_anonymous):
32
 
        """Create either an anonymous or authenticated request."""
33
 
        request = WebServiceTestRequest()
34
 
        if is_anonymous:
35
 
            request.setPrincipal(
36
 
                getUtility(IPlacelessAuthUtility).unauthenticatedPrincipal())
37
 
        else:
38
 
            request.setPrincipal(self.factory.makePerson())
39
 
        return request
40
 
 
41
33
    def test_unmarshall_obfuscated(self):
42
 
        # Data is obfuccated if the request is anonynous.
43
 
        request = self._makeRequest(is_anonymous=True)
44
 
        marshaller = TextFieldMarshaller(None, request)
 
34
        # Data is obfuscated if the user is anonynous.
 
35
        marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
45
36
        result = marshaller.unmarshall(None, u"foo@example.com")
46
37
        self.assertEqual(u"<email address hidden>", result)
47
38
 
48
39
    def test_unmarshall_not_obfuscated(self):
49
 
        # Data is not obfuccated if the request is authenticated.
50
 
        request = self._makeRequest(is_anonymous=False)
51
 
        marshaller = TextFieldMarshaller(None, request)
52
 
        result = marshaller.unmarshall(None, u"foo@example.com")
 
40
        # Data is not obfuccated if the user is authenticated.
 
41
        marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
 
42
        with person_logged_in(self.factory.makePerson()):
 
43
            result = marshaller.unmarshall(None, u"foo@example.com")
53
44
        self.assertEqual(u"foo@example.com", result)
54
45
 
55
46