Пример #1
0
 def testLongSurveyAnswersTest_Failed(self):
     self.mock_client.request.return_value = ({'status': '400'}, '')
     with self.AssertRaisesExceptionMatches(
             concord_util.SurveyNotRecordedError,
             'We cannot record your feedback at this time, please try again later.'
     ):
         concord_util.LogSurveyAnswers(self.survey_instances)
Пример #2
0
def LogResponse(survey_instance):
    """Sends response to concord's clearcut tables."""
    send = console_io.PromptContinue(
        prompt_string='Do you want to submit your response')
    if send:
        concord_util.LogSurveyAnswers(survey_instance)
    else:
        log.err.Print('Your response is not recorded.')
    def testLogSurveyAnswers_Success(self):
        self.mock_client.request.return_value = mock.PropertyMock(
            status_code=200)
        concord_util.LogSurveyAnswers(self.survey_instances)
        expected_headers = {'user-agent': 'cloudsdk'}
        expected_hats_response = {
            'hats_metadata': {
                'site_id': 'CloudSDK',
                'site_name': 'googlecloudsdk',
                'survey_id': 'GeneralSurvey'
            },
            'multiple_choice_response': [{
                'question_number': 0,
                'answer_text': ['Very satisfied'],
                'answer_index': [1],
                'order_index': [1],
                'order': [1, 2, 3, 4, 5]
            }],
            'open_text_response': [{
                'question_number': 2,
                'answer_text': 'Love Cloud SDK!'
            }],
            'rating_response': [{
                'question_number': 1,
                'rating': 10
            }]
        }
        expected_concord_event = {
            'event_metadata': [{
                'env': 'env'
            }],
            'console_type': 'CloudSDK',
            'event_type': 'hatsSurvey',
            'hats_response': expected_hats_response
        }
        expected_log_events = [{
            'event_time_ms':
            100,
            'source_extension_json':
            json.dumps(expected_concord_event, sort_keys=True)
        }]

        expected_body = json.dumps(
            {
                'client_info': {
                    'client_type': 'DESKTOP',
                    'desktop_client_info': {
                        'os': 'os_id'
                    }
                },
                'log_source_name': 'CONCORD',
                'zwieback_cookie': '111',
                'request_time_ms': 100,
                'log_event': expected_log_events
            },
            sort_keys=True)

        self.mock_client.request.assert_called_once_with(
            'POST',
            'https://play.googleapis.com/log',
            data=expected_body,
            headers=expected_headers)
        with survey_check.PromptRecord() as pr:
            self.assertEqual(pr.last_answer_survey_time, 200)
        self.AssertErrEquals('Your response is submitted.\n')