annotate Lib/test/test_xmlrpc.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 0c02f30b2538
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
1 import base64
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
2 import datetime
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
3 import sys
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
4 import time
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
5 import unittest
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
6 import xmlrpclib
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
7 import SimpleXMLRPCServer
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
8 import mimetools
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
9 import httplib
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
10 import socket
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
11 import StringIO
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
12 import os
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
13 import re
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 20571
diff changeset
14 from test import test_support
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
15
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
16 try:
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
17 import threading
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
18 except ImportError:
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
19 threading = None
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
20
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
21 try:
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
22 unicode
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
23 except NameError:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
24 have_unicode = False
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
25 else:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
26 have_unicode = True
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
27
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
28 alist = [{'astring': 'foo@bar.baz.spam',
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
29 'afloat': 7283.43,
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
30 'anint': 2**20,
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
31 'ashortlong': 2L,
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
32 'anotherlist': ['.zyx.41'],
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
33 'abase64': xmlrpclib.Binary("my dog has fleas"),
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
34 'boolean': xmlrpclib.False,
32248
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
35 'unicode': u'\u4000\u6000\u8000',
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
36 u'ukey\u4000': 'regular value',
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
37 'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
38 'datetime2': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
39 (2005, 02, 10, 11, 41, 23, 0, 1, -1)),
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
40 'datetime3': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
41 datetime.datetime(2005, 02, 10, 11, 41, 23)),
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
42 }]
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
43
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
44 class XMLRPCTestCase(unittest.TestCase):
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
45
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
46 def test_dump_load(self):
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
47 self.assertEqual(alist,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
48 xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0])
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
49
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
50 def test_dump_bare_datetime(self):
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
51 # This checks that an unwrapped datetime.date object can be handled
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
52 # by the marshalling code. This can't be done via test_dump_load()
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
53 # since with use_datetime set to 1 the unmarshaller would create
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
54 # datetime objects for the 'datetime[123]' keys as well
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
55 dt = datetime.datetime(2005, 02, 10, 11, 41, 23)
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
56 s = xmlrpclib.dumps((dt,))
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
57 (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
58 self.assertEqual(newdt, dt)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
59 self.assertEqual(m, None)
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
60
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
61 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
62 self.assertEqual(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
63
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
64 def test_datetime_before_1900(self):
46508
fdd5a0198769 Comment typo
Andrew M. Kuchling <amk@amk.ca>
parents: 46471
diff changeset
65 # same as before but with a date before 1900
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
66 dt = datetime.datetime(1, 02, 10, 11, 41, 23)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
67 s = xmlrpclib.dumps((dt,))
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
68 (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
69 self.assertEqual(newdt, dt)
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
70 self.assertEqual(m, None)
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
71
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
72 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
73 self.assertEqual(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
74
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
75 def test_cmp_datetime_DateTime(self):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
76 now = datetime.datetime.now()
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
77 dt = xmlrpclib.DateTime(now.timetuple())
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54928
diff changeset
78 self.assertTrue(dt == now)
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54928
diff changeset
79 self.assertTrue(now == dt)
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
80 then = now + datetime.timedelta(seconds=4)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54928
diff changeset
81 self.assertTrue(then >= dt)
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54928
diff changeset
82 self.assertTrue(dt < then)
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
83
35984
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
84 def test_bug_1164912 (self):
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
85 d = xmlrpclib.DateTime()
36121
686306a67e9b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 35984
diff changeset
86 ((new_d,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((d,),
35984
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
87 methodresponse=True))
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
88 self.assertIsInstance(new_d.value, str)
35984
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
89
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
90 # Check that the output of dumps() is still an 8-bit string
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
91 s = xmlrpclib.dumps((new_d,), methodresponse=True)
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
92 self.assertIsInstance(s, str)
35984
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
93
40360
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
94 def test_newstyle_class(self):
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
95 class T(object):
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
96 pass
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
97 t = T()
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
98 t.x = 100
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
99 t.y = "Hello"
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
100 ((t2,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((t,)))
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
101 self.assertEqual(t2, t.__dict__)
40360
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
102
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
103 def test_dump_big_long(self):
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
104 self.assertRaises(OverflowError, xmlrpclib.dumps, (2L**99,))
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
105
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
106 def test_dump_bad_dict(self):
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
107 self.assertRaises(TypeError, xmlrpclib.dumps, ({(1,2,3): 1},))
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
108
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
109 def test_dump_recursive_seq(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
110 l = [1,2,3]
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
111 t = [3,4,5,l]
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
112 l.append(t)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
113 self.assertRaises(TypeError, xmlrpclib.dumps, (l,))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
114
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
115 def test_dump_recursive_dict(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
116 d = {'1':1, '2':1}
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
117 t = {'3':3, 'd':d}
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
118 d['t'] = t
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
119 self.assertRaises(TypeError, xmlrpclib.dumps, (d,))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
120
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
121 def test_dump_big_int(self):
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
122 if sys.maxint > 2L**31-1:
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
123 self.assertRaises(OverflowError, xmlrpclib.dumps,
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
124 (int(2L**34),))
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
125
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
126 xmlrpclib.dumps((xmlrpclib.MAXINT, xmlrpclib.MININT))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
127 self.assertRaises(OverflowError, xmlrpclib.dumps, (xmlrpclib.MAXINT+1,))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
128 self.assertRaises(OverflowError, xmlrpclib.dumps, (xmlrpclib.MININT-1,))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
129
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
130 def dummy_write(s):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
131 pass
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
132
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
133 m = xmlrpclib.Marshaller()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
134 m.dump_int(xmlrpclib.MAXINT, dummy_write)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
135 m.dump_int(xmlrpclib.MININT, dummy_write)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
136 self.assertRaises(OverflowError, m.dump_int, xmlrpclib.MAXINT+1, dummy_write)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
137 self.assertRaises(OverflowError, m.dump_int, xmlrpclib.MININT-1, dummy_write)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
138
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
139
28809
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
140 def test_dump_none(self):
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
141 value = alist + [None]
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
142 arg1 = (alist + [None],)
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
143 strg = xmlrpclib.dumps(arg1, allow_none=True)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
144 self.assertEqual(value,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
145 xmlrpclib.loads(strg)[0][0])
28809
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
146 self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
147
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
148 def test_default_encoding_issues(self):
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
149 # SF bug #1115989: wrong decoding in '_stringify'
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
150 utf8 = """<?xml version='1.0' encoding='iso-8859-1'?>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
151 <params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
152 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
153 <string>abc \x95</string>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
154 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
155 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
156 <struct>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
157 <member>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
158 <name>def \x96</name>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
159 <value><string>ghi \x97</string></value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
160 </member>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
161 </struct>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
162 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
163 </params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
164 """
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
165
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
166 # sys.setdefaultencoding() normally doesn't exist after site.py is
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
167 # loaded. Import a temporary fresh copy to get access to it
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
168 # but then restore the original copy to avoid messing with
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
169 # other potentially modified sys module attributes
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
170 old_encoding = sys.getdefaultencoding()
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
171 with test_support.CleanImport('sys'):
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
172 import sys as temp_sys
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
173 temp_sys.setdefaultencoding("iso-8859-1")
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
174 try:
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
175 (s, d), m = xmlrpclib.loads(utf8)
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
176 finally:
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
177 temp_sys.setdefaultencoding(old_encoding)
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
178
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
179 items = d.items()
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
180 if have_unicode:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
181 self.assertEqual(s, u"abc \x95")
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
182 self.assertIsInstance(s, unicode)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
183 self.assertEqual(items, [(u"def \x96", u"ghi \x97")])
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
184 self.assertIsInstance(items[0][0], unicode)
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
185 self.assertIsInstance(items[0][1], unicode)
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
186 else:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
187 self.assertEqual(s, "abc \xc2\x95")
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
188 self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")])
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
189
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
190
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
191 class HelperTestCase(unittest.TestCase):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
192 def test_escape(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
193 self.assertEqual(xmlrpclib.escape("a&b"), "a&amp;b")
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
194 self.assertEqual(xmlrpclib.escape("a<b"), "a&lt;b")
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
195 self.assertEqual(xmlrpclib.escape("a>b"), "a&gt;b")
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
196
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
197 class FaultTestCase(unittest.TestCase):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
198 def test_repr(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
199 f = xmlrpclib.Fault(42, 'Test Fault')
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
200 self.assertEqual(repr(f), "<Fault 42: 'Test Fault'>")
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
201 self.assertEqual(repr(f), str(f))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
202
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
203 def test_dump_fault(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
204 f = xmlrpclib.Fault(42, 'Test Fault')
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
205 s = xmlrpclib.dumps((f,))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
206 (newf,), m = xmlrpclib.loads(s)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
207 self.assertEqual(newf, {'faultCode': 42, 'faultString': 'Test Fault'})
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
208 self.assertEqual(m, None)
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
209
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
210 s = xmlrpclib.Marshaller().dumps(f)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
211 self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
212
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
213
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
214 class DateTimeTestCase(unittest.TestCase):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
215 def test_default(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
216 t = xmlrpclib.DateTime()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
217
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
218 def test_time(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
219 d = 1181399930.036952
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
220 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
221 self.assertEqual(str(t), time.strftime("%Y%m%dT%H:%M:%S", time.localtime(d)))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
222
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
223 def test_time_tuple(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
224 d = (2007,6,9,10,38,50,5,160,0)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
225 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
226 self.assertEqual(str(t), '20070609T10:38:50')
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
227
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
228 def test_time_struct(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
229 d = time.localtime(1181399930.036952)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
230 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
231 self.assertEqual(str(t), time.strftime("%Y%m%dT%H:%M:%S", d))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
232
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
233 def test_datetime_datetime(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
234 d = datetime.datetime(2007,1,2,3,4,5)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
235 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
236 self.assertEqual(str(t), '20070102T03:04:05')
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
237
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
238 def test_repr(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
239 d = datetime.datetime(2007,1,2,3,4,5)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
240 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
241 val ="<DateTime '20070102T03:04:05' at %x>" % id(t)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
242 self.assertEqual(repr(t), val)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
243
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
244 def test_decode(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
245 d = ' 20070908T07:11:13 '
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
246 t1 = xmlrpclib.DateTime()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
247 t1.decode(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
248 tref = xmlrpclib.DateTime(datetime.datetime(2007,9,8,7,11,13))
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
249 self.assertEqual(t1, tref)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
250
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
251 t2 = xmlrpclib._datetime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
252 self.assertEqual(t1, tref)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
253
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
254 class BinaryTestCase(unittest.TestCase):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
255 def test_default(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
256 t = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
257 self.assertEqual(str(t), '')
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
258
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
259 def test_string(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
260 d = '\x01\x02\x03abc123\xff\xfe'
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
261 t = xmlrpclib.Binary(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
262 self.assertEqual(str(t), d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
263
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
264 def test_decode(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
265 d = '\x01\x02\x03abc123\xff\xfe'
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
266 de = base64.encodestring(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
267 t1 = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
268 t1.decode(de)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
269 self.assertEqual(str(t1), d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
270
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
271 t2 = xmlrpclib._binary(de)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
272 self.assertEqual(str(t2), d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
273
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
274
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
275 ADDR = PORT = URL = None
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
276
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
277 # The evt is set twice. First when the server is ready to serve.
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
278 # Second when the server has been shutdown. The user must clear
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
279 # the event after it has been set the first time to catch the second set.
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
280 def http_server(evt, numrequests, requestHandler=None):
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
281 class TestInstanceClass:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
282 def div(self, x, y):
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
283 return x // y
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
284
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
285 def _methodHelp(self, name):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
286 if name == 'div':
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
287 return 'This is the div function'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
288
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
289 def my_function():
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
290 '''This is my function'''
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
291 return True
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
292
46155
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
293 class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
294 def get_request(self):
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
295 # Ensure the socket is always non-blocking. On Linux, socket
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
296 # attributes are not inherited like they are on *BSD and Windows.
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
297 s, port = self.socket.accept()
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
298 s.setblocking(True)
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
299 return s, port
3103ea3df49d Bug 1503: Get the test to pass on OSX. This should make the test more
Neal Norwitz <nnorwitz@gmail.com>
parents: 46020
diff changeset
300
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
301 if not requestHandler:
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
302 requestHandler = SimpleXMLRPCServer.SimpleXMLRPCRequestHandler
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
303 serv = MyXMLRPCServer(("localhost", 0), requestHandler,
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
304 logRequests=False, bind_and_activate=False)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
305 try:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
306 serv.socket.settimeout(3)
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
307 serv.server_bind()
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
308 global ADDR, PORT, URL
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
309 ADDR, PORT = serv.socket.getsockname()
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
310 #connect to IP address directly. This avoids socket.create_connection()
72984
86e3943d0d5b Remove duplication.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72450
diff changeset
311 #trying to connect to "localhost" using all address families, which
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
312 #causes slowdown e.g. on vista which supports AF_INET6. The server listens
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
313 #on AF_INET only.
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
314 URL = "http://%s:%d"%(ADDR, PORT)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
315 serv.server_activate()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
316 serv.register_introspection_functions()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
317 serv.register_multicall_functions()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
318 serv.register_function(pow)
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
319 serv.register_function(lambda x,y: x+y, 'add')
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
320 serv.register_function(my_function)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
321 serv.register_instance(TestInstanceClass())
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
322 evt.set()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
323
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
324 # handle up to 'numrequests' requests
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
325 while numrequests > 0:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
326 serv.handle_request()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
327 numrequests -= 1
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
328
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
329 except socket.timeout:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
330 pass
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
331 finally:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
332 serv.socket.close()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
333 PORT = None
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
334 evt.set()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
335
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
336 def http_multi_server(evt, numrequests, requestHandler=None):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
337 class TestInstanceClass:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
338 def div(self, x, y):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
339 return x // y
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
340
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
341 def _methodHelp(self, name):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
342 if name == 'div':
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
343 return 'This is the div function'
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
344
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
345 def my_function():
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
346 '''This is my function'''
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
347 return True
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
348
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
349 class MyXMLRPCServer(SimpleXMLRPCServer.MultiPathXMLRPCServer):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
350 def get_request(self):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
351 # Ensure the socket is always non-blocking. On Linux, socket
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
352 # attributes are not inherited like they are on *BSD and Windows.
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
353 s, port = self.socket.accept()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
354 s.setblocking(True)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
355 return s, port
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
356
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
357 if not requestHandler:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
358 requestHandler = SimpleXMLRPCServer.SimpleXMLRPCRequestHandler
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
359 class MyRequestHandler(requestHandler):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
360 rpc_paths = []
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
361
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
362 serv = MyXMLRPCServer(("localhost", 0), MyRequestHandler,
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
363 logRequests=False, bind_and_activate=False)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
364 serv.socket.settimeout(3)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
365 serv.server_bind()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
366 try:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
367 global ADDR, PORT, URL
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
368 ADDR, PORT = serv.socket.getsockname()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
369 #connect to IP address directly. This avoids socket.create_connection()
72984
86e3943d0d5b Remove duplication.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72450
diff changeset
370 #trying to connect to "localhost" using all address families, which
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
371 #causes slowdown e.g. on vista which supports AF_INET6. The server listens
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
372 #on AF_INET only.
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
373 URL = "http://%s:%d"%(ADDR, PORT)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
374 serv.server_activate()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
375 paths = ["/foo", "/foo/bar"]
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
376 for path in paths:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
377 d = serv.add_dispatcher(path, SimpleXMLRPCServer.SimpleXMLRPCDispatcher())
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
378 d.register_introspection_functions()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
379 d.register_multicall_functions()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
380 serv.get_dispatcher(paths[0]).register_function(pow)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
381 serv.get_dispatcher(paths[1]).register_function(lambda x,y: x+y, 'add')
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
382 evt.set()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
383
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
384 # handle up to 'numrequests' requests
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
385 while numrequests > 0:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
386 serv.handle_request()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
387 numrequests -= 1
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
388
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
389 except socket.timeout:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
390 pass
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
391 finally:
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
392 serv.socket.close()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
393 PORT = None
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
394 evt.set()
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
395
44961
be44faed542d The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44958
diff changeset
396 # This function prevents errors like:
be44faed542d The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44958
diff changeset
397 # <ProtocolError for localhost:57527/RPC2: 500 Internal Server Error>
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
398 def is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
399 '''Returns True if the given ProtocolError is the product of a server-side
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
400 exception caused by the 'temporarily unavailable' response sometimes
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
401 given by operations on non-blocking sockets.'''
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
402
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
403 # sometimes we get a -1 error code and/or empty headers
45016
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
404 try:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
405 if e.errcode == -1 or e.headers is None:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
406 return True
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
407 exc_mess = e.headers.get('X-exception')
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
408 except AttributeError:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
409 # Ignore socket.errors here.
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
410 exc_mess = str(e)
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
411
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
412 if exc_mess and 'temporarily unavailable' in exc_mess.lower():
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
413 return True
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
414
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
415 return False
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
416
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
417 @unittest.skipUnless(threading, 'Threading required for this test.')
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
418 class BaseServerTestCase(unittest.TestCase):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
419 requestHandler = None
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
420 request_count = 1
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
421 threadFunc = staticmethod(http_server)
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
422
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
423 def setUp(self):
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
424 # enable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
425 SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
426
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
427 self.evt = threading.Event()
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
428 # start server thread to handle requests
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
429 serv_args = (self.evt, self.request_count, self.requestHandler)
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
430 threading.Thread(target=self.threadFunc, args=serv_args).start()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
431
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
432 # wait for the server to be ready
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
433 self.evt.wait(10)
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
434 self.evt.clear()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
435
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
436 def tearDown(self):
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
437 # wait on the server thread to terminate
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
438 self.evt.wait(10)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
439
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
440 # disable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
441 SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
442
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
443 # NOTE: The tests in SimpleServerTestCase will ignore failures caused by
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
444 # "temporarily unavailable" exceptions raised in SimpleXMLRPCServer. This
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
445 # condition occurs infrequently on some platforms, frequently on others, and
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
446 # is apparently caused by using SimpleXMLRPCServer with a non-blocking socket
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
447 # If the server class is updated at some point in the future to handle this
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
448 # situation more gracefully, these tests should be modified appropriately.
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
449
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
450 class SimpleServerTestCase(BaseServerTestCase):
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
451 def test_simple1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
452 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
453 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
454 self.assertEqual(p.pow(6,8), 6**8)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
455 except (xmlrpclib.ProtocolError, socket.error), e:
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
456 # ignore failures due to non-blocking socket 'unavailable' errors
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
457 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
458 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
459 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
460
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
461 def test_nonascii(self):
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
462 start_string = 'P\N{LATIN SMALL LETTER Y WITH CIRCUMFLEX}t'
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
463 end_string = 'h\N{LATIN SMALL LETTER O WITH HORN}n'
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
464
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
465 try:
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
466 p = xmlrpclib.ServerProxy(URL)
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
467 self.assertEqual(p.add(start_string, end_string),
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
468 start_string + end_string)
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
469 except (xmlrpclib.ProtocolError, socket.error) as e:
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
470 # ignore failures due to non-blocking socket unavailable errors.
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
471 if not is_unavailable_exception(e):
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
472 # protocol error; provide additional information in test output
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
473 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
474
72450
c02e790c4535 Issue #12931: xmlrpclib now encodes Unicode URI to ISO-8859-1, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68256
diff changeset
475 def test_unicode_host(self):
c02e790c4535 Issue #12931: xmlrpclib now encodes Unicode URI to ISO-8859-1, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68256
diff changeset
476 server = xmlrpclib.ServerProxy(u"http://%s:%d/RPC2"%(ADDR, PORT))
c02e790c4535 Issue #12931: xmlrpclib now encodes Unicode URI to ISO-8859-1, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68256
diff changeset
477 self.assertEqual(server.add("a", u"\xe9"), u"a\xe9")
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
478
44770
859bf85a556a Disabled test_xmlrpc:test_404. It's causing lots of false alarms.
Christian Heimes <christian@cheimes.de>
parents: 44211
diff changeset
479 # [ch] The test 404 is causing lots of false alarms.
859bf85a556a Disabled test_xmlrpc:test_404. It's causing lots of false alarms.
Christian Heimes <christian@cheimes.de>
parents: 44211
diff changeset
480 def XXXtest_404(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
481 # send POST with httplib, it should return 404 header and
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
482 # 'Not Found' message.
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
483 conn = httplib.HTTPConnection(ADDR, PORT)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
484 conn.request('POST', '/this-is-not-valid')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
485 response = conn.getresponse()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
486 conn.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
487
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
488 self.assertEqual(response.status, 404)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
489 self.assertEqual(response.reason, 'Not Found')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
490
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
491 def test_introspection1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
492 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
493 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
494 meth = p.system.listMethods()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
495 expected_methods = set(['pow', 'div', 'my_function', 'add',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
496 'system.listMethods', 'system.methodHelp',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
497 'system.methodSignature', 'system.multicall'])
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
498 self.assertEqual(set(meth), expected_methods)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
499 except (xmlrpclib.ProtocolError, socket.error), e:
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
500 # ignore failures due to non-blocking socket 'unavailable' errors
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
501 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
502 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
503 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
504
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
505 def test_introspection2(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
506 try:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
507 # test _methodHelp()
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
508 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
509 divhelp = p.system.methodHelp('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
510 self.assertEqual(divhelp, 'This is the div function')
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
511 except (xmlrpclib.ProtocolError, socket.error), e:
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
512 # ignore failures due to non-blocking socket 'unavailable' errors
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
513 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
514 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
515 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
516
59045
a4c45f8e70aa Issue 6292: for the moment at least, the test suite passes if run
R. David Murray <rdmurray@bitdance.com>
parents: 58472
diff changeset
517 @unittest.skipIf(sys.flags.optimize >= 2,
a4c45f8e70aa Issue 6292: for the moment at least, the test suite passes if run
R. David Murray <rdmurray@bitdance.com>
parents: 58472
diff changeset
518 "Docstrings are omitted with -O2 and above")
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
519 def test_introspection3(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
520 try:
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
521 # test native doc
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
522 p = xmlrpclib.ServerProxy(URL)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
523 myfunction = p.system.methodHelp('my_function')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
524 self.assertEqual(myfunction, 'This is my function')
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
525 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
526 # ignore failures due to non-blocking socket 'unavailable' errors
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
527 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
528 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
529 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
530
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
531 def test_introspection4(self):
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
532 # the SimpleXMLRPCServer doesn't support signatures, but
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
533 # at least check that we can try making the call
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
534 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
535 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
536 divsig = p.system.methodSignature('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
537 self.assertEqual(divsig, 'signatures not supported')
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
538 except (xmlrpclib.ProtocolError, socket.error), e:
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
539 # ignore failures due to non-blocking socket 'unavailable' errors
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
540 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
541 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
542 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
543
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
544 def test_multicall(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
545 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
546 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
547 multicall = xmlrpclib.MultiCall(p)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
548 multicall.add(2,3)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
549 multicall.pow(6,8)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
550 multicall.div(127,42)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
551 add_result, pow_result, div_result = multicall()
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
552 self.assertEqual(add_result, 2+3)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
553 self.assertEqual(pow_result, 6**8)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
554 self.assertEqual(div_result, 127//42)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
555 except (xmlrpclib.ProtocolError, socket.error), e:
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
556 # ignore failures due to non-blocking socket 'unavailable' errors
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
557 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
558 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
559 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
560
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
561 def test_non_existing_multicall(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
562 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
563 p = xmlrpclib.ServerProxy(URL)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
564 multicall = xmlrpclib.MultiCall(p)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
565 multicall.this_is_not_exists()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
566 result = multicall()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
567
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
568 # result.results contains;
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
569 # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
570 # 'method "this_is_not_exists" is not supported'>}]
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
571
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
572 self.assertEqual(result.results[0]['faultCode'], 1)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
573 self.assertEqual(result.results[0]['faultString'],
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
574 '<type \'exceptions.Exception\'>:method "this_is_not_exists" '
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
575 'is not supported')
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
576 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
577 # ignore failures due to non-blocking socket 'unavailable' errors
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
578 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
579 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
580 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
581
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
582 def test_dotted_attribute(self):
46020
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
583 # Raises an AttributeError because private methods are not allowed.
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
584 self.assertRaises(AttributeError,
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
585 SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
586
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54928
diff changeset
587 self.assertTrue(SimpleXMLRPCServer.resolve_dotted_attribute(str, 'title'))
46020
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
588 # Get the test to run faster by sending a request with test_simple1.
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
589 # This avoids waiting for the socket timeout.
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
590 self.test_simple1()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
591
75015
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
592 def test_partial_post(self):
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
593 # Check that a partial POST doesn't make the server loop: issue #14001.
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
594 conn = httplib.HTTPConnection(ADDR, PORT)
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
595 conn.request('POST', '/RPC2 HTTP/1.0\r\nContent-Length: 100\r\n\r\nbye')
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
596 conn.close()
0c02f30b2538 Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in SimpleXMLRPCServer
Charles-François Natali <neologix@free.fr>
parents: 72984
diff changeset
597
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
598 class MultiPathServerTestCase(BaseServerTestCase):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
599 threadFunc = staticmethod(http_multi_server)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
600 request_count = 2
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
601 def test_path1(self):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
602 p = xmlrpclib.ServerProxy(URL+"/foo")
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
603 self.assertEqual(p.pow(6,8), 6**8)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
604 self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
605 def test_path2(self):
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
606 p = xmlrpclib.ServerProxy(URL+"/foo/bar")
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
607 self.assertEqual(p.add(6,8), 6+8)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
608 self.assertRaises(xmlrpclib.Fault, p.pow, 6, 8)
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
609
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
610 #A test case that verifies that a server using the HTTP/1.1 keep-alive mechanism
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
611 #does indeed serve subsequent requests on the same connection
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
612 class BaseKeepaliveServerTestCase(BaseServerTestCase):
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
613 #a request handler that supports keep-alive and logs requests into a
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
614 #class variable
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
615 class RequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
616 parentClass = SimpleXMLRPCServer.SimpleXMLRPCRequestHandler
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
617 protocol_version = 'HTTP/1.1'
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
618 myRequests = []
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
619 def handle(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
620 self.myRequests.append([])
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
621 self.reqidx = len(self.myRequests)-1
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
622 return self.parentClass.handle(self)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
623 def handle_one_request(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
624 result = self.parentClass.handle_one_request(self)
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
625 self.myRequests[self.reqidx].append(self.raw_requestline)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
626 return result
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
627
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
628 requestHandler = RequestHandler
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
629 def setUp(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
630 #clear request log
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
631 self.RequestHandler.myRequests = []
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
632 return BaseServerTestCase.setUp(self)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
633
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
634 #A test case that verifies that a server using the HTTP/1.1 keep-alive mechanism
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
635 #does indeed serve subsequent requests on the same connection
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
636 class KeepaliveServerTestCase1(BaseKeepaliveServerTestCase):
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
637 def test_two(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
638 p = xmlrpclib.ServerProxy(URL)
55194
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
639 #do three requests.
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
640 self.assertEqual(p.pow(6,8), 6**8)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
641 self.assertEqual(p.pow(6,8), 6**8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
642 self.assertEqual(p.pow(6,8), 6**8)
55194
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
643
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
644 #they should have all been handled by a single request handler
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
645 self.assertEqual(len(self.RequestHandler.myRequests), 1)
55194
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
646
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
647 #check that we did at least two (the third may be pending append
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
648 #due to thread scheduling)
b1c6372a8092 http://bugs.python.org/issue6460
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55002
diff changeset
649 self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
650
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
651 #test special attribute access on the serverproxy, through the __call__
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
652 #function.
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
653 class KeepaliveServerTestCase2(BaseKeepaliveServerTestCase):
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
654 #ask for two keepalive requests to be handled.
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
655 request_count=2
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
656
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
657 def test_close(self):
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
658 p = xmlrpclib.ServerProxy(URL)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
659 #do some requests with close.
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
660 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
661 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
662 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
663 p("close")() #this should trigger a new keep-alive request
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
664 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
665 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
666 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
667
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
668 #they should have all been two request handlers, each having logged at least
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
669 #two complete requests
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
670 self.assertEqual(len(self.RequestHandler.myRequests), 2)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
671 self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
672 self.assertGreaterEqual(len(self.RequestHandler.myRequests[-2]), 2)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
673
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
674 def test_transport(self):
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
675 p = xmlrpclib.ServerProxy(URL)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
676 #do some requests with close.
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
677 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
678 p("transport").close() #same as above, really.
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
679 self.assertEqual(p.pow(6,8), 6**8)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
680 self.assertEqual(len(self.RequestHandler.myRequests), 2)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
681
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
682 #A test case that verifies that gzip encoding works in both directions
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
683 #(for a request and the response)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
684 class GzipServerTestCase(BaseServerTestCase):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
685 #a request handler that supports keep-alive and logs requests into a
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
686 #class variable
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
687 class RequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
688 parentClass = SimpleXMLRPCServer.SimpleXMLRPCRequestHandler
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
689 protocol_version = 'HTTP/1.1'
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
690
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
691 def do_POST(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
692 #store content of last request in class
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
693 self.__class__.content_length = int(self.headers["content-length"])
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
694 return self.parentClass.do_POST(self)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
695 requestHandler = RequestHandler
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
696
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
697 class Transport(xmlrpclib.Transport):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
698 #custom transport, stores the response length for our perusal
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
699 fake_gzip = False
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
700 def parse_response(self, response):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
701 self.response_length=int(response.getheader("content-length", 0))
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
702 return xmlrpclib.Transport.parse_response(self, response)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
703
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
704 def send_content(self, connection, body):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
705 if self.fake_gzip:
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
706 #add a lone gzip header to induce decode error remotely
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
707 connection.putheader("Content-Encoding", "gzip")
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
708 return xmlrpclib.Transport.send_content(self, connection, body)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
709
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
710 def setUp(self):
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
711 BaseServerTestCase.setUp(self)
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
712
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
713 def test_gzip_request(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
714 t = self.Transport()
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
715 t.encode_threshold = None
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
716 p = xmlrpclib.ServerProxy(URL, transport=t)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
717 self.assertEqual(p.pow(6,8), 6**8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
718 a = self.RequestHandler.content_length
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
719 t.encode_threshold = 0 #turn on request encoding
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
720 self.assertEqual(p.pow(6,8), 6**8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
721 b = self.RequestHandler.content_length
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
722 self.assertTrue(a>b)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
723
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
724 def test_bad_gzip_request(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
725 t = self.Transport()
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
726 t.encode_threshold = None
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
727 t.fake_gzip = True
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
728 p = xmlrpclib.ServerProxy(URL, transport=t)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
729 cm = self.assertRaisesRegexp(xmlrpclib.ProtocolError,
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
730 re.compile(r"\b400\b"))
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
731 with cm:
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
732 p.pow(6, 8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
733
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
734 def test_gsip_response(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
735 t = self.Transport()
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
736 p = xmlrpclib.ServerProxy(URL, transport=t)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
737 old = self.requestHandler.encode_threshold
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
738 self.requestHandler.encode_threshold = None #no encoding
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
739 self.assertEqual(p.pow(6,8), 6**8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
740 a = t.response_length
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
741 self.requestHandler.encode_threshold = 0 #always encode
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
742 self.assertEqual(p.pow(6,8), 6**8)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
743 b = t.response_length
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
744 self.requestHandler.encode_threshold = old
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
745 self.assertTrue(a>b)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
746
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
747 #Test special attributes of the ServerProxy object
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
748 class ServerProxyTestCase(unittest.TestCase):
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
749 def setUp(self):
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
750 unittest.TestCase.setUp(self)
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
751 if threading:
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
752 self.url = URL
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
753 else:
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
754 # Without threading, http_server() and http_multi_server() will not
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
755 # be executed and URL is still equal to None. 'http://' is a just
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
756 # enough to choose the scheme (HTTP)
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
757 self.url = 'http://'
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
758
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
759 def test_close(self):
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
760 p = xmlrpclib.ServerProxy(self.url)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
761 self.assertEqual(p('close')(), None)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
762
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
763 def test_transport(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
764 t = xmlrpclib.Transport()
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
765 p = xmlrpclib.ServerProxy(self.url, transport=t)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
766 self.assertEqual(p('transport'), t)
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
767
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
768 # This is a contrived way to make a failure occur on the server side
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
769 # in order to test the _send_traceback_header flag on the server
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
770 class FailingMessageClass(mimetools.Message):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
771 def __getitem__(self, key):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
772 key = key.lower()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
773 if key == 'content-length':
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
774 return 'I am broken'
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
775 return mimetools.Message.__getitem__(self, key)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
776
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
777
61043
f090bd72acd8 Issue #7449, part 9: fix test_xmlrpclib for missing threading module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59045
diff changeset
778 @unittest.skipUnless(threading, 'Threading required for this test.')
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
779 class FailingServerTestCase(unittest.TestCase):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
780 def setUp(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
781 self.evt = threading.Event()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
782 # start server thread to handle requests
46020
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
783 serv_args = (self.evt, 1)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
784 threading.Thread(target=http_server, args=serv_args).start()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
785
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
786 # wait for the server to be ready
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
787 self.evt.wait()
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
788 self.evt.clear()
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
789
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
790 def tearDown(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
791 # wait on the server thread to terminate
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
792 self.evt.wait()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
793 # reset flag
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
794 SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
795 # reset message class
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
796 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = mimetools.Message
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
797
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
798 def test_basic(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
799 # check that flag is false by default
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
800 flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
801 self.assertEqual(flagval, False)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
802
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
803 # enable traceback reporting
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
804 SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
805
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
806 # test a call that shouldn't fail just as a smoke test
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
807 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
808 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
809 self.assertEqual(p.pow(6,8), 6**8)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
810 except (xmlrpclib.ProtocolError, socket.error), e:
42979
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
811 # ignore failures due to non-blocking socket 'unavailable' errors
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
812 if not is_unavailable_exception(e):
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
813 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
814 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
815
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
816 def test_fail_no_info(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
817 # use the broken message class
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
818 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
819
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
820 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
821 p = xmlrpclib.ServerProxy(URL)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
822 p.pow(6,8)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
823 except (xmlrpclib.ProtocolError, socket.error), e:
42979
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
824 # ignore failures due to non-blocking socket 'unavailable' errors
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
825 if not is_unavailable_exception(e) and hasattr(e, "headers"):
42979
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
826 # The two server-side error headers shouldn't be sent back in this case
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
827 self.assertTrue(e.headers.get("X-exception") is None)
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
828 self.assertTrue(e.headers.get("X-traceback") is None)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
829 else:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
830 self.fail('ProtocolError not raised')
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
831
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
832 def test_fail_with_info(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
833 # use the broken message class
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
834 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
835
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
836 # Check that errors in the server send back exception/traceback
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
837 # info when flag is set
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
838 SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
839
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
840 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
841 p = xmlrpclib.ServerProxy(URL)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
842 p.pow(6,8)
45010
c315b67245f7 Catch socket errors that are often the cause of transient failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44961
diff changeset
843 except (xmlrpclib.ProtocolError, socket.error), e:
42979
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
844 # ignore failures due to non-blocking socket 'unavailable' errors
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
845 if not is_unavailable_exception(e) and hasattr(e, "headers"):
42979
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
846 # We should get error info in the response
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
847 expected_err = "invalid literal for int() with base 10: 'I am broken'"
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
848 self.assertEqual(e.headers.get("x-exception"), expected_err)
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
849 self.assertTrue(e.headers.get("x-traceback") is not None)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
850 else:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
851 self.fail('ProtocolError not raised')
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
852
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
853 class CGIHandlerTestCase(unittest.TestCase):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
854 def setUp(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
855 self.cgi = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
856
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
857 def tearDown(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
858 self.cgi = None
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
859
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
860 def test_cgi_get(self):
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
861 with test_support.EnvironmentVarGuard() as env:
53644
85542715a249 Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents: 53484
diff changeset
862 env['REQUEST_METHOD'] = 'GET'
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
863 # if the method is GET and no request_text is given, it runs handle_get
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
864 # get sysout output
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
865 with test_support.captured_stdout() as data_out:
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
866 self.cgi.handle_request()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
867
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
868 # parse Status header
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
869 data_out.seek(0)
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
870 handle = data_out.read()
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
871 status = handle.split()[1]
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
872 message = ' '.join(handle.split()[2:4])
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
873
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
874 self.assertEqual(status, '400')
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
875 self.assertEqual(message, 'Bad Request')
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
876
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
877
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
878 def test_cgi_xmlrpc_response(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
879 data = """<?xml version='1.0'?>
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
880 <methodCall>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
881 <methodName>test_method</methodName>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
882 <params>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
883 <param>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
884 <value><string>foo</string></value>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
885 </param>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
886 <param>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
887 <value><string>bar</string></value>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
888 </param>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
889 </params>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
890 </methodCall>
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
891 """
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
892
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
893 with test_support.EnvironmentVarGuard() as env, \
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
894 test_support.captured_stdout() as data_out, \
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
895 test_support.captured_stdin() as data_in:
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
896 data_in.write(data)
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
897 data_in.seek(0)
53644
85542715a249 Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents: 53484
diff changeset
898 env['CONTENT_LENGTH'] = str(len(data))
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50002
diff changeset
899 self.cgi.handle_request()
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
900 data_out.seek(0)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
901
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
902 # will respond exception, if so, our goal is achieved ;)
56563
2048d04deab4 Don't invoke reload(sys) and use StringIO objects instead of real files to capture stdin and stdout when needed (ensures all sys attributes remain unmodified after test_xmlrpc runs)
Nick Coghlan <ncoghlan@gmail.com>
parents: 55734
diff changeset
903 handle = data_out.read()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
904
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
905 # start with 44th char so as not to get http header, we just need only xml
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
906 self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
907
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
908 # Also test the content-length returned by handle_request
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
909 # Using the same test method inorder to avoid all the datapassing
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
910 # boilerplate code.
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
911 # Test for bug: http://bugs.python.org/issue5040
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
912
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
913 content = handle[handle.find("<?xml"):]
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
914
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61043
diff changeset
915 self.assertEqual(
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
916 int(re.search('Content-Length: (\d+)', handle).group(1)),
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
917 len(content))
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
918
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
919
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
920 class FakeSocket:
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
921
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
922 def __init__(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
923 self.data = StringIO.StringIO()
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
924
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
925 def send(self, buf):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
926 self.data.write(buf)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
927 return len(buf)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
928
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
929 def sendall(self, buf):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
930 self.data.write(buf)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
931
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
932 def getvalue(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
933 return self.data.getvalue()
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
934
50734
d09d6fe31b61 Issue 4879: Allow buffering for HTTPResponse
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50002
diff changeset
935 def makefile(self, x='r', y=-1):
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
936 raise RuntimeError
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
937
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
938 def close(self):
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
939 pass
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
940
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
941 class FakeTransport(xmlrpclib.Transport):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
942 """A Transport instance that records instead of sending a request.
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
943
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
944 This class replaces the actual socket used by httplib with a
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
945 FakeSocket object that records the request. It doesn't provide a
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
946 response.
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
947 """
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
948
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
949 def make_connection(self, host):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
950 conn = xmlrpclib.Transport.make_connection(self, host)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
951 conn.sock = self.fake_socket = FakeSocket()
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
952 return conn
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
953
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
954 class TransportSubclassTestCase(unittest.TestCase):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
955
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
956 def issue_request(self, transport_class):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
957 """Return an HTTP request made via transport_class."""
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
958 transport = transport_class()
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
959 proxy = xmlrpclib.ServerProxy("http://example.com/",
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
960 transport=transport)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
961 try:
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
962 proxy.pow(6, 8)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
963 except RuntimeError:
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
964 return transport.fake_socket.getvalue()
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
965 return None
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
966
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
967 def test_custom_user_agent(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
968 class TestTransport(FakeTransport):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
969
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
970 def send_user_agent(self, conn):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
971 xmlrpclib.Transport.send_user_agent(self, conn)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
972 conn.putheader("X-Test", "test_custom_user_agent")
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
973
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
974 req = self.issue_request(TestTransport)
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 56985
diff changeset
975 self.assertIn("X-Test: test_custom_user_agent\r\n", req)
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
976
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
977 def test_send_host(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
978 class TestTransport(FakeTransport):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
979
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
980 def send_host(self, conn, host):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
981 xmlrpclib.Transport.send_host(self, conn, host)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
982 conn.putheader("X-Test", "test_send_host")
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
983
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
984 req = self.issue_request(TestTransport)
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 56985
diff changeset
985 self.assertIn("X-Test: test_send_host\r\n", req)
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
986
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
987 def test_send_request(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
988 class TestTransport(FakeTransport):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
989
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
990 def send_request(self, conn, url, body):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
991 xmlrpclib.Transport.send_request(self, conn, url, body)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
992 conn.putheader("X-Test", "test_send_request")
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
993
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
994 req = self.issue_request(TestTransport)
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 56985
diff changeset
995 self.assertIn("X-Test: test_send_request\r\n", req)
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
996
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
997 def test_send_content(self):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
998 class TestTransport(FakeTransport):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
999
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1000 def send_content(self, conn, body):
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1001 conn.putheader("X-Test", "test_send_content")
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1002 xmlrpclib.Transport.send_content(self, conn, body)
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1003
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1004 req = self.issue_request(TestTransport)
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 56985
diff changeset
1005 self.assertIn("X-Test: test_send_content\r\n", req)
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1006
56985
c146925234f0 Try to fix transient refleaks in test_xmlrpc.
Antoine Pitrou <solipsis@pitrou.net>
parents: 56563
diff changeset
1007 @test_support.reap_threads
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
1008 def test_main():
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
1009 xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
1010 BinaryTestCase, FaultTestCase, TransportSubclassTestCase]
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
1011 xmlrpc_tests.append(SimpleServerTestCase)
55232
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
1012 xmlrpc_tests.append(KeepaliveServerTestCase1)
d076e65a90d6 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55194
diff changeset
1013 xmlrpc_tests.append(KeepaliveServerTestCase2)
55343
3a613e00f66d http://bugs.python.org/issue6499
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55232
diff changeset
1014 try:
3a613e00f66d http://bugs.python.org/issue6499
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55232
diff changeset
1015 import gzip
3a613e00f66d http://bugs.python.org/issue6499
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55232
diff changeset
1016 xmlrpc_tests.append(GzipServerTestCase)
3a613e00f66d http://bugs.python.org/issue6499
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55232
diff changeset
1017 except ImportError:
3a613e00f66d http://bugs.python.org/issue6499
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55232
diff changeset
1018 pass #gzip not supported in this build
55734
ae00a3a80473 Issue 6654
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55343
diff changeset
1019 xmlrpc_tests.append(MultiPathServerTestCase)
54928
ffd7cf5c7285 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 53644
diff changeset
1020 xmlrpc_tests.append(ServerProxyTestCase)
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
1021 xmlrpc_tests.append(FailingServerTestCase)
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
1022 xmlrpc_tests.append(CGIHandlerTestCase)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
1023
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
1024 test_support.run_unittest(*xmlrpc_tests)
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
1025
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
1026 if __name__ == "__main__":
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
1027 test_main()