l.t.pages : module documentation

Part of lp.testing

Testing infrastructure for page tests.
Class UnstickyCookieHTTPCaller HTTPCaller subclass that do not carry cookies across requests.
Class LaunchpadWebServiceCaller A class for making calls to Launchpad web services.
Function extract_url_parameter Extract parameter and its value from a URL.
Class DuplicateIdError Raised by find_tag_by_id if more than one element has the given id.
Function find_tag_by_id Find and return the tag with the given ID
Function first_tag_by_class Find and return the first tag matching the given class(es)
Function find_tags_by_class Find and return one or more tags matching the given class(es)
Function find_portlet Find and return the portlet with the given title. Sequences of
Function find_main_content Return the main content of the page, excluding any portlets.
Function get_feedback_messages Find and return the feedback messages of the page.
Function print_feedback_messages Print out the feedback messages.
Function print_table Given a <table> print the content of each row.
Function get_radio_button_text_for_field Find the input called field.name, and return an iterable of strings.
Function print_radio_button_field Find the input called field.name, and print a friendly representation.
Function strip_label Strip surrounding whitespace and non-breaking spaces.
Function extract_link_from_tag Return a link from <a> tag, optionally considered relative to base.
Function extract_text Return the text stripped of all tags.
Function parse_relationship_section Parser package relationship section.
Function print_action_links Print action menu urls.
Function print_navigation_links Print navigation menu urls.
Function print_portlet_links Print portlet urls.
Function print_submit_buttons Print the submit button values found in the main content.
Function print_comments Print the comments on a BugTask index page.
Function print_batch_header Print the batch navigator header.
Function print_self_link_of_entries Print the self_link attribute of each entry in the given JSON body.
Function print_ppa_packages Undocumented
Function print_location Print the hierarchy, application tabs, and main heading of the page.
Function print_location_apps Print the application tabs' text and URL.
Function print_tag_with_id A simple helper to print the extracted text of the tag.
Function print_errors Print all the errors on the page.
Function setupBrowser Create a testbrowser object for use in pagetests.
Function setupBrowserForUser Setup a browser grabbing details from a user.
Function setupBrowserFreshLogin Create a test browser with a recently logged in user.
Function safe_canonical_url Generate a bytestring URL for an object
Function webservice_for_person Return a valid LaunchpadWebServiceCaller for the person.
Function setupDTCBrowser Testbrowser configured for Distribution Translations Coordinators.
Function setupRosettaExpertBrowser Testbrowser configured for Rosetta Experts.
Function permissive_security_policy Context manager to run code with a permissive security policy.
Function setUpGlobs Undocumented
Function PageTestSuite Create a suite of page tests for files found in storydir.
def extract_url_parameter(url, parameter):
Extract parameter and its value from a URL.

Use this if your test needs to inspect a parameter value embedded in a URL, but doesn't really care what the rest of the URL looks like or how the parameters are ordered.

def find_tag_by_id(content, id):
Find and return the tag with the given ID
def first_tag_by_class(content, class_):
Find and return the first tag matching the given class(es)
def find_tags_by_class(content, class_, only_first=False):
Find and return one or more tags matching the given class(es)
def find_portlet(content, name):
Find and return the portlet with the given title. Sequences of whitespace are considered equivalent to one space, and beginning and ending whitespace is also ignored, as are non-text elements such as images.
def find_main_content(content):
Return the main content of the page, excluding any portlets.
def get_feedback_messages(content):
Find and return the feedback messages of the page.
def print_feedback_messages(content, formatter='minimal'):
Print out the feedback messages.
def print_table(content, columns=None, skip_rows=None, sep='\t'):
Given a <table> print the content of each row.

The table is printed using `sep` as the separator.
:param columns   a list of the column numbers (zero-based) to be included
                 in the output.  If None all columns are printed.
:param skip_rows a list of row numbers (zero-based) to be skipped.  If
                 None no rows are skipped.
:param sep       the separator to be used between output items.
def get_radio_button_text_for_field(soup, name):
Find the input called field.name, and return an iterable of strings.

