def test_unicode(self):
        # test adding unicode values in all the different ways
        h = HttpHeaders([('a', 'ሴ')])
        self.assertEqual('ሴ', h.get('a'))

        h.set('b', '𦉘')
        self.assertEqual('𦉘', h.get('b'))

        h.add('c', '👁👄👁')
        self.assertEqual('👁👄👁', h.get('c'))

        h.add_pairs([('d', 'ⓤţḟ⁻❽')])
        self.assertEqual('ⓤţḟ⁻❽', h.get('d'))
Ejemplo n.º 2
0
 def _validate_successful_get_response(self, put_object):
     self.assertEqual(self.response_status_code, 200,
                      "status code is not 200")
     headers = HttpHeaders(self.response_headers)
     self.assertIsNone(headers.get("Content-Range"))
     body_length = headers.get("Content-Length")
     if not put_object:
         self.assertIsNotNone(body_length,
                              "Content-Length is missing from headers")
     if body_length:
         self.assertEqual(
             int(body_length), self.received_body_len,
             "Received body length does not match the Content-Length header"
         )
    def test_remove(self):
        h = HttpHeaders()

        self.assertRaises(KeyError, h.remove, 'Non-Existent')

        h.add('Host', 'example.org')
        h.remove('Host')
        self.assertIsNone(h.get('Host'))
 def test_get_is_case_insensitive(self):
     h = HttpHeaders()
     h.set('Cookie', 'a=1')
     h.add_pairs([('cookie', 'b=2'), ('COOKIE', 'c=3')])
     h.add(u'CoOkIe', 'd=4')  # note: unicode
     self.assertEqual('a=1', h.get(u'COOKIE'))
     self.assertEqual(['a=1', 'b=2', 'c=3', 'd=4'],
                      list(h.get_values('Cookie')))
 def test_add_pairs(self):
     h = HttpHeaders()
     h.add_pairs([
         ('Host', 'example.org'),
         ('Cookie', 'a=1'),
         ('Cookie', 'b=2'),
     ])
     self.assertEqual('example.org', h.get('Host'))
     self.assertEqual(['a=1', 'b=2'], list(h.get_values('Cookie')))
    def test_remove_value(self):
        h = HttpHeaders()

        self.assertRaises(ValueError, h.remove_value, 'Non-Existent', 'Nope')

        # header with 1 value
        h.add('Host', 'example.org')
        self.assertRaises(ValueError, h.remove_value, 'Host', 'wrong-value')
        h.remove_value('Host', 'example.org')
        self.assertIsNone(h.get('Host'))

        # pluck out a duplicate value [1,2,2] -> [1,2]
        h.add_pairs([('Dupes', '1'), ('DUPES', '2'), ('dupes', '2')])
        h.remove_value('Dupes', '2')
        self.assertEqual(['1', '2'], list(h.get_values('Dupes')))
 def test_get_none(self):
     h = HttpHeaders()
     self.assertIsNone(h.get('Non-Existent'))
     self.assertEqual('Banana', h.get('Non-Existent', 'Banana'))
     self.assertEqual([], list(h.get_values('Non-Existent')))
 def test_add_multi_values(self):
     h = HttpHeaders()
     h.add('Cookie', 'a=1')
     h.add('Cookie', 'b=2')
     self.assertEqual('a=1', h.get('Cookie'))
     self.assertEqual(['a=1', 'b=2'], list(h.get_values('Cookie')))
 def test_add(self):
     h = HttpHeaders()
     h.add('Host', 'example.org')
     self.assertEqual('example.org', h.get('Host'))
     self.assertEqual(['example.org'], list(h.get_values('Host')))