Ejemplo n.º 1
0
 def test_delete_header(self):
     d = HeaderCollection()
     d['Content-Type'] = 'test'
     d['Test'] = 'test'
     assert d.get('Content-Type')
     del d['Content-Type']
     assert not d.get('Content-Type')
Ejemplo n.º 2
0
 def test_add_header(self):
     d = HeaderCollection()
     d.add('CONTENT_TYPE', 'text/html')
     d.add('HOST', '127.0.0.1')
     assert d.get('Content-Type') == 'text/html'
     assert d.get('CONTENT_TYPE') == 'text/html'
Ejemplo n.º 3
0
 def test_get_header_doesnt_exist(self):
     d = HeaderCollection()
     assert not d.get('test', option='charset', default=None)
Ejemplo n.º 4
0
 def test_set_header(self):
     d = HeaderCollection({'test': 'testing'})
     d.set('test', 'test')
     assert d['HTTP_TEST'] == 'test'
Ejemplo n.º 5
0
 def test_set_header_immutable(self):
     d = HeaderCollection.from_environ({'CONTENT_TYPE': 'text/html'})
     with raises(TypeError):
         d['test'] = 'test'
     with raises(TypeError):
         del d['CONTENT_TYPE']
Ejemplo n.º 6
0
 def test_tuple_pairs_multiple(self):
     d = HeaderCollection()
     d.add('Content-Type', 'text/html')
     d.add('Content-Type', 'text/xml')
     assert ('Content-Type', 'text/html') in d()
     assert ('Content-Type', 'text/xml') in d()
Ejemplo n.º 7
0
 def test_tuple_pairs(self):
     d = HeaderCollection.from_environ({'CONTENT_TYPE': 'text/html'})
     assert d() == [('Content-Type', 'text/html')]
Ejemplo n.º 8
0
 def test_add_overwrite_header(self):
     d = HeaderCollection()
     d.add('CONTENT_TYPE', 'text/html', charset='utf-8')
     assert len(d) == 1
     d.add('CONTENT_TYPE', 'text/plain', charset='utf-8', replace=True)
     assert len(d) == 1
Ejemplo n.º 9
0
 def test_add_option(self):
     d = HeaderCollection()
     d.add('CONTENT_TYPE', 'text/html', charset='utf-8')
     assert d.get('Content-Type') == 'text/html; charset=utf-8'
     assert d.get_option('Content-Type', 'charset') == 'utf-8'
     assert d.get_option('Content-Type', 'random', 'test') == 'test'
Ejemplo n.º 10
0
 def test_get_header_doesnt_exist(self):
     d = HeaderCollection()
     assert not d.get('test', option='charset', default=None)
     d = HeaderCollection({'CONTENT_TYPE': ''})
     assert d.get('Content-Type', default='utf-8') == 'utf-8'
     assert not d.get('Content-Type')
Ejemplo n.º 11
0
 def headers(self):
     return HeaderCollection.from_environ(self.environ)