mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merged revisions 71984 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r71984 | walter.doerwald | 2009-04-26 22:51:44 +0200 (So, 26 Apr 2009) | 2 lines Use test.test_support.EnvironmentVarGuard where tests change environment vars. ........
This commit is contained in:
parent
4af362905c
commit
b525e18500
6 changed files with 36 additions and 64 deletions
|
@ -571,25 +571,25 @@ class CGIHandlerTestCase(unittest.TestCase):
|
|||
self.cgi = None
|
||||
|
||||
def test_cgi_get(self):
|
||||
os.environ['REQUEST_METHOD'] = 'GET'
|
||||
# if the method is GET and no request_text is given, it runs handle_get
|
||||
# get sysout output
|
||||
tmp = sys.stdout
|
||||
sys.stdout = open(support.TESTFN, "w")
|
||||
self.cgi.handle_request()
|
||||
sys.stdout.close()
|
||||
sys.stdout = tmp
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
env.set('REQUEST_METHOD', 'GET')
|
||||
# if the method is GET and no request_text is given, it runs handle_get
|
||||
# get sysout output
|
||||
tmp = sys.stdout
|
||||
sys.stdout = open(support.TESTFN, "w")
|
||||
self.cgi.handle_request()
|
||||
sys.stdout.close()
|
||||
sys.stdout = tmp
|
||||
|
||||
# parse Status header
|
||||
handle = open(support.TESTFN, "r").read()
|
||||
status = handle.split()[1]
|
||||
message = ' '.join(handle.split()[2:4])
|
||||
# parse Status header
|
||||
handle = open(support.TESTFN, "r").read()
|
||||
status = handle.split()[1]
|
||||
message = ' '.join(handle.split()[2:4])
|
||||
|
||||
self.assertEqual(status, '400')
|
||||
self.assertEqual(message, 'Bad Request')
|
||||
self.assertEqual(status, '400')
|
||||
self.assertEqual(message, 'Bad Request')
|
||||
|
||||
os.remove(support.TESTFN)
|
||||
os.environ['REQUEST_METHOD'] = ''
|
||||
os.remove(support.TESTFN)
|
||||
|
||||
def test_cgi_xmlrpc_response(self):
|
||||
data = """<?xml version='1.0'?>
|
||||
|
@ -612,11 +612,9 @@ class CGIHandlerTestCase(unittest.TestCase):
|
|||
sys.stdin = open("xmldata.txt", "r")
|
||||
sys.stdout = open(support.TESTFN, "w")
|
||||
|
||||
os.environ['CONTENT_LENGTH'] = str(len(data))
|
||||
try:
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
env.set('CONTENT_LENGTH', str(len(data)))
|
||||
self.cgi.handle_request()
|
||||
finally:
|
||||
del os.environ['CONTENT_LENGTH']
|
||||
|
||||
sys.stdin.close()
|
||||
sys.stdout.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue