Esempio n. 1
0
class TestRequest(Request):
    def __init__(self, **kwargs):
        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():
Esempio n. 2
0
    return Response("test4 - {}".format(id))


class TestRequest(Request):
    def __init__(self, **kwargs):
        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)
Esempio n. 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)
Esempio n. 4
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List
from controllers.computer import ComputerList, ComputerMethods
from controllers.program import ProgramList, ProgramMethods

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
        url("/computer", ComputerMethods(), methods=["get", "post", "put", "delete"]),
        url("/computers", ComputerList(), methods=["get"]),
        url("/program", ProgramMethods(), methods=["get", "post", "put", "delete"]),
        url("/programs", ProgramList(), methods=["get"]),
    ]),
]
Esempio n. 5
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List
from controllers.author import ListCreateAuthors, DetailUpdateDeleteAuthor
from controllers.book import CreateListBook, DetailUpdateDeleteBook, ListCreateTag, DetailTag
from controllers.stock import GetStock, PeDetails, ListStocks

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
        url("/authors", ListCreateAuthors(), methods=["get", "post"]),
        url("/authors/<int:pk>", DetailUpdateDeleteAuthor(), methods=["get", "delete", "put"]),
        url("/books", CreateListBook(), methods=["get", "post"]),
        url("/books/<int:pk>", DetailUpdateDeleteBook(), methods=["get", "delete", "put"]),
        url("/tags", ListCreateTag(), methods=["get", "post"]),
        url("/tags/<int:pk>", DetailTag(), methods=["get"]),
        url("/stocks", ListStocks(), methods=["get"]),
        url("/stocks/<int:pk>", GetStock(), methods=["get"]),
        url("/stocks/pe-info", PeDetails(), methods=["get"]),

    ]),
]
Esempio n. 6
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
    ]),
]
Esempio n. 7
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers import user, artist

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),

        # user urls
        url("/login", user.Login(), methods=["post"]),
        url("/users", user.Register(), methods=["post"]),
        url("/users", user.List(), methods=["get"]),

        # artist urls
        url("/artists", artist.List(), methods=["get"]),
        url("/artists", artist.Create(), methods=["post"]),
        url("/artists/<int:id>", artist.Update(), methods=["put"]),
        url("/artists/<int:id>", artist.Delete(), methods=["delete"]),
        url("/artists/<int:id>", artist.Get(), methods=["get"]),
        url("/artists/<int:id>/like", artist.Like(), methods=["post"]),
        url("/artists/<int:id>/unlike", artist.Unlike(), methods=["post"]),
    ]),
]
Esempio n. 8
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)