Pravin
Pravin

Reputation: 697

Patching Falcon hook

I have a api with a before hook. I want to patch it to my custom_function. Any idea how do I do it? I have already patch falcon.before to my custom_falcon_before.

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)

second print is False.

My API model is as below

class SingleModel:

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

Upvotes: 5

Views: 328

Answers (1)

ADR
ADR

Reputation: 1291

Place expect_model_existence to a separate module and patch it before the view.py will be imported

Place print('too late') in a module that contains expect_model_existence to verify that everything is OK.

Falcon doesn't provide something more comfortable :(

Upvotes: 2

Related Questions