annotate Lib/test/test_xmlrpc.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 0688e8b24632
children a88cb8005110
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
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
8 import threading
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
9 import mimetools
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
10 import httplib
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
11 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
12 import StringIO
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
13 import os
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:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
17 unicode
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
18 except NameError:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
19 have_unicode = False
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
20 else:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
21 have_unicode = True
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
22
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
23 alist = [{'astring': 'foo@bar.baz.spam',
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
24 '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
25 '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
26 'ashortlong': 2L,
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
27 'anotherlist': ['.zyx.41'],
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
28 'abase64': xmlrpclib.Binary("my dog has fleas"),
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
29 'boolean': xmlrpclib.False,
32248
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
30 'unicode': u'\u4000\u6000\u8000',
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
31 u'ukey\u4000': 'regular value',
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
32 'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
33 'datetime2': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
34 (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
35 'datetime3': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
36 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
37 }]
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
38
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
39 class XMLRPCTestCase(unittest.TestCase):
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
40
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
41 def test_dump_load(self):
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
42 self.assertEquals(alist,
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
43 xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0])
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
44
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
45 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
46 # 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
47 # 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
48 # 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
49 # 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
50 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
51 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
52 (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
53 self.assertEquals(newdt, dt)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
54 self.assertEquals(m, None)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
55
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
56 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
57 self.assertEquals(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
58
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
59 def test_datetime_before_1900(self):
46508
fdd5a0198769 Comment typo
Andrew M. Kuchling <amk@amk.ca>
parents: 46471
diff changeset
60 # same as before but with a date before 1900
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
61 dt = datetime.datetime(1, 02, 10, 11, 41, 23)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
62 s = xmlrpclib.dumps((dt,))
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
63 (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
64 self.assertEquals(newdt, dt)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
65 self.assertEquals(m, None)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
66
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
67 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
68 self.assertEquals(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
69
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
70 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
71 now = datetime.datetime.now()
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
72 dt = xmlrpclib.DateTime(now.timetuple())
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
73 self.assert_(dt == now)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
74 self.assert_(now == dt)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
75 then = now + datetime.timedelta(seconds=4)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
76 self.assert_(then >= dt)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
77 self.assert_(dt < then)
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
78
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
79 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
80 d = xmlrpclib.DateTime()
36121
686306a67e9b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 35984
diff changeset
81 ((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
82 methodresponse=True))
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
83 self.assert_(isinstance(new_d.value, str))
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
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 # 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
86 s = xmlrpclib.dumps((new_d,), methodresponse=True)
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 self.assert_(isinstance(s, str))
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
88
40360
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
89 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
90 class T(object):
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
91 pass
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
92 t = T()
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
93 t.x = 100
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
94 t.y = "Hello"
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
95 ((t2,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((t,)))
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
96 self.assertEquals(t2, t.__dict__)
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
97
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
98 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
99 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
100
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
101 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
102 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
103
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
104 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
105 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
106 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
107 l.append(t)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
108 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
109
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
110 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
111 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
112 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
113 d['t'] = t
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
114 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
115
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
116 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
117 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
118 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
119 (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
120
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
121 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
122 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
123 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
124
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
125 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
126 pass
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
127
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
128 m = xmlrpclib.Marshaller()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
129 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
130 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
131 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
132 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
133
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
134
28809
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
135 def test_dump_none(self):
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
136 value = alist + [None]
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
137 arg1 = (alist + [None],)
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
138 strg = xmlrpclib.dumps(arg1, allow_none=True)
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
139 self.assertEquals(value,
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
140 xmlrpclib.loads(strg)[0][0])
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
141 self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
142
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
143 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
144 # 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
145 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
146 <params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
147 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
148 <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
149 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
150 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
151 <struct>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
152 <member>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
153 <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
154 <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
155 </member>
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 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
158 </params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
159 """
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
160
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
161 # sys.setdefaultencoding() normally doesn't exist after site.py is
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
162 # loaded. reload(sys) is the way to get it back.
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
163 old_encoding = sys.getdefaultencoding()
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
164 setdefaultencoding_existed = hasattr(sys, "setdefaultencoding")
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
165 reload(sys) # ugh!
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
166 sys.setdefaultencoding("iso-8859-1")
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
167 try:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
168 (s, d), m = xmlrpclib.loads(utf8)
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
169 finally:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
170 sys.setdefaultencoding(old_encoding)
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
171 if not setdefaultencoding_existed:
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
172 del sys.setdefaultencoding
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
173
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
174 items = d.items()
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
175 if have_unicode:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
176 self.assertEquals(s, u"abc \x95")
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
177 self.assert_(isinstance(s, unicode))
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
178 self.assertEquals(items, [(u"def \x96", u"ghi \x97")])
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
179 self.assert_(isinstance(items[0][0], unicode))
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
180 self.assert_(isinstance(items[0][1], unicode))
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
181 else:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
182 self.assertEquals(s, "abc \xc2\x95")
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
183 self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
184
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
185
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
186 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
187 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
188 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
189 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
190 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
191
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
192 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
193 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
194 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
195 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
196 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
197
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
198 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
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 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
201 (newf,), m = xmlrpclib.loads(s)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
202 self.assertEquals(newf, {'faultCode': 42, 'faultString': 'Test Fault'})
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
203 self.assertEquals(m, None)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
204
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
205 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
206 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
207
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
208
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
209 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
210 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
211 t = xmlrpclib.DateTime()
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 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
214 d = 1181399930.036952
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
215 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
216 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
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_tuple(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
219 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
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), '20070609T10:38:50')
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_struct(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
224 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
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), 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
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_datetime_datetime(self):
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
229 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
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), '20070102T03:04:05')
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_repr(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 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
237 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
238
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
239 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
240 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
241 t1 = xmlrpclib.DateTime()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
242 t1.decode(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
243 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
244 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
245
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
246 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
247 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
248
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
249 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
250 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
251 t = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
252 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
253
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
254 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
255 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
256 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
257 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
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_decode(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 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
262 t1 = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
263 t1.decode(de)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
264 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
265
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
266 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
267 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
268
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
269
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
270 PORT = None
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
271
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
272 # 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
273 # 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
274 # the event after it has been set the first time to catch the second set.
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
275 def http_server(evt, numrequests):
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
276 class TestInstanceClass:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
277 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
278 return x // y
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
279
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
280 def _methodHelp(self, name):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
281 if name == 'div':
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
282 return 'This is the div function'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
283
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
284 def my_function():
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
285 '''This is my function'''
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
286 return True
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
287
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
288 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
289 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
290 # 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
291 # 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
292 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
293 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
294 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
295
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
296 try:
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
297 serv = MyXMLRPCServer(("localhost", 0),
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 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
299 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
300 serv.server_bind()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
301 global PORT
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
302 PORT = serv.socket.getsockname()[1]
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
303 serv.server_activate()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
304 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
305 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
306 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
307 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
308 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
309 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
310 evt.set()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
311
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
312 # 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
313 while numrequests > 0:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
314 serv.handle_request()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
315 numrequests -= 1
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
316
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
317 except socket.timeout:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
318 pass
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
319 finally:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
320 serv.socket.close()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
321 PORT = None
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
322 evt.set()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
323
44961
be44faed542d The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44958
diff changeset
324 # 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
325 # <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
326 def is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
327 '''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
328 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
329 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
330
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
331 # 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
332 try:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
333 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
334 return True
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
335 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
336 except AttributeError:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
337 # Ignore socket.errors here.
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
338 exc_mess = str(e)
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
339
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
340 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
341 return True
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
342
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
343 return False
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
344
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
345 # NOTE: The tests in SimpleServerTestCase will ignore failures caused by
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
346 # "temporarily unavailable" exceptions raised in SimpleXMLRPCServer. This
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
347 # condition occurs infrequently on some platforms, frequently on others, and
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
348 # is apparently caused by using SimpleXMLRPCServer with a non-blocking socket.
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
349 # If the server class is updated at some point in the future to handle this
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
350 # situation more gracefully, these tests should be modified appropriately.
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
351
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
352 class SimpleServerTestCase(unittest.TestCase):
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
353 def setUp(self):
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
354 # enable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
355 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
356
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
357 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
358 # start server thread to handle requests
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
359 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
360 threading.Thread(target=http_server, 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
361
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
362 # 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
363 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
364 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
365
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
366 def tearDown(self):
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
367 # wait on the server thread to terminate
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
368 self.evt.wait()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
369
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
370 # disable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
371 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
372
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
373 def test_simple1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
374 try:
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
375 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
376 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
377 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
378 # 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
379 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
380 # 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
381 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
382
44770
859bf85a556a Disabled test_xmlrpc:test_404. It's causing lots of false alarms.
Christian Heimes <christian@cheimes.de>
parents: 44211
diff changeset
383 # [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
384 def XXXtest_404(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
385 # 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
386 # 'Not Found' message.
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
387 conn = httplib.HTTPConnection('localhost', PORT)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
388 conn.request('POST', '/this-is-not-valid')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
389 response = conn.getresponse()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
390 conn.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
391
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
392 self.assertEqual(response.status, 404)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
393 self.assertEqual(response.reason, 'Not Found')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
394
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
395 def test_introspection1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
396 try:
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
397 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
398 meth = p.system.listMethods()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
399 expected_methods = set(['pow', 'div', 'my_function', 'add',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
400 'system.listMethods', 'system.methodHelp',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
401 'system.methodSignature', 'system.multicall'])
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
402 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
403 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
404 # 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
405 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
406 # 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
407 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
408
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
409 def test_introspection2(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
410 try:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
411 # test _methodHelp()
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
412 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
413 divhelp = p.system.methodHelp('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
414 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
415 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
416 # 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
417 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
418 # 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
419 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
420
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
421 def test_introspection3(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
422 try:
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
423 # test native doc
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
424 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
425 myfunction = p.system.methodHelp('my_function')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
426 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
427 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
428 # 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
429 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
430 # 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
431 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
432
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
433 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
434 # 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
435 # 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
436 try:
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
437 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
438 divsig = p.system.methodSignature('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
439 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
440 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
441 # 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
442 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
443 # 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
444 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
445
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
446 def test_multicall(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
447 try:
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
448 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
449 multicall = xmlrpclib.MultiCall(p)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
450 multicall.add(2,3)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
451 multicall.pow(6,8)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
452 multicall.div(127,42)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
453 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
454 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
455 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
456 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
457 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
458 # 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
459 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
460 # 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
461 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
462
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
463 def test_non_existing_multicall(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
464 try:
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
465 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
466 multicall = xmlrpclib.MultiCall(p)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
467 multicall.this_is_not_exists()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
468 result = multicall()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
469
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
470 # result.results contains;
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
471 # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
472 # 'method "this_is_not_exists" is not supported'>}]
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
473
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
474 self.assertEqual(result.results[0]['faultCode'], 1)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
475 self.assertEqual(result.results[0]['faultString'],
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
476 '<type \'exceptions.Exception\'>:method "this_is_not_exists" '
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
477 '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
478 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
479 # 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
480 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
481 # 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
482 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
483
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
484 def test_dotted_attribute(self):
46020
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
485 # 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
486 self.assertRaises(AttributeError,
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
487 SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
488
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
489 self.assert_(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
490 # 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
491 # 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
492 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
493
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
494 # 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
495 # 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
496 class FailingMessageClass(mimetools.Message):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
497 def __getitem__(self, key):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
498 key = key.lower()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
499 if key == 'content-length':
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
500 return 'I am broken'
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
501 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
502
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
503
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
504 class FailingServerTestCase(unittest.TestCase):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
505 def setUp(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
506 self.evt = threading.Event()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
507 # 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
508 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
509 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
510
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
511 # 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
512 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
513 self.evt.clear()
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
514
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
515 def tearDown(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
516 # 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
517 self.evt.wait()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
518 # reset flag
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
519 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
520 # reset message class
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
521 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
522
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
523 def test_basic(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
524 # 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
525 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
526 self.assertEqual(flagval, False)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
527
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
528 # enable traceback reporting
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
529 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
530
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
531 # 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
532 try:
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
533 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
534 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
535 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
536 # 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
537 if not is_unavailable_exception(e):
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
538 # 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
539 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
540
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
541 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
542 # 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
543 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
544
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
545 try:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
546 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
547 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
548 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
549 # 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
550 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
551 # 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
552 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
553 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
554 else:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
555 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
556
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
557 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
558 # 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
559 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
560
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
561 # 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
562 # 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
563 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
564
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
565 try:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
566 p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
567 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
568 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
569 # 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
570 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
571 # 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
572 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
573 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
574 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
575 else:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
576 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
577
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
578 class CGIHandlerTestCase(unittest.TestCase):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
579 def setUp(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
580 self.cgi = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
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 tearDown(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
583 self.cgi = None
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
584
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
585 def test_cgi_get(self):
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
586 with test_support.EnvironmentVarGuard() as env:
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
587 env.set('REQUEST_METHOD', 'GET')
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
588 # 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
589 # get sysout output
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
590 tmp = sys.stdout
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
591 sys.stdout = open(test_support.TESTFN, "w")
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
592 self.cgi.handle_request()
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
593 sys.stdout.close()
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
594 sys.stdout = tmp
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
595
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
596 # parse Status header
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
597 handle = open(test_support.TESTFN, "r").read()
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
598 status = handle.split()[1]
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
599 message = ' '.join(handle.split()[2:4])
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
600
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
601 self.assertEqual(status, '400')
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
602 self.assertEqual(message, 'Bad Request')
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
603
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
604 os.remove(test_support.TESTFN)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
605
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
606 def test_cgi_xmlrpc_response(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
607 data = """<?xml version='1.0'?>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
608 <methodCall>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
609 <methodName>test_method</methodName>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
610 <params>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
611 <param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
612 <value><string>foo</string></value>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
613 </param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
614 <param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
615 <value><string>bar</string></value>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
616 </param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
617 </params>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
618 </methodCall>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
619 """
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
620 open("xmldata.txt", "w").write(data)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
621 tmp1 = sys.stdin
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
622 tmp2 = sys.stdout
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
623
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
624 sys.stdin = open("xmldata.txt", "r")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
625 sys.stdout = open(test_support.TESTFN, "w")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
626
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
627 with test_support.EnvironmentVarGuard() as env:
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52900
diff changeset
628 env.set('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
629 self.cgi.handle_request()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
630
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
631 sys.stdin.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
632 sys.stdout.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
633 sys.stdin = tmp1
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
634 sys.stdout = tmp2
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
635
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
636 # will respond exception, if so, our goal is achieved ;)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
637 handle = open(test_support.TESTFN, "r").read()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
638
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
639 # 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
640 self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
641
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
642 os.remove("xmldata.txt")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
643 os.remove(test_support.TESTFN)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
644
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
645 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
646
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
647 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
648 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
649
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
650 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
651 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
652 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
653
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
654 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
655 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
656
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
657 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
658 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
659
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
660 def makefile(self, x, y):
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
661 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
662
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
663 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
664 """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
665
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
666 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
667 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
668 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
669 """
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
670
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
671 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
672 conn = xmlrpclib.Transport.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
673 conn._conn.sock = self.fake_socket = 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
674 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
675
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
676 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
677
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
678 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
679 """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
680 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
681 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
682 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
683 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
684 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
685 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
686 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
687 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
688
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
689 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
690 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
691
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
692 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
693 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
694 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
695
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
696 req = self.issue_request(TestTransport)
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
697 self.assert_("X-Test: test_custom_user_agent\r\n" in req)
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
698
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
699 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
700 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
701
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
702 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
703 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
704 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
705
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
706 req = self.issue_request(TestTransport)
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
707 self.assert_("X-Test: test_send_host\r\n" in req)
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
708
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
709 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
710 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
711
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
712 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
713 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
714 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
715
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
716 req = self.issue_request(TestTransport)
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
717 self.assert_("X-Test: test_send_request\r\n" in req)
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
718
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
719 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
720 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
721
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
722 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
723 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
724 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
725
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
726 req = self.issue_request(TestTransport)
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
727 self.assert_("X-Test: test_send_content\r\n" in req)
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
728
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
729 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
730 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
731 BinaryTestCase, FaultTestCase, TransportSubclassTestCase]
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
732
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
733 # The test cases against a SimpleXMLRPCServer raise a socket error
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
734 # 10035 (WSAEWOULDBLOCK) in the server thread handle_request call when
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
735 # run on Windows. This only happens on the first test to run, but it
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
736 # fails every time and so these tests are skipped on win32 platforms.
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
737 if sys.platform != 'win32':
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
738 xmlrpc_tests.append(SimpleServerTestCase)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
739 xmlrpc_tests.append(FailingServerTestCase)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
740 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
741
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
742 test_support.run_unittest(*xmlrpc_tests)
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
743
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
744 if __name__ == "__main__":
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
745 test_main()