class RequestTests(unittest.TestCase, ResponseTestMixin): (source)
Tests for http.Request
Method | test_add |
http.Request.setCookie supports a sameSite argument. |
Method | test_add |
http.Request.addCookie replaces linear whitespace and semicolons with single spaces. |
Method | test_add |
http.Request.addCookie adds a new cookie to be sent with the response. bytes arguments are not decoded. |
Method | test_add |
http.Request.addCookie adds a new cookie to be sent with the response. unicode arguments are encoded using UTF-8. |
Method | test_add |
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_add |
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_connection |
http.Request.connectionLost closes Request.content and drops the reference to the HTTPChannel to assist with garbage collection. |
Method | test_connection |
Request.connectionLost triggers all finish notification Deferreds and cleans up per-request state. |
Method | test |
A http.Request is equal to itself. |
Method | test_eq |
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_finish |
Calling Request.finish after Request.connectionLost has been called results in a RuntimeError being raised. |
Method | test_finish |
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_finish |
Request.finish triggers all finish notification Deferreds. |
Method | test_finish |
A RuntimeError is logged if a producer is still registered when an http.Request is finished. |
Method | test_finish |
http.Request.finish will call the channel's factory to produce a log message. |
Method | test_first |
For an HTTP 1.0 request, http.Request.write sends an HTTP 1.0 Response-Line and whatever response headers are set. |
Method | test_first |
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_first |
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_get |
http.Request.getAllheaders returns a dict mapping all request header names to their corresponding values. |
Method | test_get |
When there are multiple values for a single request header, http.Request.getAllHeaders returns only the last value. |
Method | test_get |
http.Request.getAllHeaders returns an empty dict if there are no request headers. |
Method | test_get |
http.Request.getClientAddress returns the client's address as an IAddress provider. |
Method | test_get |
http.Request.getClientIP returns the host part of the client's address when connected over IPv4. |
Method | test_get |
http.Request.getClientIP returns the host part of the client's address when connected over IPv6. |
Method | test_get |
http.Request.getClientIP returns None for the client's IP address when connected over a non-TCP transport. |
Method | test_get |
http.Request.getHeader returns the value of the named request header. |
Method | test_get |
http.Request.getHeader returns None when asked for the value of a request header which is not present. |
Method | test_get |
When there are multiple values for a single request header, http.Request.getHeader returns the last value. |
Method | test_get |
http.Request.getRequestHostname returns the hostname portion of the request, based on the Host: header. |
Method | test |
A http.Request is hashable. |
Method | test_last |
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 |
A http.Request is not equal to another object. |
Method | test_ne |
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_parse |
http.Request.parseCookies extracts cookies from requestHeaders and adds them to received_cookies. |
Method | test_parse |
http.Request.parseCookies parses valid cookies set before or after malformed cookies. |
Method | test_parse |
http.Request.parseCookies can be called on a request with an empty cookie header. |
Method | test_parse |
http.Request.parseCookies parses cookies with an empty value. |
Method | test_parse |
http.Request.parseCookies ignores cookies which don't have a value. |
Method | test_parse |
http.Request.parseCookies can extract cookies from multiple Cookie headers. |
Method | test_parse |
http.Request.parseCookies can be called on a request without a cookie header. |
Method | test_parse |
http.Request.parseCookies leaves trailing whitespace in the cookie value. |
Method | test_parse |
http.Request.parseCookies strips leading whitespace in the cookie key. |
Method | test_provides_ |
http.Request provides http._IDeprecatedHTTPChannelToRequestInterface , which defines the interface used by http.HTTPChannel . |
Method | test_received |
http.Request.received_cookies defaults to an empty dict . |
Method | test_register |
Calling Request.registerProducer when a producer is already registered raises ValueError. |
Method | test_register |
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_register |
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_repr |
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: |
Method | test_repr |
Subclasses of Request inherit a __repr__ implementation which includes the subclass's name in place of the string "Request". |
Method | test_repr |
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_request |
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_set |
http.Request.setHeader sets the value of the given response header. |
Method | test_set |
http.Request.setHost sets the value of the host request header. The port should not be added because it is the default. |
Method | test_set |
http.Request.setHost sets the value of the host request header. The port should be added because it is not the default. |
Method | test_set |
http.Request.setHost sets the value of the host request header. The port should not be added because it is the default. |
Method | test_set |
http.Request.setHost sets the value of the host request header. The port should be added because it is not the default. |
Method | test_set |
If the resource is older than the if-modified-since date in the request header, http.Request.setLastModified returns http.CACHED . |
Method | test_set |
If the supplied timestamp occurs earlier than the current lastModified attribute, http.Request.setLastModified ignores it. |
Method | test_set |
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_set |
If the resource is newer than the if-modified-since date in the request header, http.Request.setLastModified returns None |
Method | test_set |
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 ... |
Method | test_set |
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_set |
If the supplied timestamp is later than the lastModified attribute's value, http.Request.setLastModified updates the lastModifed attribute. |
Method | test_set |
http.Request.setResponseCode takes a status code and causes it to be used as the response status. |
Method | test_set |
http.Request.setResponseCode accepts int for the code parameter and raises TypeError if passed anything else. |
Method | test_set |
http.Request.setResponseCode accepts int for the code parameter. |
Method | test_set |
http.Request.setResponseCode takes a status code and a message and causes them to be used as the response status. |
Method | test_set |
http.Request.setResponseCode accepts bytes for the message parameter and raises TypeError if passed anything else. |
Method | test_unregister |
Request.unregisterProducer unregisters a non-queued non-streaming producer from the request and the request's transport. |
Method | test_unregister |
Request.unregisterProducer unregisters a non-queued streaming producer from the request and the request's transport. |
Method | test_write |
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_write |
Calling Request.write after Request.finish has been called results in a RuntimeError being raised. |
Method | _check |
Call http.Request.addCookie with *args and **kwargs, and check that the cookie value is equal to expectedCookieValue. |
Method | _compat |
Verify that each of two different attributes which are associated with the same state properly reflect changes made through the other. |
Inherited from TestCase
:
Method | __call__ |
Run the test. Should always do exactly the same thing as run(). |
Method | __init__ |
Construct an asynchronous test case for methodName. |
Method | add |
Extend the base cleanup feature with support for cleanup functions which return Deferreds. |
Method | assert |
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 | defer |
Run any scheduled cleanups and report errors (if any) to the result. object. |
Method | defer |
Undocumented |
Method | defer |
Undocumented |
Method | defer |
Undocumented |
Method | get |
Undocumented |
Method | get |
Returns the timeout value set on this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a timeout attribute, returns that. Returns util.DEFAULT_TIMEOUT_DURATION ... |
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 | _cb |
Undocumented |
Method | _class |
Undocumented |
Method | _clean |
Undocumented |
Method | _deprecate |
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 | _eb |
Undocumented |
Method | _eb |
Undocumented |
Method | _eb |
Undocumented |
Method | _make |
Create a method which wraps the reactor method name. The new method issues a deprecation warning and calls the original. |
Method | _run |
Run a single method, either a test method or fixture. |
Method | _run |
Really run setUp, the test method, and tearDown. Any of these may return defer.Deferred s. After they complete, do some reactor cleanup. |
Method | _undeprecate |
Restore the deprecated reactor methods. Undoes what _deprecateReactor did. |
Method | _wait |
Take a Deferred that only ever callbacks. Block until it happens. |
Instance Variable | _passed |
Undocumented |
Instance Variable | _reactor |
Undocumented |
Instance Variable | _timed |
Undocumented |
Inherited from SynchronousTestCase
(via TestCase
):
Method | __eq__ |
Override the comparison defined by the base TestCase which considers instances of the same class with the same _testMethodName to be equal. Since trial puts TestCase instances into a set, that definition of comparison makes it impossible to run the same test method twice... |
Method | __hash__ |
Undocumented |
Method | call |
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 | flush |
Remove stored errors received from the log. |
Method | flush |
Remove stored warnings from the list of captured warnings and return them. |
Method | get |
Retrieve a module attribute which should have been deprecated, and assert that we saw the appropriate deprecation warning. |
Method | get |
Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a skip attribute, returns that in a tuple (... |
Method | get |
Return a Todo object if the test is marked todo. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a todo attribute, returns that. Returns ... |
Method | mktemp |
Create a new path name which can be used for a new file or directory. |
Method | patch |
Monkey patch an object for the duration of the test. |
Method | run |
Run the test case, storing the results in result. |
Method | run |
If no methodName argument is passed to the constructor, run will treat this method as the thing with the actual test inside. |
Method | short |
Undocumented |
Instance Variable | failure |
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 | 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 . |
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. |
Method | _get |
Return the reason to use for skipping a test method. |
Method | _get |
Returns any warning suppressions set for this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a suppress attribute, returns that. ... |
Method | _install |
Undocumented |
Method | _remove |
Undocumented |
Method | _run |
Synchronously run any cleanups which have been added. |
Instance Variable | _cleanups |
Undocumented |
Instance Variable | _observer |
Undocumented |
Instance Variable | _parents |
Undocumented |
Instance Variable | _test |
Undocumented |
Instance Variable | _warnings |
Undocumented |
Inherited from _Assertions
(via TestCase
, SynchronousTestCase
):
Method | assert |
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 | assert |
Fail if first - second > tolerance |
Method | assert |
Fail the test if first and second are not equal. |
Method | assert |
Fail the test if condition evaluates to True. |
Method | assert |
Fail the test if containee is not found in container. |
Method | assert |
Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test. |
Method | assert |
Fail if instance is not an instance of the given class or of one of the given classes. |
Method | assert |
Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test. |
Method | assert |
Assert that deferred does not have a result at this point. |
Method | assert |
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 | assert |
Fail the test if first == second. |
Method | assert |
Fail the test if containee is found in container. |
Method | assert |
Fail if instance is an instance of the given class or of one of the given classes. |
Method | assert |
Fail if astring contains substring. |
Method | assert |
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 | assert |
Fail if substring does not exist within astring. |
Method | assert |
Fail the test if condition evaluates to False. |
Method | assert |
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 | fail |
Absolutely fail the test. Do not pass go, do not collect $200. |
Method | failure |
Return the current failure result of deferred or raise self.failureException. |
Method | success |
Return the current success result of deferred or raise self.failureException. |
Inherited from ResponseTestMixin
(via TestCase
, SynchronousTestCase
, _Assertions
):
Method | assert |
Assert that the responses matches the expected responses. |
http.Request.addCookie
adds a new cookie to be sent with the response. bytes
arguments are not decoded.
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, and can be called with just a key and a value. unicode
arguments are encoded using UTF-8.
http.Request.connectionLost
closes Request.content
and drops the reference to the HTTPChannel
to assist with garbage collection.
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.
Calling Request.finish
after Request.connectionLost
has been called results in a RuntimeError
being raised.
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.
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.
http.Request.getAllheaders
returns a dict mapping all request header names to their corresponding values.
When there are multiple values for a single request header, http.Request.getAllHeaders
returns only the last value.
http.Request.getClientIP
returns None
for the client's IP address when connected over a non-TCP transport.
http.Request.getHeader
returns None
when asked for the value of a request header which is not present.
When there are multiple values for a single request header, http.Request.getHeader
returns the last value.
http.Request.getRequestHostname
returns the hostname portion of the request, based on the Host: header.
If the last-modified header already exists in the http.Request
response headers, the lastModified attribute is ignored and a message is logged.
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.
http.Request
provides http._IDeprecatedHTTPChannelToRequestInterface
, which defines the interface used by http.HTTPChannel
.
Calling Request.registerProducer
with an IPullProducer when the request is not queued registers the producer as a pull producer on the request's transport.
Calling Request.registerProducer
with an IPushProducer when the request is not queued registers the producer as a push producer on the request's transport.
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.__repr__
returns the class name, object address, and dummy-place holder values when used on a Request
which has not yet been initialized.
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.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 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.
If the resource is older than the if-modified-since date in the request header, http.Request.setLastModified
returns http.CACHED
.
If the supplied timestamp occurs earlier than the current lastModified attribute, http.Request.setLastModified
ignores it.
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 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 lower than the if-modified-since date in the request header, the method returns http.CACHED
.
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.
If the supplied timestamp is later than the lastModified attribute's value, http.Request.setLastModified
updates the lastModifed attribute.
http.Request.setResponseCode
accepts int for the code parameter and raises TypeError
if passed anything else.
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.
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.
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.
Call http.Request.addCookie
with *args and **kwargs, and check that the cookie value is equal to expectedCookieValue.