annotate Lib/test/test_xmlrpc.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 85542715a249
children ffd7cf5c7285
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
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
14 import re
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 20571
diff changeset
15 from test import test_support
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
16
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
17 try:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
18 unicode
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
19 except NameError:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
20 have_unicode = False
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
21 else:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
22 have_unicode = True
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
23
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
24 alist = [{'astring': 'foo@bar.baz.spam',
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
25 '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
26 '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
27 'ashortlong': 2L,
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
28 'anotherlist': ['.zyx.41'],
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
29 'abase64': xmlrpclib.Binary("my dog has fleas"),
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
30 'boolean': xmlrpclib.False,
32248
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
31 'unicode': u'\u4000\u6000\u8000',
df4943d24cb6 [Bug #841757] Exercise handling of Unicode strings
Andrew M. Kuchling <amk@amk.ca>
parents: 28809
diff changeset
32 u'ukey\u4000': 'regular value',
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
33 'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
34 'datetime2': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
35 (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
36 'datetime3': xmlrpclib.DateTime(
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
37 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
38 }]
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
39
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
40 class XMLRPCTestCase(unittest.TestCase):
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
41
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
42 def test_dump_load(self):
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
43 self.assertEquals(alist,
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
44 xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0])
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
45
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 32248
diff changeset
46 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
47 # 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
48 # 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
49 # 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
50 # 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
51 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
52 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
53 (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
54 self.assertEquals(newdt, dt)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
55 self.assertEquals(m, None)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
56
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
57 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34881
diff changeset
58 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
59
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
60 def test_datetime_before_1900(self):
46508
fdd5a0198769 Comment typo
Andrew M. Kuchling <amk@amk.ca>
parents: 46471
diff changeset
61 # same as before but with a date before 1900
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
62 dt = datetime.datetime(1, 02, 10, 11, 41, 23)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
63 s = xmlrpclib.dumps((dt,))
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
64 (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
65 self.assertEquals(newdt, dt)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
66 self.assertEquals(m, None)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
67
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
68 (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
69 self.assertEquals(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 46155
diff changeset
70
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
71 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
72 now = datetime.datetime.now()
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
73 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
74 self.assert_(dt == now)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
75 self.assert_(now == dt)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
76 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
77 self.assert_(then >= dt)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 45020
diff changeset
78 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
79
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
80 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
81 d = xmlrpclib.DateTime()
36121
686306a67e9b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 35984
diff changeset
82 ((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
83 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
84 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
85
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 # 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
87 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
88 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
89
40360
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
90 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
91 class T(object):
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
92 pass
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
93 t = T()
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
94 t.x = 100
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
95 t.y = "Hello"
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 36121
diff changeset
96 ((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
97 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
98
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
99 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
100 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
101
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
102 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
103 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
104
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
105 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
106 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
107 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
108 l.append(t)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
109 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
110
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
111 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
112 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
113 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
114 d['t'] = t
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
115 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
116
20571
541f825c7d63 added tests for long ints and ints where they are > 32 bits.
Skip Montanaro <skip@pobox.com>
parents: 20205
diff changeset
117 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
118 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
119 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
120 (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
121
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
122 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
123 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
124 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
125
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
126 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
127 pass
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
128
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
129 m = xmlrpclib.Marshaller()
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.MAXINT, dummy_write)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
131 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
132 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
133 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
134
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
135
28809
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
136 def test_dump_none(self):
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
137 value = alist + [None]
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
138 arg1 = (alist + [None],)
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
139 strg = xmlrpclib.dumps(arg1, allow_none=True)
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
140 self.assertEquals(value,
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
141 xmlrpclib.loads(strg)[0][0])
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
142 self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
28a09767a24f [Patch #628208] Test the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 24364
diff changeset
143
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
144 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
145 # 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
146 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
147 <params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
148 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
149 <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
150 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
151 <param><value>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
152 <struct>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
153 <member>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
154 <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
155 <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
156 </member>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
157 </struct>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
158 </value></param>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
159 </params>
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
160 """
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
161
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
162 # 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
163 # 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
164 old_encoding = sys.getdefaultencoding()
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
165 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
166 reload(sys) # ugh!
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
167 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
168 try:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
169 (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
170 finally:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
171 sys.setdefaultencoding(old_encoding)
34881
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
172 if not setdefaultencoding_existed:
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
173 del sys.setdefaultencoding
64bc5a922f57 test_default_encoding_issues(): Fully restore sys.setdefaultencoding.
Tim Peters <tim.peters@gmail.com>
parents: 34582
diff changeset
174
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
175 items = d.items()
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
176 if have_unicode:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
177 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
178 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
179 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
180 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
181 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
182 else:
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
183 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
184 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
185
42251
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
186
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
187 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
188 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
189 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
190 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
191 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
192
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
193 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
194 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
195 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
196 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
197 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
198
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
199 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
200 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
201 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
202 (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
203 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
204 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
205
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
206 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
207 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
208
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
209
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
210 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
211 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
212 t = xmlrpclib.DateTime()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
213
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
214 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
215 d = 1181399930.036952
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
216 t = xmlrpclib.DateTime(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
217 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
218
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
219 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
220 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
221 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
222 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
223
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
224 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
225 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
226 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
227 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
228
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
229 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
230 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
231 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
232 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
233
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
234 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
235 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
236 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
237 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
238 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
239
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
240 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
241 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
242 t1 = xmlrpclib.DateTime()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
243 t1.decode(d)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
244 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
245 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
246
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
247 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
248 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
249
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
250 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
251 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
252 t = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
253 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
254
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
255 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
256 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
257 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
258 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
259
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
260 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
261 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
262 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
263 t1 = xmlrpclib.Binary()
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
264 t1.decode(de)
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
265 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
266
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
267 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
268 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
269
0c0d750ee75e Added tests for basic behavior of DateTime, Binary, and Fault classes
Facundo Batista <facundobatista@gmail.com>
parents: 40360
diff changeset
270
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
271 ADDR = PORT = URL = None
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
272
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
273 # 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
274 # 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
275 # 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
276 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
277 class TestInstanceClass:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
278 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
279 return x // y
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
280
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
281 def _methodHelp(self, name):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
282 if name == 'div':
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
283 return 'This is the div function'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
284
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
285 def my_function():
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
286 '''This is my function'''
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
287 return True
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
288
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
289 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
290 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
291 # 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
292 # 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
293 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
294 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
295 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
296
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
297 serv = MyXMLRPCServer(("localhost", 0),
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
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 try:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
300 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
301 serv.server_bind()
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
302 global ADDR, PORT, URL
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
303 ADDR, PORT = serv.socket.getsockname()
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
304 #connect to IP address directly. This avoids socket.create_connection()
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
305 #trying to connect to to "localhost" using all address families, which
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
306 #causes slowdown e.g. on vista which supports AF_INET6. The server listens
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
307 #on AF_INET only.
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
308 URL = "http://%s:%d"%(ADDR, PORT)
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
309 serv.server_activate()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
310 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
311 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
312 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
313 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
314 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
315 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
316 evt.set()
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
317
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
318 # 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
319 while numrequests > 0:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
320 serv.handle_request()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
321 numrequests -= 1
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
322
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
323 except socket.timeout:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
324 pass
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
325 finally:
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
326 serv.socket.close()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
327 PORT = None
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
328 evt.set()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
329
44961
be44faed542d The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
Neal Norwitz <nnorwitz@gmail.com>
parents: 44958
diff changeset
330 # 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
331 # <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
332 def is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
333 '''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
334 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
335 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
336
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
337 # 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
338 try:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
339 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
340 return True
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
341 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
342 except AttributeError:
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
343 # Ignore socket.errors here.
0a70f5b30b8a Try to handle socket.errors properly in is_unavailable
Neal Norwitz <nnorwitz@gmail.com>
parents: 45010
diff changeset
344 exc_mess = str(e)
42886
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
345
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
346 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
347 return True
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
348
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
349 return False
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
350
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
351 # 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
352 # "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
353 # 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
354 # 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
355 # 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
356 # 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
357
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
358 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
359 def setUp(self):
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
360 # enable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
361 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
362
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
363 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
364 # 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
365 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
366 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
367
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
368 # 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
369 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
370 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
371
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
372 def tearDown(self):
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
373 # 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
374 self.evt.wait()
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
375
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
376 # disable traceback reporting
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
377 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
378
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
379 def test_simple1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
380 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
381 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
382 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
383 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
384 # 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
385 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
386 # 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
387 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
388
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
389 def test_nonascii(self):
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
390 start_string = 'P\N{LATIN SMALL LETTER Y WITH CIRCUMFLEX}t'
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
391 end_string = 'h\N{LATIN SMALL LETTER O WITH HORN}n'
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
392
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
393 try:
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
394 p = xmlrpclib.ServerProxy(URL)
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
395 self.assertEqual(p.add(start_string, end_string),
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
396 start_string + end_string)
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
397 except (xmlrpclib.ProtocolError, socket.error) as e:
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
398 # ignore failures due to non-blocking socket unavailable errors.
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
399 if not is_unavailable_exception(e):
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
400 # protocol error; provide additional information in test output
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
401 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
402
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
403
44770
859bf85a556a Disabled test_xmlrpc:test_404. It's causing lots of false alarms.
Christian Heimes <christian@cheimes.de>
parents: 44211
diff changeset
404 # [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
405 def XXXtest_404(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
406 # 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
407 # 'Not Found' message.
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
408 conn = httplib.HTTPConnection(ADDR, PORT)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
409 conn.request('POST', '/this-is-not-valid')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
410 response = conn.getresponse()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
411 conn.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
412
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
413 self.assertEqual(response.status, 404)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
414 self.assertEqual(response.reason, 'Not Found')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
415
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
416 def test_introspection1(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
417 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
418 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
419 meth = p.system.listMethods()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
420 expected_methods = set(['pow', 'div', 'my_function', 'add',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
421 'system.listMethods', 'system.methodHelp',
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
422 'system.methodSignature', 'system.multicall'])
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
423 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
424 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
425 # 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
426 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
427 # 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
428 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
429
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
430 def test_introspection2(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
431 try:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
432 # test _methodHelp()
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
433 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
434 divhelp = p.system.methodHelp('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
435 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
436 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
437 # 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
438 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
439 # 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
440 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
441
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
442 def test_introspection3(self):
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
443 try:
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
444 # test native doc
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
445 p = xmlrpclib.ServerProxy(URL)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
446 myfunction = p.system.methodHelp('my_function')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
447 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
448 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
449 # 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
450 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
451 # 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
452 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
453
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
454 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
455 # 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
456 # 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
457 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
458 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
459 divsig = p.system.methodSignature('div')
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
460 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
461 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
462 # 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
463 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
diff changeset
464 # 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
465 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
466
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
467 def test_multicall(self):
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
468 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
469 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
470 multicall = xmlrpclib.MultiCall(p)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
471 multicall.add(2,3)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
472 multicall.pow(6,8)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
473 multicall.div(127,42)
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
474 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
475 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
476 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
477 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
478 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
479 # 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
480 if not is_unavailable_exception(e):
e648485cf3af Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42682
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", "")))
42587
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
483
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
484 def test_non_existing_multicall(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
485 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
486 p = xmlrpclib.ServerProxy(URL)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
487 multicall = xmlrpclib.MultiCall(p)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
488 multicall.this_is_not_exists()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
489 result = multicall()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
490
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
491 # result.results contains;
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
492 # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
493 # 'method "this_is_not_exists" is not supported'>}]
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
494
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
495 self.assertEqual(result.results[0]['faultCode'], 1)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
496 self.assertEqual(result.results[0]['faultString'],
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
497 '<type \'exceptions.Exception\'>:method "this_is_not_exists" '
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
498 '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
499 except (xmlrpclib.ProtocolError, socket.error), e:
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
500 # 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
501 if not is_unavailable_exception(e):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
502 # protocol error; provide additional information in test output
45020
be3140ec67c8 socket.error doesn't have a headers attribute like ProtocolError.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45016
diff changeset
503 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
504
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
505 def test_dotted_attribute(self):
46020
722bef6835b9 Speed up the test by avoiding socket timeouts.
Neal Norwitz <nnorwitz@gmail.com>
parents: 45459
diff changeset
506 # 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
507 self.assertRaises(AttributeError,
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
508 SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
509
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
510 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
511 # 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
512 # 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
513 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
514
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
515 # 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
516 # 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
517 class FailingMessageClass(mimetools.Message):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
518 def __getitem__(self, key):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
519 key = key.lower()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
520 if key == 'content-length':
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
521 return 'I am broken'
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
522 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
523
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
524
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
525 class FailingServerTestCase(unittest.TestCase):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
526 def setUp(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
527 self.evt = threading.Event()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
528 # 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
529 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
530 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
531
44958
6ae22030e152 Use a condition variable (threading.Event) rather than sleeps and checking a
Neal Norwitz <nnorwitz@gmail.com>
parents: 44770
diff changeset
532 # 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
533 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
534 self.evt.clear()
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
535
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
536 def tearDown(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
537 # 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
538 self.evt.wait()
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
539 # reset flag
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
540 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
541 # reset message class
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
542 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
543
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
544 def test_basic(self):
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
545 # 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
546 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
547 self.assertEqual(flagval, False)
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
548
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
549 # enable traceback reporting
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
550 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
551
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
552 # 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
553 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
554 p = xmlrpclib.ServerProxy(URL)
42682
43b354a8f773 Catch ProtocolError exceptions and include the header information in
Facundo Batista <facundobatista@gmail.com>
parents: 42658
diff changeset
555 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
556 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
557 # 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
558 if not is_unavailable_exception(e):
82602315eaeb Ignore test failures caused by 'resource temporarily unavailable'
Facundo Batista <facundobatista@gmail.com>
parents: 42886
diff changeset
559 # 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
560 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
561
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
562 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
563 # 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
564 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
565
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
566 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
567 p = xmlrpclib.ServerProxy(URL)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
568 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
569 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
570 # 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
571 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
572 # 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
573 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
574 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
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
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
578 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
579 # 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
580 SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
581
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
582 # 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
583 # 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
584 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
585
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
586 try:
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
587 p = xmlrpclib.ServerProxy(URL)
42658
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
588 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
589 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
590 # 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
591 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
592 # 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
593 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
594 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
595 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
596 else:
bc31dfcf7dfa Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
Facundo Batista <facundobatista@gmail.com>
parents: 42587
diff changeset
597 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
598
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
599 class CGIHandlerTestCase(unittest.TestCase):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
600 def setUp(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
601 self.cgi = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
602
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
603 def tearDown(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
604 self.cgi = None
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_get(self):
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
607 with test_support.EnvironmentVarGuard() as env:
53644
85542715a249 Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents: 53484
diff changeset
608 env['REQUEST_METHOD'] = 'GET'
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
609 # if the method is GET and no request_text is given, it runs handle_get
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
610 # get sysout output
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
611 tmp = sys.stdout
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
612 sys.stdout = open(test_support.TESTFN, "w")
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
613 self.cgi.handle_request()
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
614 sys.stdout.close()
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
615 sys.stdout = tmp
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
616
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
617 # parse Status header
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
618 handle = open(test_support.TESTFN, "r").read()
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
619 status = handle.split()[1]
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
620 message = ' '.join(handle.split()[2:4])
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
621
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
622 self.assertEqual(status, '400')
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
623 self.assertEqual(message, 'Bad Request')
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
624
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
625 os.remove(test_support.TESTFN)
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
626
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
627 def test_cgi_xmlrpc_response(self):
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
628 data = """<?xml version='1.0'?>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
629 <methodCall>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
630 <methodName>test_method</methodName>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
631 <params>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
632 <param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
633 <value><string>foo</string></value>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
634 </param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
635 <param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
636 <value><string>bar</string></value>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
637 </param>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
638 </params>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
639 </methodCall>
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
640 """
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
641 open("xmldata.txt", "w").write(data)
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
642 tmp1 = sys.stdin
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
643 tmp2 = sys.stdout
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
644
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
645 sys.stdin = open("xmldata.txt", "r")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
646 sys.stdout = open(test_support.TESTFN, "w")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
647
53484
abdc1764d8e5 Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents: 52671
diff changeset
648 with test_support.EnvironmentVarGuard() as env:
53644
85542715a249 Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents: 53484
diff changeset
649 env['CONTENT_LENGTH'] = str(len(data))
52647
027a3adc0d8f Fix test_xmlrpc and make the CGI handler work with no CONTENT_LENGTH.
Georg Brandl <georg@python.org>
parents: 50794
diff changeset
650 self.cgi.handle_request()
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
651
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
652 sys.stdin.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
653 sys.stdout.close()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
654 sys.stdin = tmp1
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
655 sys.stdout = tmp2
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
656
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
657 # 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
658 handle = open(test_support.TESTFN, "r").read()
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
659
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
660 # 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
661 self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
662
52671
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
663 # Also test the content-length returned by handle_request
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
664 # Using the same test method inorder to avoid all the datapassing
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
665 # boilerplate code.
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
666 # Test for bug: http://bugs.python.org/issue5040
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
667
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
668 content = handle[handle.find("<?xml"):]
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
669
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
670 self.assertEquals(
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
671 int(re.search('Content-Length: (\d+)', handle).group(1)),
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
672 len(content))
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
673
42da7154b270 Fix for issue5040. Adding test for Content-Length
Senthil Kumaran <orsenthil@gmail.com>
parents: 52647
diff changeset
674
44211
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
675 os.remove("xmldata.txt")
80884643a6f9 Increase unit test coverage of SimpleXMLRPCServer.
Georg Brandl <georg@python.org>
parents: 42979
diff changeset
676 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
677
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
678 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
679
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 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
681 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
682
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 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
684 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
685 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
686
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 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
688 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
689
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 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
691 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
692
50734
d09d6fe31b61 Issue 4879: Allow buffering for HTTPResponse
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50002
diff changeset
693 def makefile(self, x='r', y=-1):
50002
5ef8b5a74efa Merged revisions 67245,67277,67289,67295,67301-67303,67307,67330,67332,67336,67355,67359,67362,67364,67367-67368,67370 via svnmerge from
Georg Brandl <georg@python.org>
parents: 46508
diff changeset
694 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
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 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
697 """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
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 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
700 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
701 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
702 """
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
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 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
705 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
706 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
707 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
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 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
710
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 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
712 """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
713 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
714 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
715 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
716 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
717 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
718 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
719 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
720 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
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 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
723 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
724
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 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
726 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
727 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
728
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
729 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
730 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
731
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
732 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
733 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
734
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
735 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
736 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
737 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
738
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
739 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
740 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
741
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
742 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
743 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
744
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
745 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
746 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
747 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
748
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
749 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
750 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
751
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
752 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
753 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
754
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
755 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
756 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
757 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
758
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
759 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
760 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
761
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
762 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
763 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
764 BinaryTestCase, FaultTestCase, TransportSubclassTestCase]
50794
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
765 xmlrpc_tests.append(SimpleServerTestCase)
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
766 xmlrpc_tests.append(FailingServerTestCase)
8df81941de05 Re-enable all tests for windows platforms.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50734
diff changeset
767 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
768
219fe39ede99 Added tests for simple function calls and introspection that are run
Facundo Batista <facundobatista@gmail.com>
parents: 42251
diff changeset
769 test_support.run_unittest(*xmlrpc_tests)
20205
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
770
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
771 if __name__ == "__main__":
00152e68745a simple dumps/loads test case for xmlrpclib
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
772 test_main()