def testPromptForSurvey_NoCacheFile(self): prompter = survey_check.SurveyPrompter() prompter.Prompt() self.AssertErrEquals('') with survey_check.PromptRecord() as pr: self.assertEqual(pr.last_prompt_time, 1544651979) self.assertEqual(pr.last_answer_survey_time, None)
def testShouldPrompt_NotIsatty(self): self.StartPatch('googlecloudsdk.core.log.out.isatty', return_value=False) self.StartPatch('googlecloudsdk.core.log.err.isatty', return_value=False) prompter = survey_check.SurveyPrompter() self.assertFalse(prompter.ShouldPrompt())
def SurveyPromptCheck(command_path, **unused_kwargs): del command_path try: survey_check.SurveyPrompter().PromptForSurvey() # pylint:disable=broad-except, We never want this to escape, ever. Only # messages printed should reach the user. except Exception: log.debug('Failed to check survey prompt.', exc_info=True)
def SurveyPromptCheck(command_path, **unused_kwargs): """Checks for in-tool survey prompt.""" if not _ShouldCheckSurveyPrompt(command_path): return try: survey_check.SurveyPrompter().Prompt() # pylint:disable=broad-except, We never want this to escape, ever. Only # messages printed should reach the user. except Exception: log.debug('Failed to check survey prompt.', exc_info=True)
def testPromptForSurvey(self): with survey_check.PromptRecord() as pr: pr.last_prompt_time = 0 prompter = survey_check.SurveyPrompter() prompter.Prompt() self.AssertErrEquals('\n\nTo take a quick anonymous survey, run:\n' ' $ gcloud survey\n\n') with survey_check.PromptRecord() as pr: self.assertEqual(pr.last_prompt_time, 1544651979) self.assertEqual(pr.last_answer_survey_time, None)
def testShouldPrompt_LastPromptNotExpired_AnswerExpired(self): with survey_check.PromptRecord() as pr: pr.last_prompt_time = self.last_prompt_time_unexpired pr.last_answer_survey_time = self.last_answer_survey_time_expired prompter = survey_check.SurveyPrompter() self.assertFalse(prompter.ShouldPrompt())
def testShouldPrompt_LastPromptExpired_NotAnswered(self): with survey_check.PromptRecord() as pr: pr.last_prompt_time = self.last_prompt_time_expired prompter = survey_check.SurveyPrompter() self.assertTrue(prompter.ShouldPrompt())
def testShouldPrompt_NotPromptedYet_AnswerExpired(self): with survey_check.PromptRecord() as pr: pr.last_answer_survey_time = self.last_answer_survey_time_expired prompter = survey_check.SurveyPrompter() self.assertTrue(prompter.ShouldPrompt())
def testShouldPrompt_EmptyCache(self): prompter = survey_check.SurveyPrompter() self.assertTrue(prompter.ShouldPrompt())