def main(name, args): application = Application('config/dev.xml') if not args: print('USAGE: python {} <base_path>[ <port:8000>]'.format(name)) sys.exit(255) base_path = args[0] services.get('internal.finder').set_base_path(base_path) if len(args) > 1: port = args[1] application.listen(port) application.start()
class TestDependencyInjectableApplicationClass(unittest.TestCase): """ Test a dependency-injectable Application class. """ def setUp(self): self.app = Application("../data/good_server.xml") def tearDown(self): del self.app def __test_route(self, routing_pattern, routing_class): self.assertIsInstance( self.app.get_route(routing_pattern), routing_class, "Check for the route of type %s" % routing_class.__name__, ) def test_listening_port_from_configuration_file(self): """ Test the listening port from the configuration file. """ self.assertEqual(self.app.get_listening_port(), 1234) def test_listening_port_after_manual_intervention(self): """ Test the listening port from the manual intervention (covering the abstract application class). """ self.app.listen(5678) self.assertEqual(self.app.get_listening_port(), 5678) def test_routing(self): """ Test the registered routes. """ self.__test_route("/plain", DynamicRoute) self.__test_route("/ctrl-with-renderer", DynamicRoute) self.__test_route("/resources(/.*)", StaticRoute) self.__test_route("/about-shiroyuki", RelayRoute) try: self.app.get_route("/plain/") self.assertTrue(False, "Unexpectedly know the unregistered pattern.") except RoutingPatternNotFoundError: pass def test_mandatory_dependencies(self): """ Test for mandatory dependencies required by Tori.Application """ self.assertEqual(self.app._hierarchy_level, 2) self.assertIsInstance(self.app._routing_map, RoutingMap) wsgi_app = WSGIApplication("../data/good_server.xml") self.assertEqual(wsgi_app._hierarchy_level, 3)
""" A sample application using Application. :author: Juti Noppornpitak <*****@*****.**> """ from time import time import bootstrap from tori.application import Application time_at_blank_state = time() application = Application('server.xml') time_at_prepared_state = time() print('Time elapsed on setup: {}'.format(time_at_prepared_state - time_at_blank_state)) application.start()
# -*- coding: utf-8 -*- from logging import DEBUG, INFO, WARNING from tori.application import Application from tori.common import LoggerFactory import fixtures LoggerFactory.instance().set_default_level(INFO) application = Application('config/app.xml') # Load data fixtures if necessary fixtures.auto_load() # Start up the service. application.start()
# -*- coding: utf-8 -*- from tori.application import Application, WSGIApplication toriapp = None wsgiapp = None if __name__ == '__main__': # Run with the built-in server. toriapp = Application('config/app.xml') toriapp.start() else: # Run with Gunicorn toriapp = WSGIApplication('config/app.xml') wsgiapp = toriapp.get_backbone()
def setUp(self): self.app = Application("../data/good_server.xml")