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.getHeaderreturns the value of the named request header. | 
| Method | test_getHeaderReceivedMultiples | When there are multiple values for a single request header, http.Request.getHeaderreturns the last value. | 
| Method | test_getHeaderNotFound | http.Request.getHeaderreturnsNonewhen asked for the value of a request header which is not present. | 
| Method | test_getAllHeaders | http.Request.getAllheadersreturns adictmapping all request header names to their corresponding values. | 
| Method | test_getAllHeadersNoHeaders | http.Request.getAllHeadersreturns an emptydictif there are no request headers. | 
| Method | test_getAllHeadersMultipleHeaders | When there are multiple values for a single request header, http.Request.getAllHeadersreturns only the last value. | 
| Method | test_setResponseCode | http.Request.setResponseCodetakes a status code and causes it to be used as the response status. | 
| Method | test_setResponseCodeAndMessage | http.Request.setResponseCodetakes a status code and a message and causes them to be used as the 
response status. | 
| Method | test_setResponseCodeAndMessageNotBytes | http.Request.setResponseCodeacceptsbytesfor the message parameter and raisesTypeErrorif passed anything else. | 
| Method | test_setResponseCodeAcceptsIntegers | http.Request.setResponseCodeacceptsintfor the code parameter and raisesTypeErrorif passed anything else. | 
| Method | test_setResponseCodeAcceptsLongIntegers | http.Request.setResponseCodeacceptslongfor the code parameter. | 
| Method | test_setLastModifiedNeverSet | When no previous value was set and no 'if-modified-since' value was 
requested, http.Request.setLastModifiedtakes 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.setLastModifiedupdates the lastModifed attribute. | 
| Method | test_setLastModifiedIgnore | If the supplied timestamp occurs earlier than the current lastModified 
attribute, http.Request.setLastModifiedignores it. | 
| Method | test_setLastModifiedCached | If the resource is older than the if-modified-since date in the request 
header, http.Request.setLastModifiedreturnshttp.CACHED. | 
| Method | test_setLastModifiedNotCached | If the resource is newer than the if-modified-since date in the request 
header, http.Request.setLastModifiedreturns None | 
| Method | test_setLastModifiedTwiceNotCached | When http.Request.setLastModifiedis 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.setHostsets the value of the host request header. The port should not be added 
because it is the default. | 
| Method | test_setHostSSL | http.Request.setHostsets the value of the host request header. The port should not be added 
because it is the default. | 
| Method | test_setHostNonDefaultPort | http.Request.setHostsets the value of the host request header. The port should be added because
it is not the default. | 
| Method | test_setHostSSLNonDefaultPort | http.Request.setHostsets the value of the host request header. The port should be added because
it is not the default. | 
| Method | test_setHeader | http.Request.setHeadersets the value of the given response header. | 
| Method | test_addCookieWithMinimumArgumentsUnicode | http.Request.addCookieadds a new cookie to be sent with the response, and can be called with just
a key and a value.unicodearguments are encoded using UTF-8. | 
| Method | test_addCookieWithAllArgumentsUnicode | http.Request.addCookieadds a new cookie to be sent with the response.unicodearguments are encoded using UTF-8. | 
| Method | test_addCookieWithMinimumArgumentsBytes | http.Request.addCookieadds a new cookie to be sent with the response, and can be called with just
a key and a value.bytesarguments are not decoded. | 
| Method | test_addCookieWithAllArgumentsBytes | http.Request.addCookieadds a new cookie to be sent with the response.bytesarguments are not decoded. | 
| Method | test_addCookieSanitization | http.Request.addCookiereplaces linear whitespace and semicolons with single spaces. | 
| Method | test_addCookieSameSite | http.Request.setCookiesupports asameSiteargument. | 
| Method | test_firstWrite | For an HTTP 1.0 request, http.Request.writesends an HTTP 1.0 Response-Line and whatever response headers are set. | 
| Method | test_firstWriteHTTP11Chunked | For an HTTP 1.1 request, http.Request.writesends 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.writesends 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.Requestresponse
headers, the lastModified attribute is ignored and a message is logged. | 
| Method | test_receivedCookiesDefault | http.Request.received_cookiesdefaults to an emptydict. | 
| Method | test_parseCookies | http.Request.parseCookiesextracts cookies fromrequestHeadersand adds them toreceived_cookies. | 
| Method | test_parseCookiesMultipleHeaders | http.Request.parseCookiescan extract cookies from multiple Cookie headers. | 
| Method | test_parseCookiesNoCookie | http.Request.parseCookiescan be called on a request without a cookie header. | 
| Method | test_parseCookiesEmptyCookie | http.Request.parseCookiescan be called on a request with an empty cookie header. | 
| Method | test_parseCookiesIgnoreValueless | http.Request.parseCookiesignores cookies which don't have a value. | 
| Method | test_parseCookiesEmptyValue | http.Request.parseCookiesparses cookies with an empty value. | 
| Method | test_parseCookiesRetainRightSpace | http.Request.parseCookiesleaves trailing whitespace in the cookie value. | 
| Method | test_parseCookiesStripLeftSpace | http.Request.parseCookiesstrips leading whitespace in the cookie key. | 
| Method | test_parseCookiesContinueAfterMalformedCookie | http.Request.parseCookiesparses valid cookies set before or after malformed cookies. | 
| Method | test_connectionLost | http.Request.connectionLostclosesRequest.contentand drops the reference to theHTTPChannelto 
assist with garbage collection. | 
| Method | test_registerProducerTwiceFails | Calling Request.registerProducerwhen a producer is already
registered raises ValueError. | 
| Method | test_registerProducerWhenNotQueuedRegistersPushProducer | Calling Request.registerProducerwith 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.registerProducerwith an IPullProducer when
the request is not queued registers the producer as a pull producer on the 
request's transport. | 
| Method | test_connectionLostNotification | Request.connectionLosttriggers all finish notification Deferreds and cleans up per-request 
state. | 
| Method | test_finishNotification | Request.finishtriggers all finish notification 
Deferreds. | 
| Method | test_writeAfterFinish | Calling Request.writeafterRequest.finishhas
been called results in aRuntimeErrorbeing raised. | 
| Method | test_finishAfterConnectionLost | Calling Request.finishafterRequest.connectionLosthas been called results in aRuntimeErrorbeing raised. | 
| Method | test_writeAfterConnectionLost | Calling Request.writeafterRequest.connectionLosthas been called does not raise an exception.RuntimeErrorwill 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 aRequestwhich has not yet been initialized. | 
| Method | test_reprInitialized | 
 | 
