예제 #1
0
 def get_connection(self):
     conf = mox.Mox().CreateMockAnything()
     conf.database_connection = 'mongodb://localhost/%s' % self.DBNAME
     self.conn = TestConnection(conf)
     self.conn.drop_database(self.DBNAME)
     self.db = self.conn.conn[self.DBNAME]
     return self.conn
예제 #2
0
class MongoDBEngine(base.DBEngineBase):

    DBNAME = 'testdb'

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

    def clean_up(self):
        self.conn.drop_database(self.DBNAME)

    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'])
예제 #3
0
    def setUp(self):
        super(MongoDBEngineTestBase, self).setUp()

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

        self.counter = counter.Counter(
            'instance',
            counter.TYPE_CUMULATIVE,
            1,
            'user-id',
            'project-id',
            'resource-id',
            timestamp=datetime.datetime(2012, 7, 2, 10, 40),
            resource_metadata={'display_name': 'test-server',
                               'tag': 'self.counter',
                               }
            )
        self.msg = meter.meter_message_from_counter(self.counter,
                                                    'not-so-secret',
                                                    'test-1')
        self.conn.record_metering_data(self.msg)

        self.counter2 = counter.Counter(
            'instance',
            counter.TYPE_CUMULATIVE,
            1,
            'user-id',
            'project-id',
            'resource-id-alternate',
            timestamp=datetime.datetime(2012, 7, 2, 10, 41),
            resource_metadata={'display_name': 'test-server',
                               'tag': 'self.counter2',
                               }
            )
        self.msg2 = meter.meter_message_from_counter(self.counter2,
                                                     'not-so-secret',
                                                     'test-2')
        self.conn.record_metering_data(self.msg2)

        self.counter3 = counter.Counter(
            'instance',
            counter.TYPE_CUMULATIVE,
            1,
            'user-id-alternate',
            'project-id',
            'resource-id-alternate',
            timestamp=datetime.datetime(2012, 7, 2, 10, 41),
            resource_metadata={'display_name': 'test-server',
                               'tag': 'self.counter3',
                               }
            )
        self.msg3 = meter.meter_message_from_counter(self.counter3,
                                                     'not-so-secret',
                                                     'test-3')
        self.conn.record_metering_data(self.msg3)

        for i in range(2, 4):
            c = counter.Counter(
                'instance',
                counter.TYPE_CUMULATIVE,
                1,
                'user-id-%s' % i,
                'project-id-%s' % i,
                'resource-id-%s' % i,
                timestamp=datetime.datetime(2012, 7, 2, 10, 40 + i),
                resource_metadata={'display_name': 'test-server',
                                   'tag': 'counter-%s' % i,
                                   }
                )
            msg = meter.meter_message_from_counter(c, 'not-so-secret', 'test')
            self.conn.record_metering_data(msg)