Closed MordiGrip closed 3 years ago
Unfortunately it is not possible with the current pytest setup. The reason is because the current tests does not test any flask integration so the but could not be reproduce. I did wrote the minimum flask app to reproduce the bug:
import flask
from flask_cognito import CognitoAuth, cognito_auth_required, cognito_group_permissions
app = flask.Flask(__name__)
app.config["COGNITO_REGION"] = "<COGNITO_REGION>"
app.config["COGNITO_USERPOOL_ID"] = "<COGNITO_USERPOOL_ID>"
app.config["COGNITO_APP_CLIENT_ID"] = "<COGNITO_APP_CLIENT_ID>"
cogauth = CognitoAuth(app)
cogauth.init_app(app)
@app.route("/route-a")
@cognito_auth_required
@cognito_group_permissions(["Group"])
def route_a():
return "Route A"
@app.route("/route-b")
@cognito_auth_required
@cognito_group_permissions(["Group"])
def route_b():
return "Route B"
app.run()
Running this flask app will raise the following error:
$ python test.py
Traceback (most recent call last):
File "/home/mordi/projects/flask_cognito/test.py", line 23, in <module>
def route_b():
File "/home/mordi/anaconda3/envs/py39/lib/python3.9/site-packages/flask/app.py", line 1315, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/home/mordi/anaconda3/envs/py39/lib/python3.9/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/home/mordi/anaconda3/envs/py39/lib/python3.9/site-packages/flask/app.py", line 1282, in add_url_rule
raise AssertionError(
AssertionError: View function mapping is overwriting an existing endpoint function: wrapper
If you wish to have a test in pytest for this I suggest you use the FlaskClient
from flask.testing
to fully test the integration of this lib with flask.
(sorry I don't have enough time to add it my self)
No worries, thanks for the fix 🙏🏻 !
Thanks!
Thanks! Would it be possible at all to add a test for what this fixes?