aboutsummaryrefslogtreecommitdiff
path: root/test/test_collections.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_collections.py')
-rw-r--r--test/test_collections.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/test/test_collections.py b/test/test_collections.py
index b44c58a..4d173ac 100644
--- a/test/test_collections.py
+++ b/test/test_collections.py
@@ -1,6 +1,9 @@
import unittest
-from urllib3._collections import RecentlyUsedContainer as Container
+from urllib3._collections import (
+ HTTPHeaderDict,
+ RecentlyUsedContainer as Container
+)
from urllib3.packages import six
xrange = six.moves.xrange
@@ -121,5 +124,57 @@ class TestLRUContainer(unittest.TestCase):
self.assertRaises(NotImplementedError, d.__iter__)
+
+class TestHTTPHeaderDict(unittest.TestCase):
+ def setUp(self):
+ self.d = HTTPHeaderDict(A='foo')
+ self.d.add('a', 'bar')
+
+ def test_overwriting_with_setitem_replaces(self):
+ d = HTTPHeaderDict()
+
+ d['A'] = 'foo'
+ self.assertEqual(d['a'], 'foo')
+
+ d['a'] = 'bar'
+ self.assertEqual(d['A'], 'bar')
+
+ def test_copy(self):
+ h = self.d.copy()
+ self.assertTrue(self.d is not h)
+ self.assertEqual(self.d, h)
+
+ def test_add(self):
+ d = HTTPHeaderDict()
+
+ d['A'] = 'foo'
+ d.add('a', 'bar')
+
+ self.assertEqual(d['a'], 'foo, bar')
+ self.assertEqual(d['A'], 'foo, bar')
+
+ def test_getlist(self):
+ self.assertEqual(self.d.getlist('a'), ['foo', 'bar'])
+ self.assertEqual(self.d.getlist('A'), ['foo', 'bar'])
+ self.assertEqual(self.d.getlist('b'), [])
+
+ def test_delitem(self):
+ del self.d['a']
+ self.assertFalse('a' in self.d)
+ self.assertFalse('A' in self.d)
+
+ def test_equal(self):
+ b = HTTPHeaderDict({'a': 'foo, bar'})
+ self.assertEqual(self.d, b)
+ c = [('a', 'foo, bar')]
+ self.assertNotEqual(self.d, c)
+
+ def test_len(self):
+ self.assertEqual(len(self.d), 1)
+
+ def test_repr(self):
+ rep = "HTTPHeaderDict({'A': 'foo, bar'})"
+ self.assertEqual(repr(self.d), rep)
+
if __name__ == '__main__':
unittest.main()