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_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'))
    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')))