Skip to content
Myr

Merge pull request #3048 from Stranger6667/test-structures

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Added unit tests for structures module

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 456be3c, 81dc908 · Browse files · 1 file+79 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+79 added−0 removed

  • tests:+79 added−0 removed

1 file+79 added−0 removed

added:tests/test_structures.py+79 added
1# coding: utf-82import pytest34from requests.structures import CaseInsensitiveDict, LookupDict567class TestCaseInsensitiveDict:89 @pytest.fixture(autouse=True)10 def setup(self):11 """12 CaseInsensitiveDict instance with "Accept" header.13 """14 self.case_insensitive_dict = CaseInsensitiveDict()15 self.case_insensitive_dict['Accept'] = 'application/json'1617 def test_list(self):18 assert list(self.case_insensitive_dict) == ['Accept']1920 possible_keys = pytest.mark.parametrize('key', ('accept', 'ACCEPT', 'aCcEpT', 'Accept'))2122 @possible_keys23 def test_getitem(self, key):24 assert self.case_insensitive_dict[key] == 'application/json'2526 @possible_keys27 def test_delitem(self, key):28 del self.case_insensitive_dict[key]29 assert key not in self.case_insensitive_dict3031 def test_lower_items(self):32 assert list(self.case_insensitive_dict.lower_items()) == [('accept', 'application/json')]3334 def test_repr(self):35 assert repr(self.case_insensitive_dict) == "{'Accept': 'application/json'}"3637 def test_copy(self):38 copy = self.case_insensitive_dict.copy()39 assert copy is not self.case_insensitive_dict40 assert copy == self.case_insensitive_dict4142 @pytest.mark.parametrize(43 'other, result', (44 ({'AccePT': 'application/json'}, True),45 ({}, False),46 (None, False)47 )48 )49 def test_instance_equality(self, other, result):50 assert (self.case_insensitive_dict == other) is result515253class TestLookupDict:5455 @pytest.fixture(autouse=True)56 def setup(self):57 """58 LookupDict instance with "bad_gateway" attribute.59 """60 self.lookup_dict = LookupDict('test')61 self.lookup_dict.bad_gateway = 5026263 def test_repr(self):64 assert repr(self.lookup_dict) == "<lookup 'test'>"6566 get_item_parameters = pytest.mark.parametrize(67 'key, value', (68 ('bad_gateway', 502),69 ('not_a_key', None)70 )71 )7273 @get_item_parameters74 def test_getitem(self, key, value):75 assert self.lookup_dict[key] == value7677 @get_item_parameters78 def test_get(self, key, value):79 assert self.lookup_dict.get(key) == value