Known subclasses: twisted.web.test.test_webclient.URITestsForHostname, twisted.web.test.test_webclient.URITestsForIPv4, twisted.web.test.test_webclient.URITestsForIPv6

Abstract tests for twisted.web.client.URI.

Subclass this and unittest.TestCase. Then provide a value for host and uriHost.

Instance Variable host A host specification for use in tests, must be bytes.
Instance Variable uriHost The host specification in URI form, must be a bytes. In most cases this is identical with host. IPv6 address literals are an exception, according to RFC 3986 section 3.2.2, as they need to be enclosed in brackets. In this case this variable is different.
Method makeURIString Replace the string "HOST" in template with this test's host.
Method assertURIEquals Assert that all of a client.URI's components match the expected values.
Method test_parseDefaultPort client.URI.fromBytes by default assumes port 80 for the http scheme and 443 for the https scheme.
Method test_parseCustomDefaultPort client.URI.fromBytes accepts a defaultPort parameter that overrides the normal default port logic.
Method test_netlocHostPort Parsing a URI splits the network location component into host and port.
Method test_path Parse the path from a URI.
Method test_noPath The path of a URI that has no path is the empty string.
Method test_emptyPath The path of a URI with an empty path is b'/'.
Method test_param Parse URI parameters from a URI.
Method test_query Parse the query string from a URI.
Method test_fragment Parse the fragment identifier from a URI.
Method test_originForm client.URI.originForm produces an absolute URI path including the URI path.
Method test_originFormComplex client.URI.originForm produces an absolute URI path including the URI path, parameters and query string but excludes the fragment identifier.
Method test_originFormNoPath client.URI.originForm produces a path of b'/' when the URI specifies no path.
Method test_originFormEmptyPath client.URI.originForm produces a path of b'/' when the URI specifies an empty path.
Method test_externalUnicodeInterference client.URI.fromBytes parses the scheme, host, and path elements into bytes, even when passed an URL which has previously been passed to urlparse as a unicode string.
host =
A host specification for use in tests, must be bytes.
uriHost =
The host specification in URI form, must be a bytes. In most cases this is identical with host. IPv6 address literals are an exception, according to RFC 3986 section 3.2.2, as they need to be enclosed in brackets. In this case this variable is different.
def makeURIString(self, template):

Replace the string "HOST" in template with this test's host.

Byte strings Python between (and including) versions 3.0 and 3.4 cannot be formatted using % or format so this does a simple replace.

ParameterstemplateA string containing "HOST". (type: bytes)
ReturnsA string where "HOST" has been replaced by self.host. (type: bytes)
def assertURIEquals(self, uri, scheme, netloc, host, port, path, params='', query='', fragment=''):

Assert that all of a client.URI's components match the expected values.

Parametersuriclient.URI instance whose attributes will be checked for equality.
schemeURI scheme specifier. (type: bytes)
netlocNetwork location component. (type: bytes)
hostHost name. (type: bytes)
portPort number. (type: int)
pathHierarchical path. (type: bytes)
paramsParameters for last path segment, defaults to b''. (type: bytes)
queryQuery string, defaults to b''. (type: bytes)
fragmentFragment identifier, defaults to b''. (type: bytes)
def test_parseDefaultPort(self):

client.URI.fromBytes by default assumes port 80 for the http scheme and 443 for the https scheme.

def test_parseCustomDefaultPort(self):

client.URI.fromBytes accepts a defaultPort parameter that overrides the normal default port logic.

def test_netlocHostPort(self):

Parsing a URI splits the network location component into host and port.

def test_path(self):

Parse the path from a URI.

def test_noPath(self):

The path of a URI that has no path is the empty string.

def test_emptyPath(self):

The path of a URI with an empty path is b'/'.

def test_param(self):

Parse URI parameters from a URI.

def test_query(self):

Parse the query string from a URI.

def test_fragment(self):

Parse the fragment identifier from a URI.

def test_originForm(self):

client.URI.originForm produces an absolute URI path including the URI path.

def test_originFormComplex(self):

client.URI.originForm produces an absolute URI path including the URI path, parameters and query string but excludes the fragment identifier.

def test_originFormNoPath(self):

client.URI.originForm produces a path of b'/' when the URI specifies no path.

def test_originFormEmptyPath(self):

client.URI.originForm produces a path of b'/' when the URI specifies an empty path.

def test_externalUnicodeInterference(self):

client.URI.fromBytes parses the scheme, host, and path elements into bytes, even when passed an URL which has previously been passed to urlparse as a unicode string.

API Documentation for twisted, generated by pydoctor at 2020-03-25 17:34:30.