# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/scripts/announce.py
# def announce():
#     usage = "migrate: %prog config_uri migration_name"
#     description = "Add a 'send_email_periodically' preference to every user."
#     parser = optparse.OptionParser(
#         usage=usage,
#         description=textwrap.dedent(description)
#         )
#     options, args = parser.parse_args(sys.argv[1:])
#     if len(args) != 2:
#         safe_print('You must provide two arguments. '
#                    'The first one is the config file and the '
#                    'second one is the email template.')
#         return 2
#     config_uri = args[0]
#     email_template = args[1]
#     env = bootstrap(config_uri)
#     settings, closer = env['registry'].settings, env['closer']
# 
#     try:
# 
#         db = settings['mongodb'].get_database()
#         request = env['request']
# 
#         public_url_root = settings['public_url_root']
#         preferences_link = urlparse.urljoin(
#             public_url_root,
#             request.route_path('user_preferences'))
# 
#         tx = transaction.begin()
# 
#         mailer = get_mailer(request)
# 
#         for user in get_all_users_with_passwords_and_email(db):
#             message = send_email(request, email_template, user,
#                                  preferences_link)
#             mailer.send(message)
# 
#         tx.commit()
# 
#     finally:
#         closer()
# 
# Path: yithlibraryserver/scripts/testing.py
# class ScriptTests(unittest.TestCase):
# 
#     clean_collections = tuple()
# 
#     def setUp(self):
#         super(ScriptTests, self).setUp()
# 
#         fd, self.conf_file_path = tempfile.mkstemp()
#         os.write(fd, CONFIG.encode('ascii'))
#         mdb = MongoDB(MONGO_URI)
#         self.db = mdb.get_database()
# 
#     def tearDown(self):
#         super(ScriptTests, self).tearDown()
#         os.unlink(self.conf_file_path)
#         for col in self.clean_collections:
#             self.db.drop_collection(col)
# 
#     def add_passwords(self, user, n):
#         for i in range(n):
#             self.db.passwords.insert({
#                     'service': 'service-%d' % (i + 1),
#                     'secret': 's3cr3t',
#                     'owner': user,
#                     })
#         return user


import sys
from yithlibraryserver.compat import StringIO
from yithlibraryserver.scripts.announce import announce
from yithlibraryserver.scripts.testing import ScriptTests
        self.add_passwords(self.db.users.insert({
                    'first_name': 'John2',
                    'last_name': 'Doe',
                    'email': 'john2@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': False,
                    }), 10)
        self.add_passwords(self.db.users.insert({
                    'first_name': 'John3',
                    'last_name': 'Doe',
                    'email': 'john3@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': True,
                    }), 10)
        self.add_passwords(self.db.users.insert({
                    'first_name': 'John4',
                    'last_name': 'Doe',
                    'email': 'john4@example.com',
                    'email_verified': False,
                    'send_passwords_periodically': True,
                    }), 10)
        self.db.users.insert({
                    'first_name': 'John4',
                    'last_name': 'Doe',
                    'email': 'john4@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': True,
                    })

        sys.argv = ['notused', self.conf_file_path, 'new_feature_send_passwords_via_email']

# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/scripts/announce.py
# def announce():
#     usage = "migrate: %prog config_uri migration_name"
#     description = "Add a 'send_email_periodically' preference to every user."
#     parser = optparse.OptionParser(
#         usage=usage,
#         description=textwrap.dedent(description)
#         )
#     options, args = parser.parse_args(sys.argv[1:])
#     if len(args) != 2:
#         safe_print('You must provide two arguments. '
#                    'The first one is the config file and the '
#                    'second one is the email template.')
#         return 2
#     config_uri = args[0]
#     email_template = args[1]
#     env = bootstrap(config_uri)
#     settings, closer = env['registry'].settings, env['closer']
# 
#     try:
# 
#         db = settings['mongodb'].get_database()
#         request = env['request']
# 
#         public_url_root = settings['public_url_root']
#         preferences_link = urlparse.urljoin(
#             public_url_root,
#             request.route_path('user_preferences'))
# 
#         tx = transaction.begin()
# 
#         mailer = get_mailer(request)
# 
#         for user in get_all_users_with_passwords_and_email(db):
#             message = send_email(request, email_template, user,
#                                  preferences_link)
#             mailer.send(message)
# 
#         tx.commit()
# 
#     finally:
#         closer()
# 
# Path: yithlibraryserver/scripts/testing.py
# class ScriptTests(unittest.TestCase):
# 
#     clean_collections = tuple()
# 
#     def setUp(self):
#         super(ScriptTests, self).setUp()
# 
#         fd, self.conf_file_path = tempfile.mkstemp()
#         os.write(fd, CONFIG.encode('ascii'))
#         mdb = MongoDB(MONGO_URI)
#         self.db = mdb.get_database()
# 
#     def tearDown(self):
#         super(ScriptTests, self).tearDown()
#         os.unlink(self.conf_file_path)
#         for col in self.clean_collections:
#             self.db.drop_collection(col)
# 
#     def add_passwords(self, user, n):
#         for i in range(n):
#             self.db.passwords.insert({
#                     'service': 'service-%d' % (i + 1),
#                     'secret': 's3cr3t',
#                     'owner': user,
#                     })
#         return user


# Path: yithlibraryserver/scripts/tests/test_announce.py
import sys
from yithlibraryserver.compat import StringIO
from yithlibraryserver.scripts.announce import announce
from yithlibraryserver.scripts.testing import ScriptTests

        self.add_passwords(self.db.users.insert({
                    'first_name': 'John2',
                    'last_name': 'Doe',
                    'email': 'john2@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': False,
                    }), 10)
        self.add_passwords(self.db.users.insert({
                    'first_name': 'John3',
                    'last_name': 'Doe',
                    'email': 'john3@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': True,
                    }), 10)
        self.add_passwords(self.db.users.insert({
                    'first_name': 'John4',
                    'last_name': 'Doe',
                    'email': 'john4@example.com',
                    'email_verified': False,
                    'send_passwords_periodically': True,
                    }), 10)
        self.db.users.insert({
                    'first_name': 'John4',
                    'last_name': 'Doe',
                    'email': 'john4@example.com',
                    'email_verified': True,
                    'send_passwords_periodically': True,
                    })

        sys.argv = ['notused', self.conf_file_path, 'new_feature_send_passwords_via_email']

        sys.stdout = StringIO()