old_contents: from corehq.apps.domain.dbaccessors import get_docs_in_domain_by_class
  from corehq.apps.domain.models import Domain
  from corehq.dbaccessors.couchapps.all_docs import delete_all_docs_by_doc_type
  from corehq.util.test_utils import unit_testing_only
  
  
  def get_number_of_report_configs_by_data_source(domain, data_source_id):
      """
      Return the number of report configurations that use the given data source.
      """
      from corehq.apps.userreports.models import ReportConfiguration
      return ReportConfiguration.view(
          'userreports/report_configs_by_data_source',
          reduce=True,
          key=[domain, data_source_id]
      ).one()['value']
  
  
  @unit_testing_only
  def get_all_report_configs():
      all_domains = Domain.get_all()
      for domain in all_domains:
          for report_config in get_report_configs_for_domain(domain.name):
              yield report_config
  
  
  @unit_testing_only
  def delete_all_report_configs():
      from corehq.apps.userreports.models import ReportConfiguration
      delete_all_docs_by_doc_type(ReportConfiguration.get_db(), ('ReportConfiguration',))
  
  
  def get_report_configs_for_domain(domain):
      from corehq.apps.userreports.models import ReportConfiguration
      return sorted(
          get_docs_in_domain_by_class(domain, ReportConfiguration),
          key=lambda report: report.title,
      )
  
new_contents: from corehq.apps.domain.dbaccessors import get_docs_in_domain_by_class
  from corehq.apps.domain.models import Domain
  from corehq.dbaccessors.couchapps.all_docs import delete_all_docs_by_doc_type
  from corehq.util.test_utils import unit_testing_only
  
  
  def get_number_of_report_configs_by_data_source(domain, data_source_id):
      """
      Return the number of report configurations that use the given data source.
      """
      from corehq.apps.userreports.models import ReportConfiguration
      return ReportConfiguration.view(
          'userreports/report_configs_by_data_source',
          reduce=True,
          key=[domain, data_source_id]
      ).one()['value']
  
  
  def get_report_configs_for_domain(domain):
      from corehq.apps.userreports.models import ReportConfiguration
      return sorted(
          get_docs_in_domain_by_class(domain, ReportConfiguration),
          key=lambda report: report.title,
      )
  
  
  @unit_testing_only
  def get_all_report_configs():
      all_domains = Domain.get_all()
      for domain in all_domains:
          for report_config in get_report_configs_for_domain(domain.name):
              yield report_config
  
  
  @unit_testing_only
  def delete_all_report_configs():
      from corehq.apps.userreports.models import ReportConfiguration
      delete_all_docs_by_doc_type(ReportConfiguration.get_db(), ('ReportConfiguration',))
  
subject: move unit test only functions to end of file