Exemplo n.º 1
0
 def create_oauth_credentials(self):
     client = Client(**client_data())
     client._default_scopes = 'email'
     client.client_id = 'abcd'
     client.client_secret = 'abcd'
     with self.app.app_context():
         user = User.query.get(1)
         client.user = user
         db.session.add(client)
         db.session.commit()
Exemplo n.º 2
0
def create_test_objects():
    if not test_objects:
        json_header = {'Content-Type': 'application/json'}
        app = create_app(
            settings_override={'SQLALCHEMY_DATABASE_URI': "sqlite://"})
        app.config['TESTING'] = True
        app.config['LOGIN_DISABLED'] = True

        with app.app_context():
            recreate_db(db)

        client = Client(**client_data())
        client._default_scopes = 'email'
        client.client_id = 'abcd'
        client.client_secret = 'abcd'
        with app.app_context():
            user = User.query.get(1)
            client.user = user
            db.session.add(client)
            db.session.commit()
        app.login_manager.init_app(app)
        app_client = app.test_client()
        rv = app_client.post('/passport/api/v1/auth/token',
                             data={
                                 'grant_type': 'client_credentials',
                                 'client_id': 'abcd',
                                 'client_secret': 'abcd',
                             })
        response = json.loads(rv.data)
        header = {
            'Authorization': 'Bearer {0}'.format(response['access_token'])
        }
        json_header.update(header)
        test_objects['header'] = header
        test_objects['json_header'] = json_header
        test_objects['app'] = app
        test_objects['client'] = app_client
    return test_objects