Home Help Center

Python Testing Framework

What is the recommended approach for testing client\server applications in ice.

Server:
import sys, Ice, time
Ice.loadSlice('Session.ice')
from SessionFactoryI import *

class SessionServer(Ice.Application):
def run(self, args):
adapter = self.communicator().createObjectAdapter("SessionFactory.Server")
sessionfactory = SessionFactoryI()
adapter.add(sessionfactory, Ice.stringToIdentity("SessionFactory"))
adapter.activate()
self.communicator().waitForShutdown()
return True


TestFramework:
class test_Server(unittest.TestCase):
def testClientConnection(self):
#use a config file
properties = Ice.createProperties()
properties.load("config")
#initialize the ice environment
communicator = Ice.initializeWithProperties(sys.argv, properties)
#get the proxy information from the loaded config
proxy = properties.getProperty("TimeTracker.SessionFactory")
#get a proxy object for the server
sessionfactory = TimeTracker.SessionFactoryPrx.checkedCast(communicator.stringToProxy(proxy))


if __name__ == '__main__':
unittest.main()

SessionFactoryI:

import TimeTracker
from SessionI import *

class SessionFactoryI(TimeTracker.SessionFactory):
def __init__(self):
self.sessions = []
print "Session Factory Created"

def create(self, Name_, IceCurrent_):
return "Create called"

def printSessions(self, IceCurrent_):
print "printSessions called"
Sign In or Register to comment.