Skip to content

Commit 0a3bbe6

Browse files
committed
Added test for nesting _additional_headers context.
1 parent 3dd69f9 commit 0a3bbe6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,30 @@ def test_should_restore_global_headers(self):
570570
self.assertTrue('x-test' in headers)
571571
self.assertEqual(headers['x-test'], 'Global')
572572

573+
def test_should_allow_to_nest_additional_header_blocks(self):
574+
# given
575+
client = Server('http://localhost:%d' % self.port, verbose=1)
576+
577+
# when
578+
with client._additional_headers({'X-Level-1' : '1'}) as cl_level1:
579+
with self.captured_headers() as headers1:
580+
response = cl_level1.ping()
581+
self.assertTrue(response)
582+
583+
with cl_level1._additional_headers({'X-Level-2' : '2'}) as cl:
584+
with self.captured_headers() as headers2:
585+
response = cl.ping()
586+
self.assertTrue(response)
587+
588+
# then
589+
self.assertTrue('x-level-1' in headers1)
590+
self.assertEqual(headers1['x-level-1'], '1')
591+
592+
self.assertTrue('x-level-1' in headers2)
593+
self.assertEqual(headers1['x-level-1'], '1')
594+
self.assertTrue('x-level-2' in headers2)
595+
self.assertEqual(headers2['x-level-2'], '2')
596+
573597
""" Test Methods """
574598
def subtract(minuend, subtrahend):
575599
""" Using the keywords from the JSON-RPC v2 doc """

0 commit comments

Comments
 (0)