Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)