class MongoDBEngine(base.DBEngineBase):

    DBNAME = 'testdb'

    def tearDown(self):
        self.conn.drop_database(self.DBNAME)
        super(MongoDBEngine, self).tearDown()

    def get_connection(self):
        conf = mox.Mox().CreateMockAnything()
        conf.database_connection = 'mongodb://localhost/%s' % self.DBNAME
        self.conn = TestConnection(conf)
        self.db = self.conn.conn[self.DBNAME]
        return self.conn

    def clean_up(self):
        self.conn.clear()

    def get_sources_by_project_id(self, id):
        project = self.db.project.find_one({'_id': id})
        return list(project['source'])

    def get_sources_by_user_id(self, id):
        user = self.db.user.find_one({'_id': id})
        return list(user['source'])
Exemple #2
0
class TestBase(test_base.TestCase):

    DBNAME = 'testdb'

    def setUp(self):
        super(TestBase, self).setUp()
        self.conf = mock.Mock()
        self.conf.metering_storage_engine = 'mongodb'
        self.conf.database_connection = 'mongodb://localhost/%s' % self.DBNAME
        self.conn = TestConnection(self.conf)
        self.conn.drop_database(self.DBNAME)
        self.conn.conn[self.DBNAME]

    def tearDown(self):
        self.conn.drop_database(self.DBNAME)
        super(TestBase, self).tearDown()
Exemple #3
0
 def setUp(self):
     super(TestBase, self).setUp()
     self.conf = mock.Mock()
     self.conf.metering_storage_engine = 'mongodb'
     self.conf.database_connection = 'mongodb://localhost/%s' % self.DBNAME
     self.conn = TestConnection(self.conf)
     self.conn.drop_database(self.DBNAME)
     self.conn.conn[self.DBNAME]
 def get_connection(self):
     conf = mox.Mox().CreateMockAnything()
     conf.database_connection = 'mongodb://localhost/%s' % self.DBNAME
     self.conn = TestConnection(conf)
     self.db = self.conn.conn[self.DBNAME]
     return self.conn