# Path: yithlibraryserver/i18n.py
# def deform_translator(term):
#     return get_localizer(get_current_request()).translate(term)
# 
# def locale_negotiator(request):
#     available_languages = request.registry.settings['available_languages']
#     return request.accept_language.best_match(available_languages)
# 
# Path: yithlibraryserver/testing.py
# class TestCase(unittest.TestCase):
# 
#     clean_collections = tuple()
# 
#     def setUp(self):
#         settings = {
#             'mongo_uri': MONGO_URI,
#             'auth_tk_secret': '123456',
#             'twitter_consumer_key': 'key',
#             'twitter_consumer_secret': 'secret',
#             'facebook_app_id': 'id',
#             'facebook_app_secret': 'secret',
#             'google_client_id': 'id',
#             'google_client_secret': 'secret',
#             'paypal_user': 'sdk-three_api1.sdk.com',
#             'paypal_password': 'QFZCWN5HZM8VBG7Q',
#             'paypal_signature': 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
#             'testing': 'True',
#             'pyramid_mailer.prefix': 'mail_',
#             'mail_default_sender': 'no-reply@yithlibrary.com',
#             'admin_emails': 'admin1@example.com admin2@example.com',
#             'public_url_root': 'http://localhost:6543/',
#             }
#         app = main({}, **settings)
#         self.testapp = TestApp(app)
#         self.db = app.registry.settings['db_conn']['test-yith-library']
# 
#     def tearDown(self):
#         for col in self.clean_collections:
#             self.db.drop_collection(col)
# 
#         self.testapp.reset()
# 
#     def set_user_cookie(self, user_id):
#         request = TestRequest.blank('', {})
#         request.registry = self.testapp.app.registry
#         remember_headers = remember(request, user_id)
#         cookie_value = remember_headers[0][1].split('"')[1]
#         self.testapp.cookies['auth_tkt'] = cookie_value
# 
#     def add_to_session(self, data):
#         queryUtility = self.testapp.app.registry.queryUtility
#         session_factory = queryUtility(ISessionFactory)
#         request = DummyRequest()
#         session = session_factory(request)
#         for key, value in data.items():
#             session[key] = value
#         session.persist()
#         self.testapp.cookies['beaker.session.id'] = session._sess.id
# 
#     def get_session(self, response):
#         queryUtility = self.testapp.app.registry.queryUtility
#         session_factory = queryUtility(ISessionFactory)
#         request = response.request
# 
#         if not hasattr(request, 'add_response_callback'):
#             request.add_response_callback = lambda r: r
# 
#         if 'Set-Cookie' in response.headers:
#             request.environ['HTTP_COOKIE'] = response.headers['Set-Cookie']
# 
#         return session_factory(request)


import unittest
from webtest import TestRequest
from pyramid import testing
from yithlibraryserver.i18n import deform_translator, locale_negotiator
from yithlibraryserver.testing import TestCase
        request = testing.DummyRequest()
        testing.setUp(request=request)

    def tearDown(self):
        testing.tearDown()

    def test_deform_translator(self):
        self.assertEqual('foo', deform_translator('foo'))


class LocaleNegotiatorTests(TestCase):

    def test_locale_negotiator(self):
        request = TestRequest.blank('', {}, headers={})
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), 'en')

        request = TestRequest.blank('', {}, headers={
                'Accept-Language': 'es',
                })
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), 'es')

        request = TestRequest.blank('', {}, headers={
                'Accept-Language': 'de',  # german is not supported
                })
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), None)

        request = TestRequest.blank('', {}, headers={

# Path: yithlibraryserver/i18n.py
# def deform_translator(term):
#     return get_localizer(get_current_request()).translate(term)
# 
# def locale_negotiator(request):
#     available_languages = request.registry.settings['available_languages']
#     return request.accept_language.best_match(available_languages)
# 
# Path: yithlibraryserver/testing.py
# class TestCase(unittest.TestCase):
# 
#     clean_collections = tuple()
# 
#     def setUp(self):
#         settings = {
#             'mongo_uri': MONGO_URI,
#             'auth_tk_secret': '123456',
#             'twitter_consumer_key': 'key',
#             'twitter_consumer_secret': 'secret',
#             'facebook_app_id': 'id',
#             'facebook_app_secret': 'secret',
#             'google_client_id': 'id',
#             'google_client_secret': 'secret',
#             'paypal_user': 'sdk-three_api1.sdk.com',
#             'paypal_password': 'QFZCWN5HZM8VBG7Q',
#             'paypal_signature': 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',
#             'testing': 'True',
#             'pyramid_mailer.prefix': 'mail_',
#             'mail_default_sender': 'no-reply@yithlibrary.com',
#             'admin_emails': 'admin1@example.com admin2@example.com',
#             'public_url_root': 'http://localhost:6543/',
#             }
#         app = main({}, **settings)
#         self.testapp = TestApp(app)
#         self.db = app.registry.settings['db_conn']['test-yith-library']
# 
#     def tearDown(self):
#         for col in self.clean_collections:
#             self.db.drop_collection(col)
# 
#         self.testapp.reset()
# 
#     def set_user_cookie(self, user_id):
#         request = TestRequest.blank('', {})
#         request.registry = self.testapp.app.registry
#         remember_headers = remember(request, user_id)
#         cookie_value = remember_headers[0][1].split('"')[1]
#         self.testapp.cookies['auth_tkt'] = cookie_value
# 
#     def add_to_session(self, data):
#         queryUtility = self.testapp.app.registry.queryUtility
#         session_factory = queryUtility(ISessionFactory)
#         request = DummyRequest()
#         session = session_factory(request)
#         for key, value in data.items():
#             session[key] = value
#         session.persist()
#         self.testapp.cookies['beaker.session.id'] = session._sess.id
# 
#     def get_session(self, response):
#         queryUtility = self.testapp.app.registry.queryUtility
#         session_factory = queryUtility(ISessionFactory)
#         request = response.request
# 
#         if not hasattr(request, 'add_response_callback'):
#             request.add_response_callback = lambda r: r
# 
#         if 'Set-Cookie' in response.headers:
#             request.environ['HTTP_COOKIE'] = response.headers['Set-Cookie']
# 
#         return session_factory(request)


# Path: yithlibraryserver/tests/test_i18n.py
import unittest
from webtest import TestRequest
from pyramid import testing
from yithlibraryserver.i18n import deform_translator, locale_negotiator
from yithlibraryserver.testing import TestCase

        request = testing.DummyRequest()
        testing.setUp(request=request)

    def tearDown(self):
        testing.tearDown()

    def test_deform_translator(self):
        self.assertEqual('foo', deform_translator('foo'))


class LocaleNegotiatorTests(TestCase):

    def test_locale_negotiator(self):
        request = TestRequest.blank('', {}, headers={})
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), 'en')

        request = TestRequest.blank('', {}, headers={
                'Accept-Language': 'es',
                })
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), 'es')

        request = TestRequest.blank('', {}, headers={
                'Accept-Language': 'de',  # german is not supported
                })
        request.registry = self.testapp.app.registry
        self.assertEqual(locale_negotiator(request), None)

        request = TestRequest.blank('', {}, headers={

                'Accept-Language': 'de, es',