Esempio n. 1
0
    def test_basics(self):
        h = Headers({'Content-Type': 'text/html', 'Content-Length': 1234})
        self.assertIn('Content-Type', h)
        self.assertIn('Content-Length', h)

        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'])
    def test_basics(self):
        h = Headers({'Content-Type': 'text/html', 'Content-Length': 1234})
        self.assertIn('Content-Type', h)
        self.assertIn('Content-Length', h)

        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'])
Esempio n. 3
0
    def test_multivalue(self):
        h = Headers()

        h['X-Forwarded-For'] = hlist = ['ip1', 'ip2']
        self.assertEqual(h['X-Forwarded-For'], 'ip2')
        self.assertEqual(h.get('X-Forwarded-For'), 'ip2')
        self.assertEqual(h.getlist('X-Forwarded-For'), hlist)
        self.assertIsNot(h.getlist('X-Forwarded-For'), hlist)
    def test_multivalue(self):
        h = Headers()

        h['X-Forwarded-For'] = hlist = ['ip1', 'ip2']
        self.assertEqual(h['X-Forwarded-For'], 'ip2')
        self.assertEqual(h.get('X-Forwarded-For'), 'ip2')
        self.assertEqual(h.getlist('X-Forwarded-For'), hlist)
        self.assertIsNot(h.getlist('X-Forwarded-For'), hlist)
Esempio n. 5
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'])
 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'])