Пример #1
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
Пример #2
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
Пример #3
0
 def test_copy(self):
     h1 = Headers({"header1": ["value1", "value2"]})
     h2 = copy.copy(h1)
     self.assertEqual(h1, h2)
     self.assertEqual(h1.getlist("header1"), h2.getlist("header1"))
     assert h1.getlist("header1") is not h2.getlist("header1")
     assert isinstance(h2, Headers)
Пример #4
0
 def test_copy(self):
     h1 = Headers({'header1': ['value1', 'value2']})
     h2 = copy.copy(h1)
     self.assertEqual(h1, h2)
     self.assertEqual(h1.getlist('header1'), h2.getlist('header1'))
     assert h1.getlist('header1') is not h2.getlist('header1')
     assert isinstance(h2, Headers)
Пример #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
Пример #6
0
 def test_copy(self):
     h1 = Headers({'header1': ['value1', 'value2']})
     h2 = copy.copy(h1)
     self.assertEqual(h1, h2)
     self.assertEqual(h1.getlist('header1'), h2.getlist('header1'))
     assert h1.getlist('header1') is not h2.getlist('header1')
     assert isinstance(h2, Headers)
Пример #7
0
 def test_update(self):
     h = Headers()
     h.update({
         'Content-Type': 'text/html',
         'X-Forwarded-For': ['ip1', 'ip2']
     })
     self.assertEqual(h.getlist('Content-Type'), ['text/html'])
     self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1', 'ip2'])
Пример #8
0
 def test_update(self):
     h = Headers()
     h.update({
         "Content-Type": "text/html",
         "X-Forwarded-For": ["ip1", "ip2"]
     })
     self.assertEqual(h.getlist("Content-Type"), [b"text/html"])
     self.assertEqual(h.getlist("X-Forwarded-For"), [b"ip1", b"ip2"])
Пример #9
0
    def test_appendlist(self):
        h1 = Headers({"header1": "value1"})
        h1.appendlist("header1", "value3")
        self.assertEqual(h1.getlist("header1"), [b"value1", b"value3"])

        h1 = Headers()
        h1.appendlist("header1", "value1")
        h1.appendlist("header1", "value3")
        self.assertEqual(h1.getlist("header1"), [b"value1", b"value3"])
Пример #10
0
    def test_appendlist(self):
        h1 = Headers({'header1': 'value1'})
        h1.appendlist('header1', 'value3')
        self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])

        h1 = Headers()
        h1.appendlist('header1', 'value1')
        h1.appendlist('header1', 'value3')
        self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])
Пример #11
0
    def test_appendlist(self):
        h1 = Headers({'header1': 'value1'})
        h1.appendlist('header1', 'value3')
        self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])

        h1 = Headers()
        h1.appendlist('header1', 'value1')
        h1.appendlist('header1', 'value3')
        self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])
Пример #12
0
 def test_int_value(self):
     h1 = Headers({'hey': 5})
     h1['foo'] = 1
     h1.setdefault('bar', 2)
     h1.setlist('buz', [1, 'dos', 3])
     self.assertEqual(h1.getlist('foo'), [b'1'])
     self.assertEqual(h1.getlist('bar'), [b'2'])
     self.assertEqual(h1.getlist('buz'), [b'1', b'dos', b'3'])
     self.assertEqual(h1.getlist('hey'), [b'5'])
Пример #13
0
 def test_int_value(self):
     h1 = Headers({"hey": 5})
     h1["foo"] = 1
     h1.setdefault("bar", 2)
     h1.setlist("buz", [1, "dos", 3])
     self.assertEqual(h1.getlist("foo"), [b"1"])
     self.assertEqual(h1.getlist("bar"), [b"2"])
     self.assertEqual(h1.getlist("buz"), [b"1", b"dos", b"3"])
     self.assertEqual(h1.getlist("hey"), [b"5"])
