1 #!/usr/bin/env python2.3
2 from __future__
import generators
5 import os
, time
, xmlrpclib
6 from os
.path
import dirname
, abspath
, join
8 rox_lib
= dirname(dirname(dirname(abspath(sys
.argv
[0]))))
9 sys
.path
.insert(0, join(rox_lib
, 'python'))
11 from rox
import xxmlrpc
, g
14 allowed_methods
= ['echo', 'none']
23 class TestXXMLRPC(unittest
.TestCase
):
25 service
= xxmlrpc
.XXMLRPCServer('rox_test_service')
26 service
.add_object('/foo', TestObject())
27 self
.proxy
= xxmlrpc
.XXMLProxy('rox_test_service')
30 obj
= self
.proxy
.get_object('/foo')
31 call
= obj
.echo('Hello World')
32 self
.assertEquals("Echo: Hello World", call
.get_response())
35 obj
= self
.proxy
.get_object('/foo')
40 except xmlrpclib
.Fault
, ex
:
41 self
.assertEquals('TypeError', ex
.faultCode
)
42 assert ex
.faultString
.find('cannot concatenate') >= 0
45 obj
= self
.proxy
.get_object('/foo')
46 call1
= obj
.echo('Hello')
47 call2
= obj
.echo('World')
48 self
.assertEquals("Echo: World", call2
.get_response())
49 self
.assertEquals("Echo: Hello", call1
.get_response())
51 def testBadObject(self
):
52 obj
= self
.proxy
.get_object('/food')
57 except xmlrpclib
.Fault
, ex
:
58 self
.assertEquals('UnknownObject', ex
.faultCode
)
60 def testBadMethod(self
):
61 obj
= self
.proxy
.get_object('/foo')
62 call
= obj
.write("Hi")
66 except xmlrpclib
.Fault
, ex
:
67 self
.assertEquals('NoSuchMethod', ex
.faultCode
)
69 def testReturnNone(self
):
70 obj
= self
.proxy
.get_object('/foo')
72 self
.assertEquals(True, call
.get_response())
74 def testNoReturn(self
):
75 obj
= self
.proxy
.get_object('/foo')
78 sys
.stderr
= StringIO
.StringIO()
81 err
= sys
.stderr
.getvalue()
82 assert err
.index("ClientCall object destroyed") == 0
83 sys
.stderr
= StringIO
.StringIO()
84 # Wait for proxy to try to read window
85 while not sys
.stderr
.getvalue():
87 err
= sys
.stderr
.getvalue()
88 assert err
.index("No '_XXMLRPC_MESSAGE' property") == 0
92 suite
= unittest
.makeSuite(TestXXMLRPC
)
93 if __name__
== '__main__':