| Method | test_reprSubclass | Subclasses of Requestinherit a__repr__implementation which includes the subclass's name in place of the string"Request". | 
| Method | test_unregisterNonQueuedNonStreamingProducer | Request.unregisterProducerunregisters a non-queued 
non-streaming producer from the request and the request's transport. | 
| Method | test_unregisterNonQueuedStreamingProducer | Request.unregisterProducerunregisters a non-queued 
streaming producer from the request and the request's transport. | 
| Method | test_finishProducesLog | http.Request.finishwill call the channel's factory to produce a log message. | 
| Method | test_requestBodyTimeoutFromFactory | HTTPChanneltimeouts whenever data from a request body is not delivered to it in time, 
even when it gets built from aHTTPFactory. | 
| Method | test_finishCleansConnection | http.Request.finishwill 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.Requestprovideshttp._IDeprecatedHTTPChannelToRequestInterface,
which defines the interface used byhttp.HTTPChannel. | 
| Method | test_eq | A http.Requestis equal to itself. | 
| Method | test_ne | A http.Requestis not equal to another object. | 
| Method | test_hashable | A http.Requestis hashable. | 
| Method | test_eqWithNonRequest | A http.Requeston the left hand side of an equality comparison to an instance that is not 
ahttp.Requesthands the comparison off to that object's__eq__implementation. | 
| Method | test_neWithNonRequest | A http.Requeston the left hand side of an inequality comparison to an instance that is 
not ahttp.Requesthands 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.Requestis 
finished. | 
| Method | test_getClientIPWithIPv4 | http.Request.getClientIPreturns the host part of the client's address when connected over IPv4. | 
| Method | test_getClientIPWithIPv6 | http.Request.getClientIPreturns the host part of the client's address when connected over IPv6. | 
| Method | test_getClientIPWithNonTCPPeer | http.Request.getClientIPreturnsNonefor the client's IP address when connected over a non-TCP transport. | 
| Method | test_getClientAddress | http.Request.getClientAddressreturns the client's address as anIAddressprovider. | 
| 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.addCookiewith*argsand**kwargs, and check that the 
cookie value is equal toexpectedCookieValue. | 
Inherited from TestCase:
| Instance Variable | timeout | A real number of seconds. If set, the test will raise an error if it takes 
longer than timeoutseconds. If not set, 
util.DEFAULT_TIMEOUT_DURATION is used. | 
| Method | __init__ | Construct an asynchronous test case for methodName. | 
| Method | assertFailure | Fail if deferreddoes not errback with one ofexpectedFailures. 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,crashandstoponreactor. 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 _deprecateReactordid. | 
| Method | _runCleanups | Run the cleanups added with addCleanupin order. | 
| Method | _runFixturesAndTest | Really run setUp, the test method, andtearDown.  Any of these may returndefer.Deferreds.
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 | Noneor 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 theTestResultsupports skipping). | 
| Instance Variable | todo | None,
a string or a tuple of(errors, reason)whereerrorsis either an exception class or an iterable of 
exception classes, andreasonis a string. SeeTodoormakeTodofor 
more information. | 
| Instance Variable | suppress | Noneor a list of tuples of(args, kwargs)to be passed towarnings.filterwarnings. Use these to suppress warnings raised
in a test. Useful for testing deprecated code. See alsoutil.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 methodNameargument is passed to the constructor,runwill 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 conditionevaluates to True. | 
| Method | assertTrue | Fail the test if conditionevaluates to False. | 
| Method | assertRaises | Fail the test unless calling the function fwith the givenargsandkwargsraisesexception. 
The failure will report the traceback and call stack of the unexpected 
exception. | 
| Method | assertEqual | Fail the test if firstandsecondare not 
equal. | 
| Method | assertIs | Fail the test if firstis notsecond.  This is
an obect-identity-equality test, not an object equality (i.e.__eq__) test. | 
| Method | assertIsNot | Fail the test if firstissecond.  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 containeeis not found incontainer. | 
| Method | assertNotIn | Fail the test if containeeis found incontainer. | 
| 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 substringdoes not exist withinastring. | 
| Method | assertNotSubstring | Fail if astringcontainssubstring. | 
| 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 instanceis not an instance of the given class or 
of one of the given classes. | 
| Method | assertNotIsInstance | Fail if instanceis an instance of the given class or of 
one of the given classes. | 
| Method | successResultOf | Return the current success result of deferredor raiseself.failureException. | 
| Method | failureResultOf | Return the current failure result of deferredor raiseself.failureException. | 
| Method | assertNoResult | Assert that deferreddoes not have a result at this 
point. | 
| Method | assertRegex | Fail the test if a regexpsearch oftextfails. | 
Inherited from ResponseTestMixin:
| Method | assertResponseEquals | Assert that the responsesmatches theexpectedresponses. | 
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.