# Path: yithlibraryserver/backups/utils.py
# def get_user_passwords(db, user):
#     passwords_manager = PasswordsManager(db)
#     return [remove_attrs(password, 'owner', '_id')
#             for password in passwords_manager.retrieve(user)]
# 
# Path: yithlibraryserver/backups/utils.py
# def get_backup_filename(date):
#     return 'yith-library-backup-%d-%02d-%02d.yith' % (
#         date.year, date.month, date.day)
# 
# Path: yithlibraryserver/backups/utils.py
# def compress(passwords):
#     buf = BytesIO()
#     gzip_data = gzip.GzipFile(fileobj=buf, mode='wb')
#     data = json.dumps(passwords)
#     gzip_data.write(data.encode('utf-8'))
#     gzip_data.close()
#     return buf.getvalue()
# 
# def uncompress(compressed_data):
#     buf = BytesIO(compressed_data)
#     gzip_data = gzip.GzipFile(fileobj=buf, mode='rb')
#     raw_data = gzip_data.read()
#     return json.loads(raw_data.decode('utf-8'))
# 
# 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 datetime
from yithlibraryserver.backups.utils import get_user_passwords
from yithlibraryserver.backups.utils import get_backup_filename
from yithlibraryserver.backups.utils import compress, uncompress
from yithlibraryserver.testing import TestCase

    clean_collections = ('users', 'passwords', )

    def test_get_user_passwords(self):
        user_id = self.db.users.insert({
                'first_name': 'John',
                'last_name': 'Doe',
                }, safe=True)
        user = self.db.users.find_one({'_id': user_id})

        self.assertEqual(get_user_passwords(self.db, user), [])

        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret1',
                })
        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret2',
                })

        self.assertEqual(get_user_passwords(self.db, user), [{
                    'password': 'secret1',
                    } ,{
                    'password': 'secret2',
                    }])

    def test_get_backup_filename(self):
        self.assertEqual(get_backup_filename(datetime.date(2012, 10, 28)),
                         'yith-library-backup-2012-10-28.yith')

# Path: yithlibraryserver/backups/utils.py
# def get_user_passwords(db, user):
#     passwords_manager = PasswordsManager(db)
#     return [remove_attrs(password, 'owner', '_id')
#             for password in passwords_manager.retrieve(user)]
# 
# Path: yithlibraryserver/backups/utils.py
# def get_backup_filename(date):
#     return 'yith-library-backup-%d-%02d-%02d.yith' % (
#         date.year, date.month, date.day)
# 
# Path: yithlibraryserver/backups/utils.py
# def compress(passwords):
#     buf = BytesIO()
#     gzip_data = gzip.GzipFile(fileobj=buf, mode='wb')
#     data = json.dumps(passwords)
#     gzip_data.write(data.encode('utf-8'))
#     gzip_data.close()
#     return buf.getvalue()
# 
# def uncompress(compressed_data):
#     buf = BytesIO(compressed_data)
#     gzip_data = gzip.GzipFile(fileobj=buf, mode='rb')
#     raw_data = gzip_data.read()
#     return json.loads(raw_data.decode('utf-8'))
# 
# 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/backups/tests/test_utils.py
import datetime
from yithlibraryserver.backups.utils import get_user_passwords
from yithlibraryserver.backups.utils import get_backup_filename
from yithlibraryserver.backups.utils import compress, uncompress
from yithlibraryserver.testing import TestCase


    clean_collections = ('users', 'passwords', )

    def test_get_user_passwords(self):
        user_id = self.db.users.insert({
                'first_name': 'John',
                'last_name': 'Doe',
                }, safe=True)
        user = self.db.users.find_one({'_id': user_id})

        self.assertEqual(get_user_passwords(self.db, user), [])

        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret1',
                })
        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret2',
                })

        self.assertEqual(get_user_passwords(self.db, user), [{
                    'password': 'secret1',
                    } ,{
                    'password': 'secret2',
                    }])

    def test_get_backup_filename(self):
        self.assertEqual(get_backup_filename(datetime.date(2012, 10, 28)),
                         'yith-library-backup-2012-10-28.yith')

        self.assertEqual(get_backup_filename(datetime.date(2013, 1, 8)),