# 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/authorization.py
# class AuthorizationCodes(Codes):
# 
#     collection_name = 'authorization_codes'
# 
#     def get_redirect_url(self, code, uri, state=None):
#         parameters = ['code=%s' % code]
#         if state:
#             parameters.append('state=%s' % state)
#         return '%s?%s' % (uri, '&'.join(parameters))
# 
#     def create(self, user_id, client_id, scope):
#         return super(AuthorizationCodes, self).create(user_id,
#                                                       scope=scope,
#                                                       client_id=client_id)
# 
# Path: yithlibraryserver/oauth2/authorization.py
# class AccessCodes(Codes):
# 
#     collection_name = 'access_codes'
# 
#     def create(self, user_id, grant):
#         return super(AccessCodes, self).create(user_id,
#                                                scope=grant['scope'],
#                                                client_id=grant['client_id'])
# 
# Path: yithlibraryserver/oauth2/authorization.py
# class Authorizator(object):
# 
#     def __init__(self, db, app):
#         self.db = db
#         self.app = app
#         self.auth_codes = AuthorizationCodes(db)
#         self.access_codes = AccessCodes(db)
# 
#     def is_app_authorized(self, user):
#         return self.app['_id'] in user['authorized_apps']
# 
#     def store_user_authorization(self, user):
#         self.db.users.update(
#             {'_id': user['_id']},
#             {'$addToSet': {'authorized_apps': self.app['_id']}},
#             safe=True,
#             )
# 
#     def remove_user_authorization(self, user):
#         self.db.users.update(
#             {'_id': user['_id']},
#             {'$pull': {'authorized_apps': self.app['_id']}},
#             safe=True,
#             )


from yithlibraryserver import testing
from yithlibraryserver.oauth2.authorization import AuthorizationCodes
from yithlibraryserver.oauth2.authorization import AccessCodes
from yithlibraryserver.oauth2.authorization import Authorizator
# Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Yaco Sistemas
# Copyright (C) 2012-2013 Alejandro Blanco Escudero <alejandro.b.e@gmail.com>
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.



class AuthorizationTests(testing.TestCase):

    clean_collections = ('authorization_codes', 'access_codes', 'users')

    def test_authorization_codes(self):

# 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/authorization.py
# class AuthorizationCodes(Codes):
# 
#     collection_name = 'authorization_codes'
# 
#     def get_redirect_url(self, code, uri, state=None):
#         parameters = ['code=%s' % code]
#         if state:
#             parameters.append('state=%s' % state)
#         return '%s?%s' % (uri, '&'.join(parameters))
# 
#     def create(self, user_id, client_id, scope):
#         return super(AuthorizationCodes, self).create(user_id,
#                                                       scope=scope,
#                                                       client_id=client_id)
# 
# Path: yithlibraryserver/oauth2/authorization.py
# class AccessCodes(Codes):
# 
#     collection_name = 'access_codes'
# 
#     def create(self, user_id, grant):
#         return super(AccessCodes, self).create(user_id,
#                                                scope=grant['scope'],
#                                                client_id=grant['client_id'])
# 
# Path: yithlibraryserver/oauth2/authorization.py
# class Authorizator(object):
# 
#     def __init__(self, db, app):
#         self.db = db
#         self.app = app
#         self.auth_codes = AuthorizationCodes(db)
#         self.access_codes = AccessCodes(db)
# 
#     def is_app_authorized(self, user):
#         return self.app['_id'] in user['authorized_apps']
# 
#     def store_user_authorization(self, user):
#         self.db.users.update(
#             {'_id': user['_id']},
#             {'$addToSet': {'authorized_apps': self.app['_id']}},
#             safe=True,
#             )
# 
#     def remove_user_authorization(self, user):
#         self.db.users.update(
#             {'_id': user['_id']},
#             {'$pull': {'authorized_apps': self.app['_id']}},
#             safe=True,
#             )


# Path: yithlibraryserver/oauth2/tests/test_authorization.py
from yithlibraryserver import testing
from yithlibraryserver.oauth2.authorization import AuthorizationCodes
from yithlibraryserver.oauth2.authorization import AccessCodes
from yithlibraryserver.oauth2.authorization import Authorizator

# Yith Library Server is a password storage server.
# Copyright (C) 2012-2013 Yaco Sistemas
# Copyright (C) 2012-2013 Alejandro Blanco Escudero <alejandro.b.e@gmail.com>
# Copyright (C) 2012-2013 Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Yith Library Server.
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.



class AuthorizationTests(testing.TestCase):

    clean_collections = ('authorization_codes', 'access_codes', 'users')

    def test_authorization_codes(self):

        codes = AuthorizationCodes(self.db)