def create_app(self): try: #app = super(OAuth2ProviderTestCase, self).create_app() #app = api.create_app() app = factory.create_app('adsws.modules.oauth2server', SQLALCHEMY_DATABASE_URI='sqlite://', TESTING = True, LOGIN_DISABLED = False, # necessary to exercise flask_login+oauth2 WTF_CSRF_ENABLED = False, DEBUG=False, SQLALCHEMY_ECHO = False, SITE_SECURE_URL='http://localhost', EXTENSIONS=['adsws.ext.template', 'adsws.ext.sqlalchemy', 'adsws.ext.mail', 'adsws.ext.menu', 'adsws.ext.security'], PACKAGES=['adsws.modules.oauth2server']) app.testing = True app.config.update(dict( OAUTH2_CACHE_TYPE='simple', )) client = create_client(app, 'oauth2test') client.http_request = MagicMock( side_effect=self.patch_request(app) ) db.create_all(app=app) return app except Exception as e: print(e) raise
def create_app(self): try: #app = super(OAuth2ProviderTestCase, self).create_app() #app = api.create_app() app = factory.create_app( 'adsws.modules.oauth2server', SQLALCHEMY_DATABASE_URI='sqlite://', TESTING=True, LOGIN_DISABLED=False, # necessary to exercise flask_login+oauth2 WTF_CSRF_ENABLED=False, DEBUG=False, SQLALCHEMY_ECHO=False, SITE_SECURE_URL='http://localhost', EXTENSIONS=[ 'adsws.ext.template', 'adsws.ext.sqlalchemy', 'adsws.ext.mail', 'adsws.ext.menu', 'adsws.ext.security' ], PACKAGES=['adsws.modules.oauth2server']) app.testing = True app.config.update(dict(OAUTH2_CACHE_TYPE='simple', )) client = create_client(app, 'oauth2test') client.http_request = MagicMock( side_effect=self.patch_request(app)) db.create_all(app=app) return app except Exception as e: print(e) raise
def setUp(self): db.create_all(app=self.app) self.bootstrap_user = user_manipulator.create( email=self.app.config['BOOTSTRAP_USER_EMAIL'], password='******', active=True) self.real_user = user_manipulator.create( email='real_user@unittests', password='******', active=True, ) self.passwords = { self.bootstrap_user: '******', self.real_user: '******', }
def setUp(self): db.create_all(app=self.app) self.bootstrap_user = user_manipulator.create( email=self.app.config['BOOTSTRAP_USER_EMAIL'], password='******', active=True ) self.real_user = user_manipulator.create( email='real_user@unittests', password='******', active=True, ) self.passwords = { self.bootstrap_user:'******', self.real_user: '******', }
def setUp(self): @self.app.route('/postlogin') def username(): if current_user.is_authenticated(): return current_user.email return u'Anonymous' @self.app.errorhandler(404) def handle_404(e): raise e db.create_all(app=self.app) FlaskAppTestCase.setUp(self) user = user_manipulator.create(email='montysolr', password='******', active=True) self.user = user from adsws.modules.oauth2server.models import OAuthClient, Scope, OAuthToken from adsws.modules.oauth2server.registry import scopes as scopes_registry # Register a test scope scopes_registry.register(Scope('adsws:internal')) self.base_url = self.app.config.get('SITE_SECURE_URL') # create a client in the database c1 = OAuthClient( client_id='bumblebee', client_secret='client secret', name='bumblebee', description='', is_confidential=False, user_id=user.id, _redirect_uris='%s/client/authorized' % self.base_url, _default_scopes="adsws:internal", ratelimit=1.0 ) db.session.add(c1) db.session.commit() self.oauth = OAuth(self.app) # have the remote app ready self.authenticate()
def setUp(self): """ Sets up all of the users, clients, and tokens that management commands will run against. """ db.create_all(app=self.app) now = datetime.datetime.now() delta = datetime.timedelta times = [ now, now-delta(seconds=3), now+delta(seconds=3), now+delta(hours=1), ] self.times = times # Save for comparisons in the tests # This is a user that has registered but not confirmed their account u = user_manipulator.create( email="unconfirmed@unittest", registered_at=now+delta(seconds=1), ) db.session.add(u) # This is a user that has registered but not confirmed their account, # and furthermore will not have a registered_at attribute set u = user_manipulator.create( email="blankuser@unittest", ) db.session.add(u) # This is a user that has registered and confirmed their account u = user_manipulator.create( email="user@unittest", registered_at=now, confirmed_at=now, ) db.session.add(u) for _time in times: client = OAuthClient( user_id=u.id, client_id=gen_salt(20), client_secret=gen_salt(20), is_confidential=False, is_internal=True, _default_scopes="", last_activity=_time, ) db.session.add(client) token = OAuthToken( client_id=client.client_id, user_id=u.id, access_token=gen_salt(20), refresh_token=gen_salt(20), expires=_time, _scopes="", is_personal=False, is_internal=True, ) db.session.add(token) # Add a client without a last_activity to verify that the cleanup # scripts do not break under this condition client = OAuthClient( user_id=u.id, client_id=gen_salt(20), client_secret=gen_salt(20), is_confidential=False, is_internal=True, _default_scopes="", ) db.session.add(client) # Add a token without an expiry to verify that the cleanup scripts # do not break under this condition token = OAuthToken( client_id=client.client_id, user_id=u.id, access_token=gen_salt(20), refresh_token=gen_salt(20), _scopes="", is_personal=False, is_internal=True, ) db.session.add(token) db.session.commit()
def setUp(self): db.create_all(app=self.app)