diff --git a/mvc_flask/__init__.py b/mvc_flask/__init__.py index 1e0fbcb..57a4791 100644 --- a/mvc_flask/__init__.py +++ b/mvc_flask/__init__.py @@ -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), ) diff --git a/mvc_flask/router.py b/mvc_flask/router.py index 3e1b64c..08d7d86 100644 --- a/mvc_flask/router.py +++ b/mvc_flask/router.py @@ -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 diff --git a/tests/routes_test.py b/tests/routes_test.py index e11d5fd..68e4a08 100644 --- a/tests/routes_test.py +++ b/tests/routes_test.py @@ -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 @@ -68,6 +68,7 @@ def _(client=test_client): ] assert methods.count("PUT") == 1 + assert methods.count("PATCH") == 1 @test("count DELETE") diff --git a/tests/users_test.py b/tests/users_test.py index 4901dae..723c032 100644 --- a/tests/users_test.py +++ b/tests/users_test.py @@ -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))