Flask OpenID unittest Flask OpenID unittest flask flask

Flask OpenID unittest


There is an alternative - monkey-patch the open-id extension's try_login method:

class LoginTestMonkeyPatch(object):    def __init__(self, oid=None, default_response=None):        self.response = default_response        if oid is not None:            self.init(oid)    def init(self, oid):        oid.try_login = self.try_login    def try_login(self, *args, **kwargs):        # Do whatever you want to do here


If you are patching the login, you may not be testing it.

I had the same problem. For me the best solution was to disable the "log in required" part of the view.

I don't know if you are using Flask Login, but if you are you can bypass the @login_required so that you don't even need to worry about trying to login the user with something like:

def setUp   env = Environments(app)   env.from_object('config.Testing')   lm = LoginManager()   lm.init_app(app)   self.app = app.test_client()

Just a thought, I hope this helps you or someone else :)

P.S. This is my first post on Stack Overflow. Thanks to all the many posters that have helped me so much!