def test_should_override_global_headers(self): # given client = Server('http://localhost:{0}'.format(self.port), verbose=1, headers={'X-Test' : 'Global'}) # when with self.captured_headers() as headers: with client._additional_headers({'X-Test' : 'Method'}) as cl: response = cl.ping() self.assertTrue(response) # then self.assertTrue('x-test' in headers) self.assertEqual(headers['x-test'], 'Method')
def test_should_add_custom_headers_to_methods(self): # given client = Server('http://localhost:{0}'.format(self.port), verbose=1) # when with self.captured_headers() as headers: with client._additional_headers({'X-Method' : 'Method'}) as cl: response = cl.ping() self.assertTrue(response) # then self.assertTrue('x-method' in headers) self.assertEqual(headers['x-method'], 'Method')
def test_should_allow_to_nest_additional_header_blocks(self): # given client = Server('http://localhost:%d' % self.port, verbose=1) # when with client._additional_headers({'X-Level-1' : '1'}) as cl_level1: with self.captured_headers() as headers1: response = cl_level1.ping() self.assertTrue(response) with cl_level1._additional_headers({'X-Level-2' : '2'}) as cl: with self.captured_headers() as headers2: response = cl.ping() self.assertTrue(response) # then self.assertTrue('x-level-1' in headers1) self.assertEqual(headers1['x-level-1'], '1') self.assertTrue('x-level-1' in headers2) self.assertEqual(headers1['x-level-1'], '1') self.assertTrue('x-level-2' in headers2) self.assertEqual(headers2['x-level-2'], '2')