From 5980d5df3e4cf1e2d420c24dec667018e2ccad02 Mon Sep 17 00:00:00 2001 From: Allan Crooks Date: Sun, 10 Sep 2017 09:53:26 +0100 Subject: [PATCH] Add tests showing current behaviour of how multiple response headers with the same name are compiled into a single value. --- tests/test_requests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_requests.py b/tests/test_requests.py index 272d3fd4..8aa0af0d 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -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: