test_routes_server_response
Tests for routes server response framing behavior.
Classes
RoutesServerWriteResponseTests
Bases: TestCase
Methods:
test_sets_content_length_for_large_json_payload()
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_encodes_string_body_as_utf8_bytes()
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_writes_newline_when_body_is_none()
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_calls_end_headers_without_custom_headers()
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_overrides_existing_content_length_header()
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
RoutesServerQueryParsingTests
Bases: TestCase
Tests for the query-string parsing logic in _prepare_request.
Methods:
test_single_value_key_flattened_to_string()
A query param with one value should be stored as a plain string.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_multiple_distinct_keys_parsed_independently()
Each distinct key in the query string is stored as its own entry.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_empty_query_string_produces_empty_dict()
An absent query string leaves query_params empty.
test_none_query_string_produces_empty_dict()
A None query string leaves query_params empty.
test_repeated_key_stored_as_list()
A key that appears more than once should be stored as a list.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_repeated_key_list_preserves_all_values()
All values for a repeated key must be present — none are dropped.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_mixed_single_and_multi_value_keys()
Single-value and multi-value keys can coexist in the same query.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_url_encoded_value_is_decoded()
URL percent-encoding in query values must be decoded.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_url_encoded_special_characters()
Percent-encoded characters in query values are decoded properly.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_query_params_do_not_affect_request_path()
Query string parameters must not bleed into the request path.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_query_params_do_not_affect_route_params()
Query parameters are stored separately from URL path parameters.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
RoutesServerRequestHeadersTests
Bases: TestCase
Tests that incoming HTTP headers reach the handler on request.headers.
A route could not do header-based auth, content negotiation or an Origin check before, because nothing ever copied the wire headers onto the Request. What these pin down is that a header name resolves to the same value whichever engine parsed it, since IronPython 2 hands them over lower-cased and CPython 3 hands them over as sent.
Attributes
INCOMING = {'Authorization': 'Bearer s3cr3t', 'Content-Type': 'application/json', 'X-Request-Id': 'abc-123'}
class-attribute
instance-attribute
Methods:
test_incoming_headers_are_not_empty()
The headers of an incoming request must not be dropped.
Regression guard for the bug this fixes: request.headers was always {}.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_every_incoming_header_reaches_the_request()
Each header the client sent is readable on the prepared request.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_authorization_resolves_regardless_of_name_case()
The lookup a bearer-token check performs must work on both engines.
IronPython 2 reports 'authorization' and CPython 3 reports 'Authorization'
for the same request; get("Authorization") has to answer both.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_header_name_membership_ignores_case()
in resolves a header name without regard to case.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_absent_header_reads_as_none()
A header the client did not send has no value, rather than raising.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_header_names_are_exposed_normalized()
Names are stored lower-cased, so iterating is stable across engines.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_repeated_header_collapses_to_a_single_value()
A client repeating a name leaves one entry, whichever value wins.
Which of the repeats survives is not asserted: the order IronPython 2 reports repeated names in comes from a dict, which does not define one. What must hold is that the repeats do not fan out into several entries.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_setting_the_same_name_differently_replaces_the_value()
Writing one name twice leaves a single entry, not two.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_headers_are_removed_by_name_regardless_of_case()
Deleting and popping match without regard to case.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_setdefault_does_not_overwrite_an_existing_header()
Setdefault fills an absent name only, matching plain dict semantics.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_update_normalizes_every_name_it_adds()
A bulk update routes through the same normalization as add_header.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_copy_is_independent_and_case_insensitive()
A copy keeps the case-insensitive behavior without sharing state.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_headers_stay_out_of_the_query_and_path_parameters()
Headers must not bleed into the handler's other injected arguments.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_request_headers_are_a_plain_dict_for_consumers()
Handlers copy the mapping wholesale, as the issue's repro does.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_response_headers_are_untouched()
Only request headers gained case-insensitive lookup.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
RoutesServerHandlerKwargsTests
Bases: TestCase
Tests that query_params are injected into handler kwargs correctly.
Methods:
test_single_query_param_injected_as_kwarg()
A single-value query param is passed to the handler as a kwarg.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_multi_value_query_param_injected_as_list()
A repeated query param is passed to the handler as a list kwarg.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_query_param_not_in_handler_signature_is_excluded()
Query params that don't match handler parameters are filtered out.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_request_object_always_injected()
The request object is always present in handler kwargs.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_response.py
test_query_params_and_route_params_coexist_in_kwargs()
Route path params and query params are both present in kwargs.