Exemple #1
0
def setup_app():
    main_handler = chain(
            wrap_auth(backend=auth_backend),
            wrap_json_body,
            wrap_json_response,
            wrap_cors_response,
            wrap_sqlalchemy_session,
            router(urls)
    )

    return application(main_handler)
Exemple #2
0
        self.scheme = "http"


urls = [
    url("/", handler1, methods=["get", "post"], name="handler1"),
    url("/<int:id>", handler2, methods="get", name="handler2"),
    context(
        "/test",
        [
            url("/", handler3, methods=["get", "post"], name="handler3"),
            url("/<int:id>", handler4, methods=["get", "post"], name="handler4"),
        ],
    ),
]

app = router(urls)


def test_routing_root():
    request = TestRequest(uri="/", method="get")
    response = app(request)
    assert response.body == "test1"


def test_routing_root_invalid_method():
    request = TestRequest(uri="/", method="put")
    response = app(request)
    assert response.status == 405


def test_routing_by_id():
Exemple #3
0
    else:
        return NotFound()


def create(request):
    database.append(request.data)
    return Created(request.data, mimetype="application/json")


def delete(request, index):
    if len(database) > index:
        del database[index]
        return NoContent()
    else:
        return NotFound()

urls = [
    context("/api", [
        url("/", list, methods=["get"]),
        url("/", create, methods=["post"]),
        url("/<int:index>", detail, methods=["get"]),
        url("/<int:index>", delete, methods=["delete"]),
    ])
]

app = application(chain(json_middleware, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
Exemple #4
0
        return NotFound()


def create(request):
    database.append(request.body)
    return Created(request.body, mimetype="application/json")


def delete(request, index):
    if len(database) > index:
        del database[index]
        return NoContent()
    else:
        return NotFound()


urls = [
    context("/api", [
        url("/", list, methods=["get"]),
        url("/", create, methods=["post"]),
        url("/<int:index>", detail, methods=["get"]),
        url("/<int:index>", delete, methods=["delete"]),
    ])
]

app = application(chain(wrap_json, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
from anillo.app import application
from anillo.handlers.routing import router, url
from anillo.http import Ok


def index(request):
    return Ok("Index")


def hello(request):
    return Ok("Hello World!")

urls = [
    url("/", index),
    url("/hello", hello, methods=["get"]),
]

app = application(router(urls))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
Exemple #6
0
        super().__init__(**kwargs)
        self.server_name = "test"
        self.server_port = "80"
        self.scheme = "http"


urls = [
    url("/", handler1, methods=["get", "post"], name="handler1"),
    url("/<int:id>", handler2, methods="get", name="handler2"),
    context("/test", [
        url("/", handler3, methods=["get", "post"], name="handler3"),
        url("/<int:id>", handler4, methods=["get", "post"], name="handler4"),
    ])
]

app = router(urls)


def test_routing_root():
    request = TestRequest(uri="/", method="get")
    response = app(request)
    assert response.body == "test1"


def test_routing_root_invalid_method():
    request = TestRequest(uri="/", method="put")
    response = app(request)
    assert response.status == 405


def test_routing_by_id():
Exemple #7
0
    else:
        return NotFound()


def create(request):
    database.append(request.body)
    return Created(request.body, mimetype="application/json")


def delete(request, index):
    if len(database) > index:
        del database[index]
        return NoContent()
    else:
        return NotFound()

urls = [
    context("/api", [
        url("/", list, methods=["get"]),
        url("/", create, methods=["post"]),
        url("/<int:index>", detail, methods=["get"]),
        url("/<int:index>", delete, methods=["delete"]),
    ])
]

app = application(chain(wrap_json, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)