l.a.t.test_tales : module documentation

Part of lp.app.tests

tales.py doctests.
Function test_requestapi
>>> from lp.app.browser.tales import IRequestAPI, RequestAPI
Function test_cookie_scope The 'request/lp:cookie_scope' TALES expression returns a string
Function test_dbschemaapi
>>> from lp.app.browser.tales import DBSchemaAPI
Class TestPersonFormatterAPI Tests for PersonFormatterAPI
Class TestTeamFormatterAPI Test permissions required to access TeamFormatterAPI methods.
Class TestObjectFormatterAPI Tests for ObjectFormatterAPI
Class TestFormattersAPI Tests for FormattersAPI.
Class TestNoneFormatterAPI Tests for NoneFormatterAPI
Class TestIRCNicknameFormatterAPI Tests for IRCNicknameFormatterAPI
Class ObjectImageDisplayAPITestCase Tests for ObjectImageDisplayAPI
Class TestDateTimeFormatterAPI No class docstring; 7/7 methods documented
Class TestPackageBuildFormatterAPI Tests for PackageBuildFormatterAPI.
def test_requestapi():
>>> from lp.app.browser.tales import IRequestAPI, RequestAPI
>>> from lp.registry.interfaces.person import IPerson
>>> from zope.interface.verify import verifyObject
>>> class FakePrincipal:
...     def __conform__(self, protocol):
...         if protocol is IPerson:
...             return "This is a person"
...
>>> class FakeApplicationRequest:
...    principal = FakePrincipal()
...    def getURL(self):
...        return 'http://launchpad.test/'
...

Let's make a fake request, where request.principal is a FakePrincipal object. We can use a class or an instance here. It really doesn't matter.

>>> request = FakeApplicationRequest()
>>> adapter = RequestAPI(request)
>>> verifyObject(IRequestAPI, adapter)
True
>>> adapter.person
'This is a person'
def test_cookie_scope():

The 'request/lp:cookie_scope' TALES expression returns a string that represents the scope parameters necessary for a cookie to be available for the entire Launchpad site. It takes into account the request URL and the cookie_domains setting in launchpad.conf.

>>> from lp.app.browser.tales import RequestAPI
>>> def cookie_scope(url):
...     class FakeRequest:
...         def getURL(self):
...             return url
...     return RequestAPI(FakeRequest()).cookie_scope

The cookie scope will use the secure attribute if the request was secure:

>>> print cookie_scope('http://launchpad.net/')
; Path=/; Domain=.launchpad.net
>>> print cookie_scope('https://launchpad.net/')
; Path=/; Secure; Domain=.launchpad.net

The domain parameter is omitted for domains that appear to be separate from a Launchpad instance:

>>> print cookie_scope('https://example.com/')
; Path=/; Secure
def test_dbschemaapi():
>>> from lp.app.browser.tales import DBSchemaAPI
>>> from lp.code.enums import BranchType

The syntax to get the title is: number/lp:DBSchemaClass

>>> (str(DBSchemaAPI(1).traverse('BranchType', []))
...  == BranchType.HOSTED.title)
True

Using an inappropriate number should give a KeyError.

>>> DBSchemaAPI(99).traverse('BranchType', [])
Traceback (most recent call last):
...
KeyError: 99

Using a dbschema name that doesn't exist should give a LocationError

>>> DBSchemaAPI(99).traverse('NotADBSchema', [])
Traceback (most recent call last):
...
LocationError: 'NotADBSchema'
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.