twisted.web.test.test_http.RequestTests(unittest.TestCase, ResponseTestMixin)
class documentationtwisted.web.test.test_http
(View In Hierarchy)
Tests for http.Request
Method | test_getHeader | http.Request.getHeader
returns the value of the named request header. |
Method | test_getHeaderReceivedMultiples | When there are multiple values for a single request header, http.Request.getHeader
returns the last value. |
Method | test_getHeaderNotFound | http.Request.getHeader
returns None
when asked for the value of a request header which is not present. |
Method | test_getAllHeaders | http.Request.getAllheaders returns a dict
mapping all request header names to their corresponding values. |
Method | test_getAllHeadersNoHeaders | http.Request.getAllHeaders
returns an empty dict if there are no request headers. |
Method | test_getAllHeadersMultipleHeaders | When there are multiple values for a single request header, http.Request.getAllHeaders
returns only the last value. |
Method | test_setResponseCode | http.Request.setResponseCode
takes a status code and causes it to be used as the response status. |
Method | test_setResponseCodeAndMessage | http.Request.setResponseCode
takes a status code and a message and causes them to be used as the
response status. |
Method | test_setResponseCodeAndMessageNotBytes | http.Request.setResponseCode
accepts bytes for the message parameter and raises TypeError
if passed anything else. |
Method | test_setResponseCodeAcceptsIntegers | http.Request.setResponseCode
accepts int for the code parameter and raises TypeError
if passed anything else. |
Method | test_setResponseCodeAcceptsLongIntegers | http.Request.setResponseCode
accepts long for the code parameter. |
Method | test_setLastModifiedNeverSet | When no previous value was set and no 'if-modified-since' value was
requested, http.Request.setLastModified
takes a timestamp in seconds since the epoch and sets the request's
lastModified attribute. |
Method | test_setLastModifiedUpdate | If the supplied timestamp is later than the lastModified attribute's
value, http.Request.setLastModified
updates the lastModifed attribute. |
Method | test_setLastModifiedIgnore | If the supplied timestamp occurs earlier than the current lastModified
attribute, http.Request.setLastModified
ignores it. |
Method | test_setLastModifiedCached | If the resource is older than the if-modified-since date in the request
header, http.Request.setLastModified
returns http.CACHED . |
Method | test_setLastModifiedNotCached | If the resource is newer than the if-modified-since date in the request
header, http.Request.setLastModified
returns None |
Method | test_setLastModifiedTwiceNotCached | When http.Request.setLastModified
is called multiple times, the highest supplied value is honored. If that
value is higher than the if-modified-since date in the request header, the
method returns None. |
Method | test_setLastModifiedTwiceCached | No summary |
Method | test_setHost | http.Request.setHost
sets the value of the host request header. The port should not be added
because it is the default. |
Method | test_setHostSSL | http.Request.setHost
sets the value of the host request header. The port should not be added
because it is the default. |
Method | test_setHostNonDefaultPort | http.Request.setHost
sets the value of the host request header. The port should be added because
it is not the default. |
Method | test_setHostSSLNonDefaultPort | http.Request.setHost
sets the value of the host request header. The port should be added because
it is not the default. |
Method | test_setHeader | http.Request.setHeader
sets the value of the given response header. |
Method | test_addCookieWithMinimumArgumentsUnicode | http.Request.addCookie
adds a new cookie to be sent with the response, and can be called with just
a key and a value. unicode
arguments are encoded using UTF-8. |
Method | test_addCookieWithAllArgumentsUnicode | http.Request.addCookie
adds a new cookie to be sent with the response. unicode
arguments are encoded using UTF-8. |
Method | test_addCookieWithMinimumArgumentsBytes | http.Request.addCookie
adds a new cookie to be sent with the response, and can be called with just
a key and a value. bytes
arguments are not decoded. |
Method | test_addCookieWithAllArgumentsBytes | http.Request.addCookie
adds a new cookie to be sent with the response. bytes
arguments are not decoded. |
Method | test_addCookieSanitization | http.Request.addCookie
replaces linear whitespace and semicolons with single spaces. |
Method | test_addCookieSameSite | http.Request.setCookie supports a sameSite
argument. |
Method | test_firstWrite | For an HTTP 1.0 request, http.Request.write
sends an HTTP 1.0 Response-Line and whatever response headers are set. |
Method | test_firstWriteHTTP11Chunked | For an HTTP 1.1 request, http.Request.write
sends an HTTP 1.1 Response-Line, whatever response headers are set, and
uses chunked encoding for the response body. |
Method | test_firstWriteLastModified | For an HTTP 1.0 request for a resource with a known last modified time,
http.Request.write
sends an HTTP Response-Line, whatever response headers are set, and a
last-modified header with that time. |
Method | test_lastModifiedAlreadyWritten | If the last-modified header already exists in the http.Request response
headers, the lastModified attribute is ignored and a message is logged. |
Method | test_receivedCookiesDefault | http.Request.received_cookies defaults to an empty dict . |
Method | test_parseCookies | http.Request.parseCookies
extracts cookies from requestHeaders and adds them to
received_cookies . |
Method | test_parseCookiesMultipleHeaders | http.Request.parseCookies
can extract cookies from multiple Cookie headers. |
Method | test_parseCookiesNoCookie | http.Request.parseCookies
can be called on a request without a cookie header. |
Method | test_parseCookiesEmptyCookie | http.Request.parseCookies
can be called on a request with an empty cookie header. |
Method | test_parseCookiesIgnoreValueless | http.Request.parseCookies
ignores cookies which don't have a value. |
Method | test_parseCookiesEmptyValue | http.Request.parseCookies
parses cookies with an empty value. |
Method | test_parseCookiesRetainRightSpace | http.Request.parseCookies
leaves trailing whitespace in the cookie value. |
Method | test_parseCookiesStripLeftSpace | http.Request.parseCookies
strips leading whitespace in the cookie key. |
Method | test_parseCookiesContinueAfterMalformedCookie | http.Request.parseCookies
parses valid cookies set before or after malformed cookies. |
Method | test_connectionLost | http.Request.connectionLost
closes Request.content
and drops the reference to the HTTPChannel to
assist with garbage collection. |
Method | test_registerProducerTwiceFails | Calling Request.registerProducer when a producer is already
registered raises ValueError. |
Method | test_registerProducerWhenNotQueuedRegistersPushProducer | Calling Request.registerProducer with an IPushProducer when
the request is not queued registers the producer as a push producer on the
request's transport. |
Method | test_registerProducerWhenNotQueuedRegistersPullProducer | Calling Request.registerProducer with an IPullProducer when
the request is not queued registers the producer as a pull producer on the
request's transport. |
Method | test_connectionLostNotification | Request.connectionLost
triggers all finish notification Deferreds and cleans up per-request
state. |
Method | test_finishNotification | Request.finish triggers all finish notification
Deferreds. |
Method | test_writeAfterFinish | Calling Request.write after Request.finish has
been called results in a RuntimeError
being raised. |
Method | test_finishAfterConnectionLost | Calling Request.finish after Request.connectionLost
has been called results in a RuntimeError
being raised. |
Method | test_writeAfterConnectionLost | Calling Request.write after Request.connectionLost
has been called does not raise an exception. RuntimeError
will be raised when finish is called on the request. |
Method | test_reprUninitialized | Request.__repr__
returns the class name, object address, and dummy-place holder values when
used on a Request which has not yet been initialized. |
Method | test_reprInitialized |
|
Method | test_reprSubclass | Subclasses of Request inherit a __repr__
implementation which includes the subclass's name in place of the string
"Request" . |
Method | test_unregisterNonQueuedNonStreamingProducer | Request.unregisterProducer unregisters a non-queued
non-streaming producer from the request and the request's transport. |
Method | test_unregisterNonQueuedStreamingProducer | Request.unregisterProducer unregisters a non-queued
streaming producer from the request and the request's transport. |
Method | test_finishProducesLog | http.Request.finish
will call the channel's factory to produce a log message. |
Method | test_requestBodyTimeoutFromFactory | HTTPChannel
timeouts whenever data from a request body is not delivered to it in time,
even when it gets built from a HTTPFactory . |
Method | test_finishCleansConnection | http.Request.finish
will notify the channel that it is finished, and will put the transport
back in the producing state so that the reactor can close the
connection. |
Method | test_provides_IDeprecatedHTTPChannelToRequestInterface | http.Request
provides http._IDeprecatedHTTPChannelToRequestInterface ,
which defines the interface used by http.HTTPChannel . |
Method | test_eq | A http.Request
is equal to itself. |
Method | test_ne | A http.Request
is not equal to another object. |
Method | test_hashable | A http.Request
is hashable. |
Method | test_eqWithNonRequest | A http.Request
on the left hand side of an equality comparison to an instance that is not
a http.Request
hands the comparison off to that object's __eq__
implementation. |
Method | test_neWithNonRequest | A http.Request
on the left hand side of an inequality comparison to an instance that is
not a http.Request
hands the comparison off to that object's __ne__
implementation. |
Method | test_finishProducerStillRegistered | A RuntimeError is logged if a producer is still registered when an http.Request is
finished. |
Method | test_getClientIPWithIPv4 | http.Request.getClientIP
returns the host part of the client's address when connected over IPv4. |
Method | test_getClientIPWithIPv6 | http.Request.getClientIP
returns the host part of the client's address when connected over IPv6. |
Method | test_getClientIPWithNonTCPPeer | http.Request.getClientIP
returns None
for the client's IP address when connected over a non-TCP transport. |
Method | test_getClientAddress | http.Request.getClientAddress
returns the client's address as an IAddress
provider. |
Method | _compatHeadersTest | Verify that each of two different attributes which are associated with the same state properly reflect changes made through the other. |
Method | _checkCookie | Call http.Request.addCookie
with *args and **kwargs , and check that the
cookie value is equal to expectedCookieValue . |
Inherited from TestCase:
Instance Variable | timeout | A real number of seconds. If set, the test will raise an error if it takes
longer than timeout seconds. If not set,
util.DEFAULT_TIMEOUT_DURATION is used. |
Method | __init__ | Construct an asynchronous test case for methodName . |
Method | assertFailure | Fail if deferred does not errback with one of
expectedFailures . Returns the original Deferred with callbacks
added. You will need to return this Deferred from your test case. |
Method | __call__ | Run the test. Should always do exactly the same thing as run(). |
Method | deferSetUp | Undocumented |
Method | deferTestMethod | Undocumented |
Method | deferTearDown | Undocumented |
Method | deferRunCleanups | Run any scheduled cleanups and report errors (if any to the result object. |
Method | addCleanup | Extend the base cleanup feature with support for cleanup functions which return Deferreds. |
Method | getSuppress | Undocumented |
Method | getTimeout | No summary |
Method | _run | Run a single method, either a test method or fixture. |
Method | _ebDeferSetUp | Undocumented |
Method | _cbDeferTestMethod | Undocumented |
Method | _ebDeferTestMethod | Undocumented |
Method | _ebDeferTearDown | Undocumented |
Method | _cbDeferRunCleanups | Undocumented |
Method | _cleanUp | Undocumented |
Method | _classCleanUp | Undocumented |
Method | _makeReactorMethod | Create a method which wraps the reactor method name . The
new method issues a deprecation warning and calls the original. |
Method | _deprecateReactor | Deprecate iterate , crash and stop
on reactor . That is, each method is wrapped in a function that
issues a deprecation warning, then calls the original. |
Method | _undeprecateReactor | Restore the deprecated reactor methods. Undoes what _deprecateReactor
did. |
Method | _runCleanups | Run the cleanups added with addCleanup
in order. |
Method | _runFixturesAndTest | Really run setUp , the test method, and
tearDown . Any of these may return defer.Deferred s.
After they complete, do some reactor cleanup. |
Method | _wait | Take a Deferred that only ever callbacks. Block until it happens. |
Inherited from SynchronousTestCase (via TestCase):
Instance Variable | failureException | An exception class, defaulting to FailTest . If the test method
raises this exception, it will be reported as a failure, rather than an
exception. All of the assertion methods raise this if the assertion fails. |
Instance Variable | skip | None
or a string explaining why this test is to be skipped. If defined, the test
will not be run. Instead, it will be reported to the result object as
'skipped' (if the TestResult supports skipping). |
Instance Variable | todo | None ,
a string or a tuple of (errors, reason) where
errors is either an exception class or an iterable of
exception classes, and reason is a string. See Todo or makeTodo for
more information. |
Instance Variable | suppress | None
or a list of tuples of (args, kwargs) to be passed to
warnings.filterwarnings . Use these to suppress warnings raised
in a test. Useful for testing deprecated code. See also util.suppress . |
Method | __eq__ | No summary |
Method | __ne__ | Undocumented |
Method | __hash__ | Undocumented |
Method | shortDescription | Undocumented |
Method | getSkip | No summary |
Method | getTodo | No summary |
Method | runTest | If no methodName argument is passed to the constructor, run
will treat this method as the thing with the actual test inside. |
Method | run | Run the test case, storing the results in result . |
Method | patch | Monkey patch an object for the duration of the test. |
Method | flushLoggedErrors | Remove stored errors received from the log. |
Method | flushWarnings | Remove stored warnings from the list of captured warnings and return them. |
Method | callDeprecated | Call a function that should have been deprecated at a specific version and in favor of a specific alternative, and assert that it was thusly deprecated. |
Method | mktemp | Create a new path name which can be used for a new file or directory. |
Method | _getSuppress | No summary |
Method | _getSkipReason | Return the reason to use for skipping a test method. |
Method | _installObserver | Undocumented |
Method | _removeObserver | Undocumented |
Inherited from _Assertions (via TestCase, SynchronousTestCase):
Method | fail | Absolutely fail the test. Do not pass go, do not collect $200. |
Method | assertFalse | Fail the test if condition evaluates to True. |
Method | assertTrue | Fail the test if condition evaluates to False. |
Method | assertRaises | Fail the test unless calling the function f with the given
args and kwargs raises exception .
The failure will report the traceback and call stack of the unexpected
exception. |
Method | assertEqual | Fail the test if first and second are not
equal. |
Method | assertIs | Fail the test if first is not second . This is
an obect-identity-equality test, not an object equality (i.e.
__eq__ ) test. |
Method | assertIsNot | Fail the test if first is second . This is an
obect-identity-equality test, not an object equality (i.e.
__eq__ ) test. |
Method | assertNotEqual | Fail the test if first == second . |
Method | assertIn | Fail the test if containee is not found in
container . |
Method | assertNotIn | Fail the test if containee is found in
container . |
Method | assertNotAlmostEqual | Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero. |
Method | assertAlmostEqual | Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero. |
Method | assertApproximates | Fail if first - second >
tolerance |
Method | assertSubstring | Fail if substring does not exist within
astring . |
Method | assertNotSubstring | Fail if astring contains substring . |
Method | assertWarns | Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine. |
Method | assertIsInstance | Fail if instance is not an instance of the given class or
of one of the given classes. |
Method | assertNotIsInstance | Fail if instance is an instance of the given class or of
one of the given classes. |
Method | successResultOf | Return the current success result of deferred or raise
self.failureException . |
Method | failureResultOf | Return the current failure result of deferred or raise
self.failureException . |
Method | assertNoResult | Assert that deferred does not have a result at this
point. |
Method | assertRegex | Fail the test if a regexp search of text
fails. |
Inherited from ResponseTestMixin:
Method | assertResponseEquals | Assert that the responses matches the expected
responses. |
Verify that each of two different attributes which are associated with the same state properly reflect changes made through the other.
This is used to test that the
headers
/responseHeaders
and
received_headers
/requestHeaders
pairs interact
properly.
When there are multiple values for a single request header, http.Request.getHeader
returns the last value.
http.Request.getHeader
returns None
when asked for the value of a request header which is not present.
http.Request.getAllheaders
returns a dict
mapping all request header names to their corresponding values.
http.Request.getAllHeaders
returns an empty dict
if there are no request headers.
When there are multiple values for a single request header, http.Request.getAllHeaders
returns only the last value.
http.Request.setResponseCode
takes a status code and causes it to be used as the response status.
http.Request.setResponseCode
takes a status code and a message and causes them to be used as the
response status.
http.Request.setResponseCode
accepts bytes
for the message parameter and raises TypeError
if passed anything else.
http.Request.setResponseCode
accepts int
for the code parameter and raises TypeError
if passed anything else.
http.Request.setResponseCode
accepts long
for the code parameter.
When no previous value was set and no 'if-modified-since' value was
requested, http.Request.setLastModified
takes a timestamp in seconds since the epoch and sets the request's
lastModified attribute.
If the supplied timestamp is later than the lastModified attribute's
value, http.Request.setLastModified
updates the lastModifed attribute.
If the supplied timestamp occurs earlier than the current lastModified
attribute, http.Request.setLastModified
ignores it.
If the resource is older than the if-modified-since date in the request
header, http.Request.setLastModified
returns http.CACHED
.
If the resource is newer than the if-modified-since date in the request
header, http.Request.setLastModified
returns None
When http.Request.setLastModified
is called multiple times, the highest supplied value is honored. If that
value is higher than the if-modified-since date in the request header, the
method returns None.
When http.Request.setLastModified
is called multiple times, the highest supplied value is honored. If that
value is lower than the if-modified-since date in the request header, the
method returns http.CACHED
.
http.Request.setHost
sets the value of the host request header. The port should not be added
because it is the default.
http.Request.setHost
sets the value of the host request header. The port should not be added
because it is the default.
http.Request.setHost
sets the value of the host request header. The port should be added because
it is not the default.
http.Request.setHost
sets the value of the host request header. The port should be added because
it is not the default.
Call http.Request.addCookie
with *args
and **kwargs
, and check that the
cookie value is equal to expectedCookieValue
.
http.Request.addCookie
adds a new cookie to be sent with the response, and can be called with just
a key and a value. unicode
arguments are encoded using UTF-8.
http.Request.addCookie
adds a new cookie to be sent with the response. unicode
arguments are encoded using UTF-8.
http.Request.addCookie
adds a new cookie to be sent with the response, and can be called with just
a key and a value. bytes
arguments are not decoded.
http.Request.addCookie
adds a new cookie to be sent with the response. bytes
arguments are not decoded.
http.Request.addCookie
replaces linear whitespace and semicolons with single spaces.
For an HTTP 1.0 request, http.Request.write
sends an HTTP 1.0 Response-Line and whatever response headers are set.
For an HTTP 1.1 request, http.Request.write
sends an HTTP 1.1 Response-Line, whatever response headers are set, and
uses chunked encoding for the response body.
For an HTTP 1.0 request for a resource with a known last modified time,
http.Request.write
sends an HTTP Response-Line, whatever response headers are set, and a
last-modified header with that time.
If the last-modified header already exists in the http.Request
response
headers, the lastModified attribute is ignored and a message is logged.
http.Request.parseCookies
extracts cookies from requestHeaders
and adds them to
received_cookies
.
http.Request.parseCookies
can extract cookies from multiple Cookie headers.
http.Request.parseCookies
can be called on a request without a cookie header.
http.Request.parseCookies
can be called on a request with an empty cookie header.
http.Request.parseCookies
ignores cookies which don't have a value.
http.Request.parseCookies
parses cookies with an empty value.
http.Request.parseCookies
leaves trailing whitespace in the cookie value.
http.Request.parseCookies
strips leading whitespace in the cookie key.
http.Request.parseCookies
parses valid cookies set before or after malformed cookies.
http.Request.connectionLost
closes Request.content
and drops the reference to the HTTPChannel
to
assist with garbage collection.
Calling Request.registerProducer
when a producer is already
registered raises ValueError.
Calling Request.registerProducer
with an IPushProducer when
the request is not queued registers the producer as a push producer on the
request's transport.
Calling Request.registerProducer
with an IPullProducer when
the request is not queued registers the producer as a pull producer on the
request's transport.
Request.connectionLost
triggers all finish notification Deferreds and cleans up per-request
state.
Calling Request.write
after Request.finish
has
been called results in a RuntimeError
being raised.
Calling Request.finish
after Request.connectionLost
has been called results in a RuntimeError
being raised.
Calling Request.write
after Request.connectionLost
has been called does not raise an exception. RuntimeError
will be raised when finish is called on the request.
Request.__repr__
returns the class name, object address, and dummy-place holder values when
used on a Request
which has not yet been initialized.
Request.__repr__
returns, as a str
,
the class name, object address, and the method, uri, and client protocol of
the HTTP request it represents. The string is in the form:
<Request at ADDRESS method=METHOD uri=URI clientproto=PROTOCOL>
Subclasses of Request
inherit a __repr__
implementation which includes the subclass's name in place of the string
"Request"
.
Request.unregisterProducer
unregisters a non-queued
non-streaming producer from the request and the request's transport.
Request.unregisterProducer
unregisters a non-queued
streaming producer from the request and the request's transport.
http.Request.finish
will call the channel's factory to produce a log message.
HTTPChannel
timeouts whenever data from a request body is not delivered to it in time,
even when it gets built from a HTTPFactory
.
http.Request.finish
will notify the channel that it is finished, and will put the transport
back in the producing state so that the reactor can close the
connection.
http.Request
provides http._IDeprecatedHTTPChannelToRequestInterface
,
which defines the interface used by http.HTTPChannel
.
A http.Request
on the left hand side of an equality comparison to an instance that is not
a http.Request
hands the comparison off to that object's __eq__
implementation.
A http.Request
on the left hand side of an inequality comparison to an instance that is
not a http.Request
hands the comparison off to that object's __ne__
implementation.
A RuntimeError is logged if a producer is still registered when an http.Request
is
finished.
http.Request.getClientIP
returns the host part of the client's address when connected over IPv4.
http.Request.getClientIP
returns the host part of the client's address when connected over IPv6.
http.Request.getClientIP
returns None
for the client's IP address when connected over a non-TCP transport.
http.Request.getClientAddress
returns the client's address as an IAddress
provider.