Пример #14
0
 def test_int_value(self):
     h1 = Headers({'hey': 5})
     h1['foo'] = 1
     h1.setdefault('bar', 2)
     h1.setlist('buz', [1, 'dos', 3])
     self.assertEqual(h1.getlist('foo'), [b'1'])
     self.assertEqual(h1.getlist('bar'), [b'2'])
     self.assertEqual(h1.getlist('buz'), [b'1', b'dos', b'3'])
     self.assertEqual(h1.getlist('hey'), [b'5'])
Пример #15
0
    def test_setdefault(self):
        h = Headers()
        hlist = ["ip1", "ip2"]
        olist = h.setdefault("X-Forwarded-For", hlist)
        assert h.getlist("X-Forwarded-For") is not hlist
        assert h.getlist("X-Forwarded-For") is olist

        h = Headers()
        olist = h.setdefault("X-Forwarded-For", "ip1")
        self.assertEqual(h.getlist("X-Forwarded-For"), [b"ip1"])
        assert h.getlist("X-Forwarded-For") is olist
Пример #16
0
    def test_setdefault(self):
        h = Headers()
        hlist = ['ip1', 'ip2']
        olist = h.setdefault('X-Forwarded-For', hlist)
        assert h.getlist('X-Forwarded-For') is not hlist
        assert h.getlist('X-Forwarded-For') is olist

        h = Headers()
        olist = h.setdefault('X-Forwarded-For', 'ip1')
        self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1'])
        assert h.getlist('X-Forwarded-For') is olist
Пример #17
0
    def test_setdefault(self):
        h = Headers()
        hlist = ['ip1', 'ip2']
        olist = h.setdefault('X-Forwarded-For', hlist)
        assert h.getlist('X-Forwarded-For') is not hlist
        assert h.getlist('X-Forwarded-For') is olist

        h = Headers()
        olist = h.setdefault('X-Forwarded-For', 'ip1')
        self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1'])
        assert h.getlist('X-Forwarded-For') is olist
Пример #18
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'])
Пример #19
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"],
        )
Пример #20
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"), [])
Пример #21
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'), [])
Пример #22
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'), [])
Пример #23
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"])
Пример #24
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"])
Пример #25
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'])
Пример #26
0
 def test_setlistdefault(self):
     h1 = Headers({"header1": "value1"})
     h1.setlistdefault("header1", ["value2", "value3"])
     h1.setlistdefault("header2", ["value2", "value3"])
     self.assertEqual(h1.getlist("header1"), [b"value1"])
     self.assertEqual(h1.getlist("header2"), [b"value2", b"value3"])
Пример #27
0
 def test_setlistdefault(self):
     h1 = Headers({'header1': 'value1'})
     h1.setlistdefault('header1', ['value2', 'value3'])
     h1.setlistdefault('header2', ['value2', 'value3'])
     self.assertEqual(h1.getlist('header1'), ['value1'])
     self.assertEqual(h1.getlist('header2'), ['value2', 'value3'])
Пример #28
0
 def test_setlistdefault(self):
     h1 = Headers({'header1': 'value1'})
     h1.setlistdefault('header1', ['value2', 'value3'])
     h1.setlistdefault('header2', ['value2', 'value3'])
     self.assertEqual(h1.getlist('header1'), ['value1'])
     self.assertEqual(h1.getlist('header2'), ['value2', 'value3'])
 def _test(response):
     import json
     headers = Headers(json.loads(response.text)['headers'])
     contentlengths = headers.getlist('Content-Length')
     self.assertEqual(len(contentlengths), 1)
     self.assertEqual(contentlengths, [b"0"])
Пример #30
0
 def _test(response):
     import json
     headers = Headers(json.loads(response.text)['headers'])
     contentlengths = headers.getlist('Content-Length')
     self.assertEqual(len(contentlengths), 1)
     self.assertEqual(contentlengths, [b"0"])
Пример #31
0
 def test_update(self):
     h = Headers()
     h.update(
         {'Content-Type': 'text/html', 'X-Forwarded-For': ['ip1', 'ip2']})
     self.assertEqual(h.getlist('Content-Type'), ['text/html'])
     self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1', 'ip2'])
Пример #32
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'])