def setUp(self): '''Create an XMLRPC object and host it in a different process''' Registry.clear() def hello(name): return 'Hello, %s' % name class ArithmeticService(object): '''An XMLRPC Object that performs arithmetic on the server''' def add(self, a, b): return a + b def pow(self, a, b): return a ** b def multiply(self, a, b): return a * b dispatcher = XMLRPCResource("/", ArithmeticService(), [hello,]) application = Application("/", resources=[dispatcher,]) application.debug = False application.secret = "SHERLOCK" print "Starting XMLRPC Server Process" self.process = Process(target=run, args=(application,)) self.process.start() time.sleep(0.5) #Wait for the server to start in the other process.
def setUp(self): '''Create a new class on the fly and test it''' Registry.clear() # Define a base class. @Path("/home") class HomeResource(Resource): '''REST API for creating User accounts''' @POST @Route("/{name}") def new(self, name): '''Creates a new user with @name''' self.response.statuscode = 200 self.response.text = "Just created: %s" % name @GET @Route("/{name}") def read(self, name): '''Get the user with @name''' self.response.statuscode = 200 self.response.text = "Just fetched: %s" % name @PUT @Route("/{name}") def update(self, name): '''updates the user with @name''' self.response.statuscode = 200 self.response.text = "Just updated: %s" % name @DELETE @Route("/{name}") def deactivate(self, name): '''deactivate the user account with @name''' self.response.statuscode = 200 self.response.text = "Just deleted: %s" % name # Inherit from it. @Path("/heart") class HomeResource2(HomeResource): pass self.application = Application(base="/", resources=[HomeResource2,]) self.application.secret = "SHERLOCK"
def setUp(self): Registry.clear() @Path("/users") class UserResource(Resource): '''REST API for creating User accounts''' @POST @Route("/create/{name}") def new(self, name): '''Creates a new user with @name''' self.response.statuscode = 200 self.response.text = "Just created: %s" % name @Methods("PUT", "POST") @Route("/do/some/stuff/with/{name}") def do(self, name): '''Creates a new user with @name''' self.response.statuscode = 200 self.response.text = "Just created: %s" % name @GET @Route("/{name}") def read(self, name): '''Get the user with @name''' self.response.statuscode = 200 self.response.text = "Just fetched: %s" % name @PUT @Route("/update/{name}") def update(self, name): '''updates the user with @name''' self.response.statuscode = 200 self.response.text = "Just updated: %s" % name @DELETE @Route("/deactivate/{name}") def deactivate(self, name): '''deactivate the user account with @name''' self.response.statuscode = 200 self.response.text = "Just deactivated: %s" % name self.application = Application(base="/", resources=[UserResource,]) self.application.debug = False self.application.secret = "SHERLOCK"
def tearDown(self): '''Clear the Registry''' Registry.clear()
def setUp(self): '''Clean up''' Registry.clear()
def setUp(self): '''Simply clears the `Registry`''' Registry.clear()
def setUp(self): """Clean up""" Registry.clear()
def tearDown(self): '''Clear the Registry''' Registry.clear() path = "src/tests/core/assets/upload.txt" if os.path.exists(path): os.remove(path)