# Path: yithlibraryserver/db.py
# DEFAULT_MONGODB_HOST = 'localhost'
# DEFAULT_MONGODB_PORT = 27017
# DEFAULT_MONGODB_NAME = 'yith-library'
# DEFAULT_MONGODB_URI = 'mongodb://%s:%d/%s' % (DEFAULT_MONGODB_HOST,
#                                               DEFAULT_MONGODB_PORT,
#                                               DEFAULT_MONGODB_NAME)
# class MongoDB(object):
#     def __init__(self, db_uri=DEFAULT_MONGODB_URI,
#                  connection_factory=pymongo.Connection):
#     def get_connection(self):
#     def get_database(self):
# def get_db(request):


import unittest
from yithlibraryserver import db
        return FakeDatabase(key)


class MongoDBTests(unittest.TestCase):

    def test_uri(self):
        mdb = db.MongoDB(connection_factory=FakeConnection)

        self.assertEqual(mdb.db_uri.geturl(), db.DEFAULT_MONGODB_URI)
        self.assertEqual(mdb.database_name, db.DEFAULT_MONGODB_NAME)
        database = mdb.get_database()
        self.assertTrue(isinstance(database, FakeDatabase))
        self.assertEqual(database.name, mdb.database_name)
        self.assertFalse(database.is_authenticated)

        # full specified uri
        uri = 'mongodb://db.example.com:1111/testdb'
        mdb = db.MongoDB(uri, connection_factory=FakeConnection)
        conn = mdb.get_connection()
        database = mdb.get_database()
        self.assertEqual(mdb.db_uri.geturl(), uri)
        self.assertEqual(mdb.db_uri.hostname, 'db.example.com')
        self.assertEqual(conn.kwargs['host'], 'db.example.com')
        self.assertEqual(mdb.db_uri.port, 1111)
        self.assertEqual(conn.kwargs['port'], 1111)
        self.assertEqual(mdb.database_name, 'testdb')
        self.assertFalse(database.is_authenticated)

        # uri without path component
        uri = 'mongodb://db.example.com:1111'

# Path: yithlibraryserver/db.py
# DEFAULT_MONGODB_HOST = 'localhost'
# DEFAULT_MONGODB_PORT = 27017
# DEFAULT_MONGODB_NAME = 'yith-library'
# DEFAULT_MONGODB_URI = 'mongodb://%s:%d/%s' % (DEFAULT_MONGODB_HOST,
#                                               DEFAULT_MONGODB_PORT,
#                                               DEFAULT_MONGODB_NAME)
# class MongoDB(object):
#     def __init__(self, db_uri=DEFAULT_MONGODB_URI,
#                  connection_factory=pymongo.Connection):
#     def get_connection(self):
#     def get_database(self):
# def get_db(request):


# Path: yithlibraryserver/tests/test_db.py
import unittest
from yithlibraryserver import db

        return FakeDatabase(key)


class MongoDBTests(unittest.TestCase):

    def test_uri(self):
        mdb = db.MongoDB(connection_factory=FakeConnection)

        self.assertEqual(mdb.db_uri.geturl(), db.DEFAULT_MONGODB_URI)
        self.assertEqual(mdb.database_name, db.DEFAULT_MONGODB_NAME)
        database = mdb.get_database()
        self.assertTrue(isinstance(database, FakeDatabase))
        self.assertEqual(database.name, mdb.database_name)
        self.assertFalse(database.is_authenticated)

        # full specified uri
        uri = 'mongodb://db.example.com:1111/testdb'
        mdb = db.MongoDB(uri, connection_factory=FakeConnection)
        conn = mdb.get_connection()
        database = mdb.get_database()
        self.assertEqual(mdb.db_uri.geturl(), uri)
        self.assertEqual(mdb.db_uri.hostname, 'db.example.com')
        self.assertEqual(conn.kwargs['host'], 'db.example.com')
        self.assertEqual(mdb.db_uri.port, 1111)
        self.assertEqual(conn.kwargs['port'], 1111)
        self.assertEqual(mdb.database_name, 'testdb')
        self.assertFalse(database.is_authenticated)

        # uri without path component
        uri = 'mongodb://db.example.com:1111'

        mdb = db.MongoDB(uri, connection_factory=FakeConnection)