首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修补Falcon钩子

修补Falcon钩子
EN

Stack Overflow用户
提问于 2019-03-15 15:02:17
回答 1查看 220关注 0票数 5

我有一个带有之前钩子的api。我想把它打到我的custom_function上。你知道我该怎么做吗?我已经在我的custom_falcon_before上打了falcon.before补丁。

代码语言:javascript
复制
class TestModel(MyTestCase):
    def falcon_before(self, model_exists):
        return model_exists

    def model_exists(self, req, resp, resource, params, require_exists):
        pass

    @patch("app.views.expect_model_existence", side_effect=model_exists)
    @patch("falcon.before", side_effect=falcon_before)
    def test_delete(self, falcon_before, model_exists):
        import falcon
        print(falcon_before is falcon.before)
        print(model_exists is expect_model_existence)

第二个打印是False

我的API模型如下

代码语言:javascript
复制
class SingleModel:

    @falcon.before(expect_model_existence, True)
    def on_delete(self, req, resp, model_id):
        pass
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-23 02:18:07

在导入view.py之前,将expect_model_existence放到单独的模块中并对其进行修补

print('too late')放在包含expect_model_existence的模块中,以验证一切正常。

Falcon没有提供更舒适的东西:(

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55177236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档