# 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
        location = 'https://example.com/callback?code=%s' % code
        self.assertEqual(res.location, location)

    def test_token_endpoint(self):
        # 1. test incorrect requests
        res = self.testapp.post('/oauth2/endpoints/token', {}, status=401)
        self.assertEqual(res.status, '401 Unauthorized')

        headers = {
            'Authorization': auth_basic_encode('123456', 'secret'),
            }

        res = self.testapp.post('/oauth2/endpoints/token', {}, headers=headers, status=401)
        self.assertEqual(res.status, '401 Unauthorized')

        app_id = self.db.applications.insert({
                'client_id': '123456',
                'client_secret': 'secret',
                'callback_url': 'https://example.com/callback',
                'name': 'Example',
                'main_url': 'https://example.com',
                }, safe=True)

        res = self.testapp.post('/oauth2/endpoints/token', {}, headers=headers, status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('Missing required grant_type')

        res = self.testapp.post('/oauth2/endpoints/token', {
                'grant_type': 'password'
                }, headers=headers, status=501)

# 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

        location = 'https://example.com/callback?code=%s' % code
        self.assertEqual(res.location, location)

    def test_token_endpoint(self):
        # 1. test incorrect requests
        res = self.testapp.post('/oauth2/endpoints/token', {}, status=401)
        self.assertEqual(res.status, '401 Unauthorized')

        headers = {
            'Authorization': auth_basic_encode('123456', 'secret'),
            }

        res = self.testapp.post('/oauth2/endpoints/token', {}, headers=headers, status=401)
        self.assertEqual(res.status, '401 Unauthorized')

        app_id = self.db.applications.insert({
                'client_id': '123456',
                'client_secret': 'secret',
                'callback_url': 'https://example.com/callback',
                'name': 'Example',
                'main_url': 'https://example.com',
                }, safe=True)

        res = self.testapp.post('/oauth2/endpoints/token', {}, headers=headers, status=400)
        self.assertEqual(res.status, '400 Bad Request')
        res.mustcontain('Missing required grant_type')

        res = self.testapp.post('/oauth2/endpoints/token', {
                'grant_type': 'password'
                }, headers=headers, status=501)

        self.assertEqual(res.status, '501 Not Implemented')