Add tests showing current behaviour of how multiple response headers with the same name are compiled into a single value.

This commit is contained in:
Allan Crooks
2017-09-10 09:53:26 +01:00
parent c7266a5ff4
commit 5980d5df3e
+20
View File
@@ -4,6 +4,7 @@
"""Tests for Requests."""
from __future__ import division
import itertools
import json
import os
import pickle
@@ -2179,6 +2180,25 @@ class TestRequests:
assert not r.history[1].is_redirect
assert r.url == urls_test[2]
def test_multiple_response_headers_with_same_name_same_case(self, httpbin):
qs = 'Fruit=Apple&Fruit=Blood+Orange&Fruit=Banana&Fruit=Berry,+Blue'
resp = requests.get(httpbin('response-headers?' + qs))
fruits = resp.headers['fruit']
assert fruits == 'Apple, Blood Orange, Banana, Berry, Blue'
def test_multiple_response_headers_with_same_name_diff_case(self, httpbin):
# urllib3 seems to have trouble guaranteeing the order of the items when
# the case is different, so we just need to make sure all of the items
# are there, rather than asserting a particular order.
qs = 'Fruit=Apple&Fruit=Blood+Orange&Fruit=Banana&Fruit=Berry,+Blue'
resp = requests.get(httpbin('response-headers?' + qs))
# These are all possible acceptable combinations for the header.
fruit_choices = ['Apple', 'Blood Orange', 'Banana', 'Berry, Blue']
fruit_permutations = itertools.permutations(fruit_choices)
fruit_headers = set(', '.join(fp) for fp in fruit_permutations)
assert resp.headers['fruit'] in fruit_headers
class TestCaseInsensitiveDict: