# Path: yithlibraryserver/db.py
# class MongoDB(object):
#     """Simple wrapper to get pymongo real objects from the settings uri"""
# 
#     def __init__(self, db_uri=DEFAULT_MONGODB_URI,
#                  connection_factory=pymongo.Connection):
#         self.db_uri = urlparse.urlparse(db_uri)
#         self.connection = connection_factory(
#             host=self.db_uri.hostname or DEFAULT_MONGODB_HOST,
#             port=self.db_uri.port or DEFAULT_MONGODB_PORT,
#             tz_aware=True)
# 
#         if self.db_uri.path:
#             self.database_name = self.db_uri.path[1:]
#         else:
#             self.database_name = DEFAULT_MONGODB_NAME
# 
#     def get_connection(self):
#         return self.connection
# 
#     def get_database(self):
#         database = self.connection[self.database_name]
#         if self.db_uri.username and self.db_uri.password:
#             database.authenticate(self.db_uri.username, self.db_uri.password)
# 
#         return database
# 
# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'


import os
import unittest
import tempfile
from yithlibraryserver.db import MongoDB
from yithlibraryserver.testing import MONGO_URI
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.



CONFIG = """[app:main]
use = egg:yith-library-server
mongo_uri = %s
auth_tk_secret = 123456
testing = True
pyramid_mailer.prefix = mail_
mail_default_sender = no-reply@yithlibrary.com
admin_emails = admin1@example.com admin2@example.com

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 65432
""" % MONGO_URI


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'))

# Path: yithlibraryserver/db.py
# class MongoDB(object):
#     """Simple wrapper to get pymongo real objects from the settings uri"""
# 
#     def __init__(self, db_uri=DEFAULT_MONGODB_URI,
#                  connection_factory=pymongo.Connection):
#         self.db_uri = urlparse.urlparse(db_uri)
#         self.connection = connection_factory(
#             host=self.db_uri.hostname or DEFAULT_MONGODB_HOST,
#             port=self.db_uri.port or DEFAULT_MONGODB_PORT,
#             tz_aware=True)
# 
#         if self.db_uri.path:
#             self.database_name = self.db_uri.path[1:]
#         else:
#             self.database_name = DEFAULT_MONGODB_NAME
# 
#     def get_connection(self):
#         return self.connection
# 
#     def get_database(self):
#         database = self.connection[self.database_name]
#         if self.db_uri.username and self.db_uri.password:
#             database.authenticate(self.db_uri.username, self.db_uri.password)
# 
#         return database
# 
# Path: yithlibraryserver/testing.py
# MONGO_URI = 'mongodb://localhost:27017/test-yith-library'


# Path: yithlibraryserver/scripts/testing.py
import os
import unittest
import tempfile
from yithlibraryserver.db import MongoDB
from yithlibraryserver.testing import MONGO_URI

# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.



CONFIG = """[app:main]
use = egg:yith-library-server
mongo_uri = %s
auth_tk_secret = 123456
testing = True
pyramid_mailer.prefix = mail_
mail_default_sender = no-reply@yithlibrary.com
admin_emails = admin1@example.com admin2@example.com

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 65432
""" % MONGO_URI


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)