예제 #1
0
 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.
예제 #2
0
파일: testcore.py 프로젝트: atlas/gates
 def testMapperFor(self):
     '''Tests if registry can create a mapper to match a set of handlers'''
     @Path("/registry")
     class Default(Resource):
     
         @POST
         @Route("/hello/{world}")
         def handle(self):
             print "Hello world"
     
     @Path("/products")
     class Product(Resource):
     
         @GET
         @Route("/{product}/{colour}")
         def show(self, product, colour):
             print "Showing id: %s" % id
      
     mapper = Registry.mapperFor("/", Product, Default)
     self.assertTrue(mapper is not None)
     results = mapper.match("/registry/hello/iroiso")
     self.assertTrue(results is not None)
     self.assertEquals(results["controller"], Default)
     self.assertEquals(results["action"], Default.handle.__func__)
     
     results = mapper.match("/products/iphone/black")
     self.assertTrue(results is not None)
     self.assertEquals(results["controller"], Product)
     self.assertEquals(results["action"], Product.show.__func__)      
예제 #3
0
파일: testroutes.py 프로젝트: atlas/gates
 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"
예제 #4
0
파일: testroutes.py 프로젝트: atlas/gates
 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"
예제 #5
0
파일: testcore.py 프로젝트: atlas/gates
 def testSanity(self):
     '''Checks the common execution paths'''
     @Path("/base", "institutions")
     class Handler(Resource):
         '''A Mock Handler'''
         pass
     print "Testing normal behavior"
     self.assertTrue(Registry.handlerFor("institutions", "/base") == Handler)
     self.assertTrue(Registry.pathFor(Handler)[1] == "/base")
     print "Testing that @Path only allows Resource objects"
     with self.assertRaises(ValueError):
         @Path("/")
         class Handler(object):
             pass
     
     print "Show that @Path only accepts routes preceded with a slash"
     with self.assertRaises(ValueError):
         @Path("hello")
         class Handler(Resource):
             pass
예제 #6
0
파일: testcore.py 프로젝트: atlas/gates
 def testSanity(self):
     '''Checks common execution paths'''
     class Handler(Resource):
         '''The simplest request handler I can conceive'''
         @GET
         @Route("/hello")
         def handle(self):
             pass
     
     builder = Registry.builderFor(Handler.handle.__func__) 
     self.assertTrue(builder is not None)
     route = builder.build()
예제 #7
0
파일: testcore.py 프로젝트: atlas/gates
 def testBuilderFor(self):
     '''Tests method: builderFor''' 
     @Path("/registry")
     class Handler(Resource):
     
         @POST
         @Route("/hello/{world}")
         def handle(self):
             print "Hello world"
     
     found = list(Registry.routesFor(Handler))
     print "Found : %s routes" % len(found)
     self.assertTrue(found)
예제 #8
0
파일: testcore.py 프로젝트: atlas/gates
 def testAddHandler(self):
     '''Tests if addHandler works as expected, Tests methods: [addHandler, pathFor, handlerFor]'''
     class Handler(Resource): pass #Sample request handler
     
     print "\nTesting the normal execution paths"
     Registry.addHandler(None, "/", Handler)
     self.assertEqual(Registry.handlerFor(None, "/"), Handler)
     self.assertEqual("/", Registry.pathFor(Handler)[1])
     print "Normal execution path ok, proceeding with other tests"
     
     print "\nTesting defensive safe guards"
     print "Checking if ``Registry`` accepts slashless paths"
     self.assertRaises(ValueError, lambda: Registry.addHandler(None, "hello", Handler))
     print "Checking if ``Registry`` accepts non Resource objects"
     self.assertRaises(ValueError, lambda: Registry.addHandler(None, "/hello", object))
     print "Checking if ``Registry`` accepts duplicate paths"
     self.assertRaises(DuplicatePathError, lambda: Registry.addHandler(None, "/", Handler))
     print "Defensive assertions ok"
예제 #9
0
 def tearDown(self):
     '''Clear the Registry'''
     Registry.clear()
예제 #10
0
파일: testcore.py 프로젝트: atlas/gates
 def setUp(self):
     '''Clean up'''
     Registry.clear()
예제 #11
0
파일: testcore.py 프로젝트: atlas/gates
 def setUp(self):
     '''Simply clears the `Registry`'''
     Registry.clear()
예제 #12
0
 def setUp(self):
     """Clean up"""
     Registry.clear()
예제 #13
0
파일: testfiles.py 프로젝트: atlas/gates
 def tearDown(self):
     '''Clear the Registry'''
     Registry.clear()
     path = "src/tests/core/assets/upload.txt"
     if os.path.exists(path):
         os.remove(path)