Skip to content
Myr

test_structures.py

This file

Path

tests/test_structures.py

76 lines · 2.2 KiB · Python

Last changed by

Merge pull request #3979 from schlamar/bypass-proxyCory Benfieldbefore adoption216aee4

History of this file

Take it

1# -*- coding: utf-8 -*-23import pytest45from requests.structures import CaseInsensitiveDict, LookupDict678class TestCaseInsensitiveDict:910    @pytest.fixture(autouse=True)11    def setup(self):12        """CaseInsensitiveDict instance with "Accept" header."""13        self.case_insensitive_dict = CaseInsensitiveDict()14        self.case_insensitive_dict['Accept'] = 'application/json'1516    def test_list(self):17        assert list(self.case_insensitive_dict) == ['Accept']1819    possible_keys = pytest.mark.parametrize('key', ('accept', 'ACCEPT', 'aCcEpT', 'Accept'))2021    @possible_keys22    def test_getitem(self, key):23        assert self.case_insensitive_dict[key] == 'application/json'2425    @possible_keys26    def test_delitem(self, key):27        del self.case_insensitive_dict[key]28        assert key not in self.case_insensitive_dict2930    def test_lower_items(self):31        assert list(self.case_insensitive_dict.lower_items()) == [('accept', 'application/json')]3233    def test_repr(self):34        assert repr(self.case_insensitive_dict) == "{'Accept': 'application/json'}"3536    def test_copy(self):37        copy = self.case_insensitive_dict.copy()38        assert copy is not self.case_insensitive_dict39        assert copy == self.case_insensitive_dict4041    @pytest.mark.parametrize(42        'other, result', (43            ({'AccePT': 'application/json'}, True),44            ({}, False),45            (None, False)46        )47    )48    def test_instance_equality(self, other, result):49        assert (self.case_insensitive_dict == other) is result505152class TestLookupDict:5354    @pytest.fixture(autouse=True)55    def setup(self):56        """LookupDict instance with "bad_gateway" attribute."""57        self.lookup_dict = LookupDict('test')58        self.lookup_dict.bad_gateway = 5025960    def test_repr(self):61        assert repr(self.lookup_dict) == "<lookup 'test'>"6263    get_item_parameters = pytest.mark.parametrize(64        'key, value', (65            ('bad_gateway', 502),66            ('not_a_key', None)67        )68    )6970    @get_item_parameters71    def test_getitem(self, key, value):72        assert self.lookup_dict[key] == value7374    @get_item_parameters75    def test_get(self, key, value):76        assert self.lookup_dict.get(key) == value