How to mock an authentication decorator with Pytest?

295 views Asked by At

I am going to mock an authentication decorator with Pytest. The framework is Pylons. Can you please let me know if you have any experience? Please help me! It's very important to me.

api.py

@validate_and_configure_for_network
def ping(self):
    data = {
        "status": 200,
        "message": "OK"
    }
    return self.json_response(http_status=200, full_response=data)

conftest.py

@pytest.fixture
def app(mocker):
    mocker.patch("ss.core.util.apiutil.validate_and_configure_for_network", return_value=True)
    app = create_app()
    return app

test_api.py

class TestPing():
    def test_ping(self):
        var = NewApiController()
        ...
0

There are 0 answers