Exemplo n.º 1
0
 def test_different_original_keys(self):
     """when setting headers using 2 different original keys it wouldn't be uniqued"""
     d = HTTPHeaders()
     d['Content-Type'] = "application/json"
     d['content-type'] = "text/plain"
     self.assertEqual(1, len(d))
     self.assertEqual("text/plain", d["CONTENT-TYPE"])
Exemplo n.º 2
0
    def test_iteration(self):
        hs = HTTPHeaders()
        hs['CONTENT_TYPE'] = "application/json"
        hs['CONTENT-LENGTH'] = "1234"
        hs['FOO-bAR'] = "che"
        for k in hs.keys():
            self.assertRegex(k, r"^[A-Z][a-z]+(?:\-[A-Z][a-z]+)*$")
            self.assertTrue(k in hs)

        for k, v in hs.items():
            self.assertRegex(k, r"^[A-Z][a-z]+(?:\-[A-Z][a-z]+)*$")
            self.assertEqual(hs[k], v)

        for k in hs:
            self.assertRegex(k, r"^[A-Z][a-z]+(?:\-[A-Z][a-z]+)*$")
            self.assertTrue(k in hs)
Exemplo n.º 3
0
    def test___init__(self):
        d = {"foo-bar": "1"}
        hs = HTTPHeaders(d)
        self.assertEqual("1", hs["foo-bar"])
        self.assertEqual(1, len(hs))

        d = [("foo-bar", "1")]
        hs = HTTPHeaders(d)
        self.assertEqual("1", hs["foo-bar"])
        self.assertEqual(1, len(hs))

        d = [("foo-bar", "1")]
        hs = HTTPHeaders(d, bar_foo="2")
        self.assertEqual("1", hs["foo-bar"])
        self.assertEqual("2", hs["bar-foo"])
        self.assertEqual(2, len(hs))
Exemplo n.º 4
0
 def test_midbody_capital_letter(self):
     """Previously, before June 2019, our headers didn't handle WebSocket correctly
     instead lowercasing the S to Websocket"""
     d = HTTPHeaders()
     d["Sec-WebSocket-Key"] = "foobar"
     self.assertTrue("Sec-Websocket-Key" in d)
     d2 = dict(d)
     self.assertFalse("Sec-Websocket-Key" in d2)
     self.assertTrue("Sec-WebSocket-Key" in d2)
Exemplo n.º 5
0
    def test_normalization(self):

        keys = ["Content-Type", "content-type", "content_type", "CONTENT_TYPE"]

        v = "foo"
        d = {"CONTENT_TYPE": v, "CONTENT_LENGTH": 1234}
        headers = HTTPHeaders(d)

        for k in keys:
            self.assertEqual(v, headers["Content-Type"])

        headers = HTTPHeaders()
        headers["CONTENT_TYPE"] = v

        for k in keys:
            self.assertEqual(v, headers["Content-Type"])

        #with self.assertRaises(KeyError):
        #    headers["foo-bar"]

        for k in keys:
            self.assertTrue(k in headers)
Exemplo n.º 6
0
    def test_pop(self):
        d = HTTPHeaders()
        d['FOO'] = 1
        r = d.pop('foo')
        self.assertEqual("1", r)

        with self.assertRaises(KeyError):
            d.pop('foo')

        with self.assertRaises(KeyError):
            d.pop('FOO')
Exemplo n.º 7
0
 def test_lifecycle(self):
     d = HTTPHeaders()
     d["foo-bar"] = 1
     self.assertEqual("1", d["Foo-Bar"])
     self.assertEqual("1", d["fOO-bAr"])
     self.assertEqual("1", d["fOO_bAr"])
Exemplo n.º 8
0
 def test_bytes(self):
     d = HTTPHeaders()
     name = testdata.get_unicode()
     val = ByteString(testdata.get_unicode())
     d[name] = val
     self.assertEqual(d[name], String(val))
Exemplo n.º 9
0
 def test_update(self):
     h = HTTPHeaders()
     h["foo"] = "1"
     self.assertEqual("1", h["foo"])
     h.update({"foo": "2"})
     self.assertEqual("2", h["foo"])