def test_stat_data_source(self, *args): data_source_vos = DataSourceFactory.build_batch( 10, domain_id=self.domain_id) list(map(lambda vo: vo.save(), data_source_vos)) params = { 'domain_id': self.domain_id, 'query': { 'aggregate': [{ 'group': { 'keys': [{ 'key': 'data_source_id', 'name': 'Id' }], 'fields': [{ 'operator': 'count', 'name': 'Count' }] } }, { 'sort': { 'key': 'Count', 'desc': True } }] } } self.transaction.method = 'stat' data_source_svc = DataSourceService(transaction=self.transaction) values = data_source_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_data_source')
def test_list_data_sources_by_tag(self, *args): DataSourceFactory(tags=[{ 'key': 'tag_key_1', 'value': 'tag_value_1' }], domain_id=self.domain_id) data_source_vos = DataSourceFactory.build_batch( 9, domain_id=self.domain_id) list(map(lambda vo: vo.save(), data_source_vos)) params = { 'query': { 'filter': [{ 'k': 'tags.tag_key_1', 'v': 'tag_value_1', 'o': 'eq' }] }, 'domain_id': self.domain_id } self.transaction.method = 'list' data_source_svc = DataSourceService(transaction=self.transaction) data_sources_vos, total_count = data_source_svc.list(params) DataSourcesInfo(data_source_vos, total_count) self.assertEqual(len(data_sources_vos), 1) self.assertIsInstance(data_sources_vos[0], DataSource) self.assertEqual(total_count, 1)
def test_list_data_sources_by_monitoring_type(self, *args): data_source_vos = DataSourceFactory.build_batch( 10, monitoring_type='METRIC', domain_id=self.domain_id) list(map(lambda vo: vo.save(), data_source_vos)) params = {'monitoring_type': 'METRIC', 'domain_id': self.domain_id} self.transaction.method = 'list' data_source_svc = DataSourceService(transaction=self.transaction) data_sources_vos, total_count = data_source_svc.list(params) DataSourcesInfo(data_source_vos, total_count) self.assertEqual(len(data_sources_vos), 10) self.assertIsInstance(data_sources_vos[0], DataSource) self.assertEqual(total_count, 10)
def test_stat_data_source_distinct(self, *args): data_source_vos = DataSourceFactory.build_batch(10, domain_id=self.domain_id) list(map(lambda vo: vo.save(), data_source_vos)) params = { 'domain_id': self.domain_id, 'query': { 'distinct': 'data_source_id', 'page': { 'start': 2, 'limit': 3 } } } self.transaction.method = 'stat' data_source_svc = DataSourceService(transaction=self.transaction) values = data_source_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_data_source_distinct')
def list(self, params): return DataSourceFactory.build_batch(10, **params), 10