Пример #1
0
def main():
    import cars
    routes = get_routes(cars)
    print("Routes\n======\n\n" +
          json.dumps([(url, repr(rh)) for url, rh in routes], indent=2))
    application = Application(routes=routes, settings={})
    reactor.listenTCP(8888, application)
    reactor.run()
Пример #2
0
 def test_get_routes(self):
     """Tests routes.get_routes"""
     assert sorted(routes.get_routes(helloworld)) == sorted([
         ("/api/helloworld/?", helloworld.api.HelloWorldHandler),
         ("/api/asynchelloworld/(?P<name>[a-zA-Z0-9_\\-]+)/?$",
          helloworld.api.AsyncHelloWorld),
         ("/api/postit/?", helloworld.api.PostIt),
         ("/api/greeting/(?P<fname>[a-zA-Z0-9_\\-]+)/"
          "(?P<lname>[a-zA-Z0-9_\\-]+)/?$", helloworld.api.Greeting),
         ("/api/freewilled/?", helloworld.api.FreeWilledHandler)
     ])
     assert sorted(routes.get_routes(cars)) == sorted([
         ("/api/cars/?", cars.api.MakeListHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/(?P<model>[a-zA-Z0-9_\\-]+)/?$",
          cars.api.ModelHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/(?P<model>[a-zA-Z0-9_\\-]+)/"
          "(?P<year>[a-zA-Z0-9_\\-]+)/?$", cars.api.YearHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/?$", cars.api.MakeHandler),
     ])
Пример #3
0
def main():
    import cars
    routes = get_routes(cars)
    print("Routes\n======\n\n" + json.dumps(
        [(url, repr(rh)) for url, rh in routes],
        indent=2)
    )
    application = Application(routes=routes, settings={})
    reactor.listenTCP(8888, application)
    reactor.run()
Пример #4
0
 def app_builder(self):
     rts = routes.get_routes(helloworld)
     rts += [
         ("/api/explodinghandler", ExplodingHandler),
         ("/api/notfoundhandler", NotFoundHandler),
     ]
     return application.Application(
         routes=rts,
         settings={"debug": True},
     )
Пример #5
0
 def test_get_routes(self):
     """Tests routes.get_routes"""
     assert sorted(routes.get_routes(
         helloworld)) == sorted([
         ("/api/helloworld/?", helloworld.api.HelloWorldHandler),
         ("/api/asynchelloworld/(?P<name>[a-zA-Z0-9_\\-]+)/?$", helloworld.api.AsyncHelloWorld),
         ("/api/postit/?", helloworld.api.PostIt),
         ("/api/greeting/(?P<fname>[a-zA-Z0-9_\\-]+)/"
          "(?P<lname>[a-zA-Z0-9_\\-]+)/?$",
          helloworld.api.Greeting),
         ("/api/freewilled/?", helloworld.api.FreeWilledHandler)
     ])
     assert sorted(routes.get_routes(
         cars)) == sorted([
         ("/api/cars/?", cars.api.MakeListHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/(?P<model>[a-zA-Z0-9_\\-]+)/?$",
          cars.api.ModelHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/(?P<model>[a-zA-Z0-9_\\-]+)/"
          "(?P<year>[a-zA-Z0-9_\\-]+)/?$", cars.api.YearHandler),
         ("/api/cars/(?P<make>[a-zA-Z0-9_\\-]+)/?$", cars.api.MakeHandler),
     ])
Пример #6
0
def main():
    # Pass the web app's package the get_routes and it will generate
    #   routes based on the submodule names and ending with lowercase
    #   request handler name (with 'handler' removed from the end of the
    #   name if it is the name).
    # [("/api/helloworld", helloworld.api.HelloWorldHandler)]
    import helloworld
    routes = get_routes(helloworld)
    print("Routes\n======\n\n" + json.dumps(
        [(url, repr(rh)) for url, rh in routes],
        indent=2)
    )
    log.startLogging(sys.stdout)
    # Create the application by passing routes and any settings
    application = Application(routes=routes, settings={})

    # Start the application on port 8888
    reactor.listenTCP(8888, application)
    reactor.run()
Пример #7
0
def test__get_api_docs():
    relative_dir = os.path.abspath(os.path.dirname(__file__))
    filepath = os.path.join(relative_dir, "helloworld_API_documentation.md")
    HELLOWORLD_DOC = open(filepath).read()

    assert get_api_docs(get_routes(helloworld)) == HELLOWORLD_DOC
Пример #8
0
def test__get_api_docs():
    relative_dir = os.path.abspath(os.path.dirname(__file__))
    filepath = os.path.join(relative_dir, "helloworld_API_documentation.md")
    HELLOWORLD_DOC = open(filepath).read()

    assert get_api_docs(get_routes(helloworld)) == HELLOWORLD_DOC