# 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/contributions/email.py
# def send_thankyou_email(request, donation):
#     return send_email(
#         request,
#         'yithlibraryserver.contributions:templates/email_thankyou',
#         donation,
#         'Thanks for your contribution!',
#         [donation['email']],
#     )
# 
# Path: yithlibraryserver/contributions/email.py
# def send_notification_to_admins(request, donation):
#     context = {
#         'home_link': request.route_url('home'),
#     }
#     context.update(donation)
#     return send_email_to_admins(
#         request,
#         'yithlibraryserver.contributions:templates/email_admin_notification',
#         context,
#         'A new donation was received!',
#     )


import datetime
from pyramid import testing
from pyramid_mailer import get_mailer
from yithlibraryserver.testing import TestCase
from yithlibraryserver.contributions.email import send_thankyou_email
from yithlibraryserver.contributions.email import send_notification_to_admins
    def setUp(self):
        self.admin_emails = ['admin1@example.com', 'admin2@example.com']
        self.config = testing.setUp(settings={
                'admin_emails': self.admin_emails,
                })
        self.config.include('pyramid_mailer.testing')
        self.config.include('yithlibraryserver')
        super(SendEmailTests, self).setUp()

    def test_send_thankyou_email(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        self.assertEqual(len(mailer.outbox), 0)

        donation = {
            'amount': 10,
            'firstname': 'John',
            'lastname': 'Doe',
            'city': 'Springfield',
            'country': 'Exampleland',
            'state': 'Example',
            'street': 'Main Street 10',
            'zip': '12345678',
            'email': 'john@example.com',
            'creation': datetime.datetime.utcnow(),
            'send_sticker': True,
        }
        send_thankyou_email(request, donation)


# 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/contributions/email.py
# def send_thankyou_email(request, donation):
#     return send_email(
#         request,
#         'yithlibraryserver.contributions:templates/email_thankyou',
#         donation,
#         'Thanks for your contribution!',
#         [donation['email']],
#     )
# 
# Path: yithlibraryserver/contributions/email.py
# def send_notification_to_admins(request, donation):
#     context = {
#         'home_link': request.route_url('home'),
#     }
#     context.update(donation)
#     return send_email_to_admins(
#         request,
#         'yithlibraryserver.contributions:templates/email_admin_notification',
#         context,
#         'A new donation was received!',
#     )


# Path: yithlibraryserver/contributions/tests/test_email.py
import datetime
from pyramid import testing
from pyramid_mailer import get_mailer
from yithlibraryserver.testing import TestCase
from yithlibraryserver.contributions.email import send_thankyou_email
from yithlibraryserver.contributions.email import send_notification_to_admins

    def setUp(self):
        self.admin_emails = ['admin1@example.com', 'admin2@example.com']
        self.config = testing.setUp(settings={
                'admin_emails': self.admin_emails,
                })
        self.config.include('pyramid_mailer.testing')
        self.config.include('yithlibraryserver')
        super(SendEmailTests, self).setUp()

    def test_send_thankyou_email(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        self.assertEqual(len(mailer.outbox), 0)

        donation = {
            'amount': 10,
            'firstname': 'John',
            'lastname': 'Doe',
            'city': 'Springfield',
            'country': 'Exampleland',
            'state': 'Example',
            'street': 'Main Street 10',
            'zip': '12345678',
            'email': 'john@example.com',
            'creation': datetime.datetime.utcnow(),
            'send_sticker': True,
        }
        send_thankyou_email(request, donation)


        self.assertEqual(len(mailer.outbox), 1)