The resulting output will look something like: ['(*) A checked option', '( ) An unchecked option']

def print_radio_button_field(content, name):
Find the input called field.name, and print a friendly representation.

The resulting output will look something like: (*) A checked option ( ) An unchecked option

def strip_label(label):
Strip surrounding whitespace and non-breaking spaces.
def extract_link_from_tag(tag, base=None):
Return a link from <a> tag, optionally considered relative to base.

A tag should contain a 'href' attribute, and base will commonly be extracted from browser.url.

def extract_text(content, extract_image_text=False, skip_tags=None, formatter='minimal'):
Return the text stripped of all tags.

All runs of tabs and spaces are replaced by a single space and runs of newlines are replaced by a single newline. Leading and trailing white spaces are stripped.

def parse_relationship_section(content):
Parser package relationship section.

See package-relationship-pages.txt and related.

def print_action_links(content):
Print action menu urls.
def print_navigation_links(content):
Print navigation menu urls.
def print_portlet_links(content, name, base=None):
Print portlet urls.

This function expects the browser.content as well as the h2 name of the
portlet. base is optional. It will locate the portlet and print out the
links. It will report if the portlet cannot be found and will also report
if there are no links to be found. Unlike the other functions on this
page, this looks for "a" instead of "li". Example usage:
--------------
>>> print_portlet_links(admin_browser.contents,'Milestone milestone3 for
    Ubuntu details')
Ubuntu: /ubuntu
Warty: /ubuntu/warty
--------------
def print_submit_buttons(content):
Print the submit button values found in the main content.

Use this to check that the buttons on a page match your expectations.

def print_comments(page):
Print the comments on a BugTask index page.
def print_batch_header(soup):
Print the batch navigator header.
def print_self_link_of_entries(json_body):
Print the self_link attribute of each entry in the given JSON body.
def print_ppa_packages(contents):
Undocumented
def print_location(contents):
Print the hierarchy, application tabs, and main heading of the page.

The hierarchy shows your position in the Launchpad structure: for example, Ubuntu > 8.04. The application tabs represent the major facets of an object: for example, Overview, Bugs, and Translations. The main heading is the first <h1> element in the page.

def print_location_apps(contents):
Print the application tabs' text and URL.
def print_tag_with_id(contents, id):
A simple helper to print the extracted text of the tag.
def print_errors(contents):
Print all the errors on the page.
def setupBrowser(auth=None):
Create a testbrowser object for use in pagetests.
ParametersauthHTTP authentication string. None for the anonymous user, or a string of the form 'Basic email:password' for an authenticated user.
ReturnsA Browser object.
def setupBrowserForUser(user):
Setup a browser grabbing details from a user.
ParametersuserThe user to use.
def setupBrowserFreshLogin(user):
Create a test browser with a recently logged in user.

The request is not shared by the browser, so we create a session of the test request and set a cookie to reference the session in the test browser.

def safe_canonical_url(*args, **kwargs):
Generate a bytestring URL for an object
def webservice_for_person(person, consumer_key=u'launchpad-library', permission=OAuthPermission.READ_PUBLIC, context=None):
Return a valid LaunchpadWebServiceCaller for the person.

Use this method to create a way to test the webservice that doesn't depend on sample data.

def setupDTCBrowser():
Testbrowser configured for Distribution Translations Coordinators.

Ubuntu is the configured distribution.

def setupRosettaExpertBrowser():
Testbrowser configured for Rosetta Experts.
@contextmanager
def permissive_security_policy(dbuser_name=None):
Context manager to run code with a permissive security policy.

This is just enough to run code such as BaseMailer that normally expects to be called only from environments that use a permissive security policy, such as jobs or scripts.

def setUpGlobs(test, future=False):
Undocumented
def PageTestSuite(storydir, package=None, setUp=setUpGlobs, **kw):
Create a suite of page tests for files found in storydir.

Each file is added as a separate DocFileTest.

Parametersstorydirthe directory containing the page tests.
packagethe package to resolve storydir relative to. Defaults to the caller's package.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.