= XMLRPC self-test API = The Launchpad root object has a simple XMLRPC API to show that XMLRPC works. >>> from lp.xmlrpc.application import SelfTest, ISelfTest >>> from canonical.launchpad.webapp.testing import verifyObject >>> selftestview = SelfTest('somecontext', 'somerequest') >>> verifyObject(ISelfTest, selftestview) True >>> selftestview.concatenate('foo', 'bar') u'foo bar' >>> selftestview.make_fault() We can test our XMLRPC APIs using xmlrpclib, using a custom Transport which talks with the publisher directly. >>> import xmlrpclib >>> from lp.testing.xmlrpc import XMLRPCTestTransport >>> selftest = xmlrpclib.ServerProxy( ... 'http://xmlrpc.launchpad.dev/', transport=XMLRPCTestTransport()) >>> selftest.concatenate('foo', 'bar') 'foo bar' >>> selftest.make_fault() Traceback (most recent call last): ... Fault: == Unexpected Exceptions == Sometimes an XML-RPC method will be buggy, and raise an exception other than xmlrpclib.Fault. We have such a method on the self test view: >>> selftestview.raise_exception() Traceback (most recent call last): ... RuntimeError: selftest exception As with normal browser requests, we don't want to expose these error messages to the user since they could contain confidential information. Such exceptions get converted to a fault listing the OOPS ID (assuming one was generated): >>> selftest.raise_exception() Traceback (most recent call last): ... Fault: == Authentication == >>> selftest.hello() 'Hello Anonymous.' The last call returned 'Anonymous', since we didn't provided a username and a password. If we do that, hello() will print the name of the logged in user: >>> selftest = xmlrpclib.ServerProxy( ... 'http://test@canonical.com:test@xmlrpc.launchpad.dev/', ... transport=XMLRPCTestTransport()) >>> selftest.hello() 'Hello Sample Person.' The interactions in this test, and the interaction in the XMLRPC methods are different, so we still have an anonymous interaction in this test. >>> getUtility(ILaunchBag).user is None True Even if we log in as Foo Bar here, the XMLRPC method will see Sample Person as the logged in user. >>> login('foo.bar@canonical.com') >>> selftest.hello() 'Hello Sample Person.' >>> print getUtility(ILaunchBag).user.displayname Foo Bar