# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'
# class FakeRequest(DummyRequest):
# class TestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#     def setUp(self):
#     def tearDown(self):
#     def set_user_cookie(self, user_id):
#     def add_to_session(self, data):
#     def get_session(self, response):
# 
# Path: yithlibraryserver/oauth2/views.py
# DEFAULT_SCOPE = 'passwords'
# 
# Path: yithlibraryserver/oauth2/authentication.py
# def auth_basic_encode(user, password):
#     value = '%s:%s' % (user, password)
#     value = 'Basic ' + encodebytes(value.encode('utf-8')).decode('utf-8')
#     return encode_header(value)


import bson
from yithlibraryserver import testing
from yithlibraryserver.oauth2.views import DEFAULT_SCOPE
from yithlibraryserver.oauth2.authentication import auth_basic_encode

        app_id2 = self.db.applications.insert({
                'client_id': '98765',
                'client_secret': 'secret2',
                'callback_url': 'https://example.com/callback2',
                'name': 'Example2',
                'main_url': 'https://example.com',
                }, safe=True)

        user_id = self.db.users.insert({
                'twitter_id': 'twitter1',
                'screen_name': 'John Doe',
                'first_name': 'John',
                'last_name': 'Doe',
                'authorized_apps': [app_id, app_id2],
                }, safe=True)
        self.set_user_cookie(str(user_id))
        self.testapp.get('/oauth2/endpoints/authorization', {
                'response_type': 'code',
                'client_id': '123456',
                })
        grant = self.db.authorization_codes.find_one({
                'scope': DEFAULT_SCOPE,
                'client_id': '123456',
                'user': user_id,
                })
        code = grant['code']

        # Authorize with app2 credentials
        headers = {

# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'
# class FakeRequest(DummyRequest):
# class TestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#     def setUp(self):
#     def tearDown(self):
#     def set_user_cookie(self, user_id):
#     def add_to_session(self, data):
#     def get_session(self, response):
# 
# Path: yithlibraryserver/oauth2/views.py
# DEFAULT_SCOPE = 'passwords'
# 
# Path: yithlibraryserver/oauth2/authentication.py
# def auth_basic_encode(user, password):
#     value = '%s:%s' % (user, password)
#     value = 'Basic ' + encodebytes(value.encode('utf-8')).decode('utf-8')
#     return encode_header(value)


# Path: yithlibraryserver/oauth2/tests/test_views.py
import bson
from yithlibraryserver import testing
from yithlibraryserver.oauth2.views import DEFAULT_SCOPE
from yithlibraryserver.oauth2.authentication import auth_basic_encode


        app_id2 = self.db.applications.insert({
                'client_id': '98765',
                'client_secret': 'secret2',
                'callback_url': 'https://example.com/callback2',
                'name': 'Example2',
                'main_url': 'https://example.com',
                }, safe=True)

        user_id = self.db.users.insert({
                'twitter_id': 'twitter1',
                'screen_name': 'John Doe',
                'first_name': 'John',
                'last_name': 'Doe',
                'authorized_apps': [app_id, app_id2],
                }, safe=True)
        self.set_user_cookie(str(user_id))
        self.testapp.get('/oauth2/endpoints/authorization', {
                'response_type': 'code',
                'client_id': '123456',
                })
        grant = self.db.authorization_codes.find_one({
                'scope': DEFAULT_SCOPE,
                'client_id': '123456',
                'user': user_id,
                })
        code = grant['code']

        # Authorize with app2 credentials
        headers = {

            'Authorization': auth_basic_encode('98765', 'secret2'),