<s> from django . test import TestCase <EOL> from mock import patch <EOL> from corehq import toggles <EOL> from corehq . apps . app_manager . const import APP_V2 <EOL> from corehq . apps . app_manager . fixtures . mobile_ucr import report_fixture_generator <EOL> from corehq . apps . app_manager . models import Application , ReportModule , ReportAppConfig <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . domain . shortcuts import create_domain <EOL> from corehq . apps . userreports . tests import get_sample_report_config <EOL> from corehq . apps . users . models import CommCareUser <EOL> class OtaRestoreUrlTests ( TestCase ) : <EOL> domain = '<STR_LIT>' <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . app = Application . new_app ( cls . domain , '<STR_LIT>' , application_version = APP_V2 ) <EOL> cls . app . save ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . app . delete ( ) <EOL> def test_app_aware_url ( self ) : <EOL> toggles . APP_AWARE_SYNC . set ( self . domain , True , toggles . NAMESPACE_DOMAIN ) <EOL> self . assertIn ( self . app . _id , self . app . ota_restore_url ) <EOL> def test_default_url ( self ) : <EOL> toggles . APP_AWARE_SYNC . set ( self . domain , False , toggles . NAMESPACE_DOMAIN ) <EOL> self . assertNotIn ( self . app . _id , self . app . ota_restore_url ) <EOL> class AppAwareSyncTests ( TestCase ) : <EOL> domain = '<STR_LIT>' <EOL> rows = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:count>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : True <EOL> } ] <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> create_domain ( cls . domain ) <EOL> toggles . MOBILE_UCR . set ( cls . domain , True , toggles . NAMESPACE_DOMAIN ) <EOL> cls . user = CommCareUser . create ( cls . domain , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cls . app1 = Application . new_app ( cls . domain , '<STR_LIT>' , application_version = APP_V2 ) <EOL> cls . report_config1 = get_sample_report_config ( ) <EOL> cls . report_config1 . save ( ) <EOL> report_app_config = { <EOL> '<STR_LIT>' : cls . report_config1 . get_id , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> module = cls . app1 . add_module ( ReportModule . new_module ( '<STR_LIT>' , None ) ) <EOL> module . report_configs = [ ReportAppConfig . wrap ( report_app_config ) ] <EOL> cls . app1 . save ( ) <EOL> cls . app2 = Application . new_app ( cls . domain , '<STR_LIT>' , application_version = APP_V2 ) <EOL> cls . report_config2 = get_sample_report_config ( ) <EOL> cls . report_config2 . save ( ) <EOL> report_app_config = { <EOL> '<STR_LIT>' : cls . report_config2 . get_id , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> module = cls . app2 . add_module ( ReportModule . new_module ( '<STR_LIT>' , None ) ) <EOL> module . report_configs = [ ReportAppConfig . wrap ( report_app_config ) ] <EOL> cls . app2 . save ( ) <EOL> cls . app3 = Application . new_app ( cls . domain , '<STR_LIT>' , application_version = APP_V2 ) <EOL> cls . app3 . save ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> toggles . MOBILE_UCR . set ( cls . domain , False , toggles . NAMESPACE_DOMAIN ) <EOL> cls . app1 . delete ( ) <EOL> cls . report_config1 . delete ( ) <EOL> cls . app2 . delete ( ) <EOL> cls . report_config2 . delete ( ) <EOL> cls . user . delete ( ) <EOL> domain = Domain . get_by_name ( cls . domain ) <EOL> domain . delete ( ) <EOL> def test_report_fixtures_provider_without_app ( self ) : <EOL> """<STR_LIT>""" <EOL> from corehq . apps . userreports . reports . data_source import ConfigurableReportDataSource <EOL> with patch . object ( ConfigurableReportDataSource , '<STR_LIT>' ) as get_data_mock : <EOL> get_data_mock . return_value = self . rows <EOL> fixtures = report_fixture_generator ( self . user , '<STR_LIT>' , None ) <EOL> reports = fixtures [ <NUM_LIT:0> ] . findall ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( reports ) , <NUM_LIT:2> ) <EOL> report_ids = { r . attrib . get ( '<STR_LIT:id>' ) for r in reports } <EOL> self . assertEqual ( report_ids , { '<STR_LIT>' , '<STR_LIT>' } ) <EOL> def test_report_fixtures_provider_with_app ( self ) : <EOL> """<STR_LIT>""" <EOL> from corehq . apps . userreports . reports . data_source import ConfigurableReportDataSource <EOL> with patch . object ( ConfigurableReportDataSource , '<STR_LIT>' ) as get_data_mock : <EOL> get_data_mock . return_value = self . rows <EOL> fixtures = report_fixture_generator ( self . user , '<STR_LIT>' , None , app = self . app1 ) <EOL> reports = fixtures [ <NUM_LIT:0> ] . findall ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( reports ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( reports [ <NUM_LIT:0> ] . attrib . get ( '<STR_LIT:id>' ) , '<STR_LIT>' ) <EOL> def test_report_fixtures_provider_with_app_that_doesnt_have_reports ( self ) : <EOL> from corehq . apps . userreports . reports . data_source import ConfigurableReportDataSource <EOL> with patch . object ( ConfigurableReportDataSource , '<STR_LIT>' ) as get_data_mock : <EOL> get_data_mock . return_value = self . rows <EOL> fixtures = report_fixture_generator ( self . user , '<STR_LIT>' , None , app = self . app3 ) <EOL> self . assertEqual ( len ( fixtures ) , <NUM_LIT:0> ) </s>
