def _gen_container_stat(self, set_metadata=False):
        if set_metadata:
            self.conf['metadata_keys'] = 'test1,test2'
            # webob runs title on all headers
        stat = db_stats_collector.ContainerStatsCollector(self.conf)
        output_data = set()
        for i in range(10):
            cont_db = ContainerBroker("%s/container-stats-201001010%s-%s.db" %
                                      (self.containers, i, uuid.uuid4().hex),
                                      account='test_acc_%s' % i,
                                      container='test_con')
            cont_db.initialize(storage_policy_index=0)
            cont_db.put_object('test_obj', time.time(), 10, 'text', 'faketag')
            metadata_output = ''
            if set_metadata:
                if i % 2:
                    cont_db.update_metadata({'X-Container-Meta-Test1': (5, 1)})
                    metadata_output = ',1,'
                else:
                    cont_db.update_metadata({'X-Container-Meta-Test2': (7, 2)})
                    metadata_output = ',,1'
            # this will "commit" the data
            cont_db.get_info()
            output_data.add('''"test_acc_%s","test_con",1,10%s''' %
                            (i, metadata_output))

        self.assertEqual(len(output_data), 10)
        return stat, output_data
 def test_container_stat_get_data(self):
     stat = db_stats_collector.ContainerStatsCollector(self.conf)
     container_db = ContainerBroker("%s/con.db" % self.containers,
                                    account='test_acc',
                                    container='test_con')
     container_db.initialize(storage_policy_index=0)
     container_db.put_object('test_obj', time.time(), 10, 'text', 'faketag')
     info = stat.get_data("%s/con.db" % self.containers)
     self.assertEquals('''"test_acc","test_con",1,10\n''', info)
 def test_container_stat_get_metadata(self):
     container_db = ContainerBroker("%s/con.db" % self.containers,
                                    account='test_acc',
                                    container='test_con')
     container_db.initialize(storage_policy_index=0)
     container_db.put_object('test_obj', time.time(), 10, 'text', 'faketag')
     container_db.update_metadata({'X-Container-Meta-Test1': ('val', 1000)})
     self.conf['metadata_keys'] = 'test1,test2'
     stat = db_stats_collector.ContainerStatsCollector(self.conf)
     info = stat.get_data("%s/con.db" % self.containers)
     self.assertEquals('''"test_acc","test_con",1,10,1,\n''', info)