Exemplo n.º 1
0
    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'])
Exemplo n.º 2
0
    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"],
        )
Exemplo n.º 3
0
 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'), [])
Exemplo n.º 4
0
 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'), [])
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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"), [])
Exemplo n.º 9
0
 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'])
Exemplo n.º 10
0
 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'])
Exemplo n.º 11
0
 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"])
Exemplo n.º 12
0
 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"])