A fork of https://github.com/Synerty/SOAPpy-py3 This is a working tree till fixes get imported upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 lines
2.9 KiB

  1. import gc
  2. import socket
  3. import threading
  4. import time
  5. import unittest
  6. import sys
  7. sys.path.insert(1, "..")
  8. import SOAPpy
  9. #SOAPpy.Config.debug=1
  10. # global to shut down server
  11. quit = 0
  12. def echoDateTime(dt):
  13. return dt
  14. def echo(s):
  15. """repeats a string twice"""
  16. return s + s
  17. def kill():
  18. """tell the server to quit"""
  19. global quit
  20. quit = 1
  21. def server1():
  22. """start a SOAP server on localhost:8000"""
  23. print "Starting SOAP Server...",
  24. server = SOAPpy.Server.SOAPServer(addr=('127.0.0.1', 8000))
  25. server.registerFunction(echoDateTime)
  26. server.registerFunction(echo)
  27. server.registerFunction(kill)
  28. print "Done."
  29. global quit
  30. while not quit:
  31. server.handle_request()
  32. quit = 0
  33. print "Server shut down."
  34. class ClientTestCase(unittest.TestCase):
  35. server = None
  36. startup_timeout = 5 # seconds
  37. def setUp(self):
  38. '''This is run once before each unit test.'''
  39. serverthread = threading.Thread(target=server1, name="SOAPServer")
  40. serverthread.start()
  41. start = time.time()
  42. connected = False
  43. server = None
  44. while not connected and time.time() - start < self.startup_timeout:
  45. print "Trying to connect to the SOAP server...",
  46. try:
  47. server = SOAPpy.Client.SOAPProxy('127.0.0.1:8000')
  48. server.echo('Hello World')
  49. except socket.error, e:
  50. print "Failure:", e
  51. time.sleep(0.5)
  52. else:
  53. connected = True
  54. self.server = server
  55. print "Success."
  56. if not connected: raise 'Server failed to start.'
  57. def tearDown(self):
  58. '''This is run once after each unit test.'''
  59. print "Trying to shut down SOAP server..."
  60. if self.server is not None:
  61. self.server.kill()
  62. time.sleep(5)
  63. return 1
  64. def testEcho(self):
  65. '''Test echo function.'''
  66. server = SOAPpy.Client.SOAPProxy('127.0.0.1:8000')
  67. s = 'Hello World'
  68. self.assertEquals(server.echo(s), s+s)
  69. def testNamedEcho(self):
  70. '''Test echo function.'''
  71. server = SOAPpy.Client.SOAPProxy('127.0.0.1:8000')
  72. s = 'Hello World'
  73. self.assertEquals(server.echo(s=s), s+s)
  74. def testEchoDateTime(self):
  75. '''Test passing DateTime objects.'''
  76. server = SOAPpy.Client.SOAPProxy('127.0.0.1:8000')
  77. dt = SOAPpy.Types.dateTimeType(data=time.time())
  78. dt_return = server.echoDateTime(dt)
  79. self.assertEquals(dt_return, dt)
  80. # def testNoLeak(self):
  81. # '''Test for memory leak.'''
  82. # gc.set_debug(gc.DEBUG_SAVEALL)
  83. # for i in range(400):
  84. # server = SOAPpy.Client.SOAPProxy('127.0.0.1:8000')
  85. # s = 'Hello World'
  86. # server.echo(s)
  87. # gc.collect()
  88. # self.assertEquals(len(gc.garbage), 0)
  89. if __name__ == '__main__':
  90. unittest.main()