def _UpdateCodeCoverageSettings(self, code_coverage_is_on, user, message): """Updates the code coverage settings. Args: code_coverage_is_on (bool): Whether the code coverage feature is turned on. user: User who initiated the update. message: The update message. Returns: A bool indicates whether the update is successful. """ code_coverage_settings = waterfall_config.GetCodeCoverageSettings() if code_coverage_is_on == code_coverage_settings.get( 'serve_presubmit_coverage_data'): return False code_coverage_settings = copy.deepcopy(code_coverage_settings) code_coverage_settings[ 'serve_presubmit_coverage_data'] = code_coverage_is_on return wf_config.FinditConfig.Get().Update( user, acl.IsPrivilegedUser(user.email(), users.is_current_user_admin()), message=message, code_coverage_settings=code_coverage_settings)
def _IsServePresubmitCoverageDataEnabled(): """Returns True if the feature to serve presubmit coverage data is enabled. Returns: Returns True if it is enabled, otherwise, False. """ # Unless the flag is explicitly set, assuming disabled by default. return waterfall_config.GetCodeCoverageSettings().get( 'serve_presubmit_coverage_data', False)
def _GetBanner(project): """If there is a service banner for a given project landing page, return it. E.g. a maintenance announcement or outage acknowledgement, etc. The setting is expected to be a dict mapping a project to the contents of the div tag for the banner. If no project banner is defined, return the default one. This expected to be None if no banner is to be shown. """ banners = waterfall_config.GetCodeCoverageSettings().get( 'project_banners', {}) return banners.get(project, banners.get('default'))
def testNonAdminCouldTurnOffCodeCoverage(self, _): self.mock_current_user(user_email='*****@*****.**', is_admin=False) params = { 'xsrf_token': 'token', 'code_coverage': 'false', 'update_reason': 'reason', } response = self.test_app.post('/trooper?format=json', params=params) redirect_url = '/trooper' self.assertTrue( response.headers.get('Location', '').endswith(redirect_url)) self.assertFalse(waterfall_config.GetCodeCoverageSettings().get( 'serve_presubmit_coverage_data'))
def HandleGet(self): action_settings = waterfall_config.GetActionSettings() auto_commit_revert_is_on = action_settings.get('auto_commit_revert', False) code_coverage_settings = waterfall_config.GetCodeCoverageSettings() code_coverage_is_on = ( code_coverage_settings.get('serve_presubmit_coverage_data', False)) return { 'template': 'trooper.html', 'data': { 'is_admin': users.is_current_user_admin(), 'auto_commit_revert_on': auto_commit_revert_is_on, 'code_coverage_on': code_coverage_is_on, } }
def testAdminCouldTurnOnCodeCoverage(self, _): self.mock_current_user(user_email='*****@*****.**', is_admin=True) self.UpdateUnitTestConfigSettings( 'code_coverage_settings', {'serve_presubmit_coverage_data': False}) params = { 'xsrf_token': 'token', 'code_coverage': 'true', 'update_reason': 'reason', 'format': 'json', } response = self.test_app.post('/trooper', params=params, status=302) self.assertTrue( response.headers.get('Location', '').endswith('/trooper')) self.assertTrue(waterfall_config.GetCodeCoverageSettings().get( 'serve_presubmit_coverage_data'))
def testGetCodeCoverageSettings(self): self.assertEqual({'serve_presubmit_coverage_data': True}, waterfall_config.GetCodeCoverageSettings())