~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/test/test_xmlrpc.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-10-03 12:03:05 UTC
  • mto: (10.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20091003120305-hij6yssh0figh590
Tags: upstream-2.6.3
ImportĀ upstreamĀ versionĀ 2.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
583
583
        self.cgi = None
584
584
 
585
585
    def test_cgi_get(self):
586
 
        os.environ['REQUEST_METHOD'] = 'GET'
587
 
        # if the method is GET and no request_text is given, it runs handle_get
588
 
        # get sysout output
589
 
        tmp = sys.stdout
590
 
        sys.stdout = open(test_support.TESTFN, "w")
591
 
        self.cgi.handle_request()
592
 
        sys.stdout.close()
593
 
        sys.stdout = tmp
594
 
 
595
 
        # parse Status header
596
 
        handle = open(test_support.TESTFN, "r").read()
597
 
        status = handle.split()[1]
598
 
        message = ' '.join(handle.split()[2:4])
599
 
 
600
 
        self.assertEqual(status, '400')
601
 
        self.assertEqual(message, 'Bad Request')
602
 
 
603
 
        os.remove(test_support.TESTFN)
604
 
        os.environ['REQUEST_METHOD'] = ''
 
586
        with test_support.EnvironmentVarGuard() as env:
 
587
            env.set('REQUEST_METHOD', 'GET')
 
588
            # if the method is GET and no request_text is given, it runs handle_get
 
589
            # get sysout output
 
590
            tmp = sys.stdout
 
591
            sys.stdout = open(test_support.TESTFN, "w")
 
592
            self.cgi.handle_request()
 
593
            sys.stdout.close()
 
594
            sys.stdout = tmp
 
595
 
 
596
            # parse Status header
 
597
            handle = open(test_support.TESTFN, "r").read()
 
598
            status = handle.split()[1]
 
599
            message = ' '.join(handle.split()[2:4])
 
600
 
 
601
            self.assertEqual(status, '400')
 
602
            self.assertEqual(message, 'Bad Request')
 
603
 
 
604
            os.remove(test_support.TESTFN)
605
605
 
606
606
    def test_cgi_xmlrpc_response(self):
607
607
        data = """<?xml version='1.0'?>
624
624
        sys.stdin = open("xmldata.txt", "r")
625
625
        sys.stdout = open(test_support.TESTFN, "w")
626
626
 
627
 
        os.environ['CONTENT_LENGTH'] = str(len(data))
628
 
        try:
 
627
        with test_support.EnvironmentVarGuard() as env:
 
628
            env.set('CONTENT_LENGTH', str(len(data)))
629
629
            self.cgi.handle_request()
630
 
        finally:
631
 
            del os.environ['CONTENT_LENGTH']
632
630
 
633
631
        sys.stdin.close()
634
632
        sys.stdout.close()