def test_basics(self): h = Headers({'Content-Type': 'text/html', 'Content-Length': 1234}) assert h['Content-Type'] assert h['Content-Length'] self.assertRaises(KeyError, h.__getitem__, 'Accept') self.assertEqual(h.get('Accept'), None) self.assertEqual(h.getlist('Accept'), []) self.assertEqual(h.get('Accept', '*/*'), '*/*') self.assertEqual(h.getlist('Accept', '*/*'), ['*/*']) self.assertEqual(h.getlist('Accept', ['text/html', 'images/jpeg']), ['text/html','images/jpeg'])
def test_basics(self): h = Headers({"Content-Type": "text/html", "Content-Length": 1234}) assert h["Content-Type"] assert h["Content-Length"] self.assertRaises(KeyError, h.__getitem__, "Accept") self.assertEqual(h.get("Accept"), None) self.assertEqual(h.getlist("Accept"), []) self.assertEqual(h.get("Accept", "*/*"), b"*/*") self.assertEqual(h.getlist("Accept", "*/*"), [b"*/*"]) self.assertEqual( h.getlist("Accept", ["text/html", "images/jpeg"]), [b"text/html", b"images/jpeg"], )
def test_none_value(self): h1 = Headers() h1['foo'] = 'bar' h1['foo'] = None h1.setdefault('foo', 'bar') self.assertEqual(h1.get('foo'), None) self.assertEqual(h1.getlist('foo'), [])
def test_multivalue(self): h = Headers() h['X-Forwarded-For'] = hlist = ['ip1', 'ip2'] self.assertEqual(h['X-Forwarded-For'], b'ip2') self.assertEqual(h.get('X-Forwarded-For'), b'ip2') self.assertEqual(h.getlist('X-Forwarded-For'), [b'ip1', b'ip2']) assert h.getlist('X-Forwarded-For') is not hlist
def test_multivalue(self): h = Headers() h["X-Forwarded-For"] = hlist = ["ip1", "ip2"] self.assertEqual(h["X-Forwarded-For"], b"ip2") self.assertEqual(h.get("X-Forwarded-For"), b"ip2") self.assertEqual(h.getlist("X-Forwarded-For"), [b"ip1", b"ip2"]) assert h.getlist("X-Forwarded-For") is not hlist
def test_none_value(self): h1 = Headers() h1["foo"] = "bar" h1["foo"] = None h1.setdefault("foo", "bar") self.assertEqual(h1.get("foo"), None) self.assertEqual(h1.getlist("foo"), [])
def test_single_value(self): h = Headers() h['Content-Type'] = 'text/html' self.assertEqual(h['Content-Type'], 'text/html') self.assertEqual(h.get('Content-Type'), 'text/html') self.assertEqual(h.getlist('Content-Type'), ['text/html'])
def test_multivalue_for_one_header(self): h = Headers((("a", "b"), ("a", "c"))) self.assertEqual(h["a"], b"c") self.assertEqual(h.get("a"), b"c") self.assertEqual(h.getlist("a"), [b"b", b"c"])
def test_single_value(self): h = Headers() h["Content-Type"] = "text/html" self.assertEqual(h["Content-Type"], b"text/html") self.assertEqual(h.get("Content-Type"), b"text/html") self.assertEqual(h.getlist("Content-Type"), [b"text/html"])