# 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
import os
import bson
from mock import patch
from pyramid_mailer import get_mailer
from yithlibraryserver.testing import TestCase
                    'LOCALECODE': 'ES',
                    'PAYMENTREQUEST_0_ITEMAMT': 5,
                    'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale',
                    'PAYMENTREQUEST_0_CURRENCYCODE': 'USD',
                    'PAYMENTREQUEST_0_AMT': 5,
                    'PAYMENTREQUEST_0_DESC': 'Donation',
                    'RETURNURL': 'http://localhost/contribute/paypal-success-callback',
                    'CANCELURL': 'http://localhost/contribute/paypal-cancel-callback',
                    })

    def test_contributions_confirm_error(self):
        res = self.testapp.get('/contribute/paypal-success-callback',
                               status=302)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(res.location, 'http://localhost/contribute')
        session = self.get_session(res)
        self.assertEqual(session['_f_error'], ['There was a problem in the confirmation process. Please start the checkout again'])

    def test_contributions_confirm_details(self):
        with patch('requests.post') as fake:
            fake.return_value.ok = True
            fake.return_value.text = 'ACK=Success&AMT=5.00&FIRSTNAME=John&LASTNAME=Doe&SHIPTOCITY=ExampleCity&SHIPTOCOUNTRYNAME=ExampleCountry&SHIPTOSTATE=ExampleState&SHIPTOSTREET=ExampleStreet&SHIPTOZIP=123456&EMAIL=john@example.com'
            res = self.testapp.get('/contribute/paypal-success-callback?token=123&PayerID=456')
            self.assertEqual(res.status, '200 OK')
            res.mustcontain('John', 'Doe', 'ExampleCity', 'ExampleCountry',
                            'ExampleState', 'ExampleStreet', '123456')
            fake.assert_called_with('https://api-3t.sandbox.paypal.com/nvp',
                                    data={
                    'METHOD': 'GetExpressCheckoutDetails',
                    'VERSION': '72.0',

# 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/tests/test_views.py
import datetime
import os
import bson
from mock import patch
from pyramid_mailer import get_mailer
from yithlibraryserver.testing import TestCase

                    'LOCALECODE': 'ES',
                    'PAYMENTREQUEST_0_ITEMAMT': 5,
                    'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale',
                    'PAYMENTREQUEST_0_CURRENCYCODE': 'USD',
                    'PAYMENTREQUEST_0_AMT': 5,
                    'PAYMENTREQUEST_0_DESC': 'Donation',
                    'RETURNURL': 'http://localhost/contribute/paypal-success-callback',
                    'CANCELURL': 'http://localhost/contribute/paypal-cancel-callback',
                    })

    def test_contributions_confirm_error(self):
        res = self.testapp.get('/contribute/paypal-success-callback',
                               status=302)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(res.location, 'http://localhost/contribute')
        session = self.get_session(res)
        self.assertEqual(session['_f_error'], ['There was a problem in the confirmation process. Please start the checkout again'])

    def test_contributions_confirm_details(self):
        with patch('requests.post') as fake:
            fake.return_value.ok = True
            fake.return_value.text = 'ACK=Success&AMT=5.00&FIRSTNAME=John&LASTNAME=Doe&SHIPTOCITY=ExampleCity&SHIPTOCOUNTRYNAME=ExampleCountry&SHIPTOSTATE=ExampleState&SHIPTOSTREET=ExampleStreet&SHIPTOZIP=123456&EMAIL=john@example.com'
            res = self.testapp.get('/contribute/paypal-success-callback?token=123&PayerID=456')
            self.assertEqual(res.status, '200 OK')
            res.mustcontain('John', 'Doe', 'ExampleCity', 'ExampleCountry',
                            'ExampleState', 'ExampleStreet', '123456')
            fake.assert_called_with('https://api-3t.sandbox.paypal.com/nvp',
                                    data={
                    'METHOD': 'GetExpressCheckoutDetails',
                    'VERSION': '72.0',

                    'USER': 'sdk-three_api1.sdk.com',