Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mvc_flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def register_blueprint(self, app: Flask):
rule=resource.path,
endpoint=resource.action,
view_func=getattr(view_func(), resource.action),
methods=[resource.method],
methods=resource.method,
defaults=dict(view=render_template, request=request),
)

Expand Down
8 changes: 4 additions & 4 deletions mvc_flask/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ def _method_route():
def get(path: str, resource: str):
controller, action = resource.split("#")
Router.ROUTES.append(
{controller: Model("GET", path, controller, action)}
{controller: Model(["GET"], path, controller, action)}
)

@staticmethod
def post(path: str, resource: str):
controller, action = resource.split("#")
Router.ROUTES.append(
{controller: Model("POST", path, controller, action)}
{controller: Model(["POST"], path, controller, action)}
)

@staticmethod
def put(path: str, resource: str):
controller, action = resource.split("#")
Router.ROUTES.append(
{controller: Model("PUT", path, controller, action)}
{controller: Model(["PUT", "PATCH"], path, controller, action)},
)

@staticmethod
def delete(path: str, resource: str):
controller, action = resource.split("#")
Router.ROUTES.append(
{controller: Model("DELETE", path, controller, action)}
{controller: Model(["DELETE"], path, controller, action)}
)

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion tests/routes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _(client=test_client):
assert methods.count("POST") == 2


@test("count PUT")
@test("count PUT and PATCH")
def _(client=test_client):
methods = [
route
Expand All @@ -68,6 +68,7 @@ def _(client=test_client):
]

assert methods.count("PUT") == 1
assert methods.count("PATCH") == 1


@test("count DELETE")
Expand Down
8 changes: 8 additions & 0 deletions tests/users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def _(client=test_client):
assert "updated user: 1" in resp.get_data(as_text=True)


@test("PATCH /users/1")
def _(client=test_client):
resp = client.patch(url_for("users.update", id=1))

assert resp.status_code == 200
assert "updated user: 1" in resp.get_data(as_text=True)


@test("DELETE /users/1")
def _(client=test_client):
resp = client.delete(url_for("users.delete", id=1))
Expand Down