@@ -0,0 +1,2422 @@
+from django.test import TestCase%0A%0Afrom django.core.management import call_command%0A%0Afrom pillowtop.es_utils import initialize_index_and_mapping%0A%0Afrom corehq.apps.domain.shortcuts import create_domain%0Afrom corehq.apps.es.tests.utils import es_test%0Afrom corehq.apps.userreports.app_manager.helpers import clean_table_name%0Afrom corehq.apps.userreports.models import DataSourceConfiguration%0Afrom corehq.apps.userreports.util import get_indicator_adapter%0Afrom corehq.elastic import get_es_new%0Afrom corehq.pillows.mappings.domain_mapping import DOMAIN_INDEX_INFO%0Afrom corehq.util.elastic import ensure_index_deleted, reset_es_index%0A%0A%0A@es_test%0Aclass TestPruneOldDatasources(TestCase):%0A%0A    def test_empty_tables_are_not_dropped(self):%0A        config = self._create_data_source_config(self.domain.name)%0A        adapter = get_indicator_adapter(config, raise_errors=True)%0A        adapter.build_table()%0A%0A        call_command('prune_old_datasources')%0A%0A        self.assertTrue(adapter.table_exists)%0A%0A    def test_empty_tables_are_dropped(self):%0A        config = self._create_data_source_config(self.domain.name)%0A        adapter = get_indicator_adapter(config, raise_errors=True)%0A        adapter.build_table()%0A%0A        call_command('prune_old_datasources', '--drop-empty-tables')%0A%0A        self.assertFalse(adapter.table_exists)%0A%0A    @classmethod%0A    def setUpClass(cls):%0A        super().setUpClass()%0A        cls.domain = create_domain('test')%0A        cls.addClassCleanup(cls.domain.delete)%0A%0A    def setUp(self):%0A        super().setUp()%0A        self._setup_es()%0A%0A    @staticmethod%0A    def _create_data_source_config(domain_name):%0A        return DataSourceConfiguration(%0A            domain=domain_name,%0A            display_name='foo',%0A            referenced_doc_type='CommCareCase',%0A            table_id=clean_table_name(domain_name, 'test-table'),%0A            configured_indicators=%5B%7B%0A                %22type%22: %22expression%22,%0A                %22expression%22: %7B%0A                    %22type%22: %22property_name%22,%0A                    %22property_name%22: 'name'%0A                %7D,%0A                %22column_id%22: 'name',%0A                %22display_name%22: 'name',%0A                %22datatype%22: %22string%22%0A            %7D%5D,%0A        )%0A%0A    def _setup_es(self):%0A        self.es = get_es_new()%0A        reset_es_index(DOMAIN_INDEX_INFO)%0A        initialize_index_and_mapping(self.es, DOMAIN_INDEX_INFO)%0A        self.addCleanup(ensure_index_deleted, DOMAIN_INDEX_INFO.index)%0A

add tests for command