Пример #1
0
    def test_should_format_success_message_with_thanks_only_if_greater_than_160_characters(
            self):
        expected_message = THANKS
        response_text = "1" * 125
        self.assertEqual(161, len(expected_message + response_text))
        with patch.object(ResponseBuilder,
                          "get_expanded_response") as get_expanded_response:
            get_expanded_response.return_value = response_text
            message = get_success_msg_for_submission_using(Mock(), None)

        self.assertEqual(expected_message, message)
Пример #2
0
 def test_should_format_success_message_for_submission_with_blank_if_no_reporter(
         self):
     expected_message = success_messages[SUBMISSION] % "" + "name: tester"
     submission_response = SubmissionResponse(
         success=True,
         submission_id=123,
         errors={},
         processed_data={'name': 'tester'})
     response = Response(reporters=[],
                         submission_response=submission_response)
     message = get_success_msg_for_submission_using(response)
     self.assertEqual(expected_message, message)
Пример #3
0
 def test_should_format_success_message_for_submission_with_blank_if_no_reporter(
         self):
     expected_message = THANKS + " name: tester"
     form_submission_mock = self.create_form_submission_mock()
     response = create_response_from_form_submission(
         reporters=[],
         submission_id=123,
         form_submission=form_submission_mock)
     form_model_mock = Mock(spec=FormModel)
     form_model_mock.stringify.return_value = {'name': 'tester'}
     message = get_success_msg_for_submission_using(response,
                                                    form_model_mock)
     self.assertEqual(expected_message, message)
Пример #4
0
    def test_should_format_success_message_with_thanks_and_response_text_if_total_length_of_success_message_is_no_more_than_160_characters(
            self):
        response_text = "choice: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
        expected_message = THANKS + " " + response_text

        self.assertEqual(160, len(expected_message))

        with patch.object(ResponseBuilder,
                          "get_expanded_response") as get_expanded_response:
            get_expanded_response.return_value = response_text
            message = get_success_msg_for_submission_using(Mock(), None)

        self.assertEqual(expected_message, message)
        self.assertTrue(160, len(message))
Пример #5
0
    def test_should_format_success_message_with_thanks_only_if_greater_than_160_characters(
            self):
        expected_message = (THANKS % "Mino") + "."
        response = Mock()
        response.reporters = [{'name': 'mino rakoto'}]
        response.entity_type = ['reporter']
        response_text = "1" * 124

        self.assertEqual(161, len(expected_message + response_text))
        with patch.object(ResponseBuilder,
                          "get_expanded_response") as get_expanded_response:
            get_expanded_response.return_value = response_text
            message = get_success_msg_for_submission_using(response, None)

        self.assertEqual(expected_message, message)
Пример #6
0
    def test_should_format_success_message_with_thanks_and_response_text_if_total_length_of_success_message_is_no_more_than_160_characters(
            self):
        response_text = ": rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
        expected_message = (THANKS % "Mino") + response_text
        response = Mock()
        response.reporters = [{'name': 'mino rakoto'}]
        response.entity_type = ['reporter']

        self.assertEqual(160, len(expected_message))

        with patch.object(ResponseBuilder,
                          "get_expanded_response") as get_expanded_response:
            get_expanded_response.return_value = response_text[1:]
            message = get_success_msg_for_submission_using(response, None)

        #self.assertEqual(expected_message, message)
        self.assertTrue(160, len(message))
Пример #7
0
 def test_should_format_success_message_for_submission_with_reporter_name(
         self):
     expected_message = success_messages[
         SUBMISSION] % "rep1" + "age: 12 name: tester choice: red"
     submission_response = SubmissionResponse(success=True,
                                              submission_id=123,
                                              errors={},
                                              processed_data={
                                                  'name': 'tester',
                                                  'age': 12,
                                                  'choice': ['red']
                                              })
     response = Response(reporters=[{
         "name": "rep1"
     }],
                         submission_response=submission_response)
     message = get_success_msg_for_submission_using(response)
     self.assertEqual(expected_message, message)
Пример #8
0
 def test_should_format_success_message_for_submission_with_reporter_name(
         self):
     expected_message = THANKS + " age: 12 name: tester choice: red"
     form_submission_mock = self.create_form_submission_mock()
     response = create_response_from_form_submission(
         reporters=[{
             "name": "rep1"
         }],
         submission_id=123,
         form_submission=form_submission_mock)
     form_model_mock = Mock(spec=FormModel)
     form_model_mock.stringify.return_value = {
         'name': 'tester',
         'age': '12',
         'choice': 'red'
     }
     message = get_success_msg_for_submission_using(response,
                                                    form_model_mock)
     self.assertEqual(expected_message, message)
Пример #9
0
 def test_should_format_success_message_for_submission_with_blank_if_no_reporter(
         self):
     expected_message = (THANKS % "Mino") + ": tester"
     form_submission_mock = self.create_form_submission_mock()
     form_submission_mock.entity_type = ['reporter']
     response = create_response_from_form_submission(
         reporters=[{
             'name': 'mino rakoto'
         }],
         submission_id=123,
         form_submission=form_submission_mock)
     form_model_mock = Mock(spec=FormModel)
     form_model_mock.entity_question.code = 'eid'
     form_model_mock.stringify.return_value = {
         'name': 'tester',
         'eid': 'cli001'
     }
     message = get_success_msg_for_submission_using(response,
                                                    form_model_mock)
     self.assertEqual(expected_message, message)
Пример #10
0
 def test_should_format_success_message_for_submission_with_reporter_name(
         self):
     expected_message = (THANKS % "Mino") + ": 12; tester; red"
     form_submission_mock = self.create_form_submission_mock()
     form_submission_mock.entity_type = ['reporter']
     response = create_response_from_form_submission(
         reporters=[{
             "name": "Mino"
         }],
         submission_id=123,
         form_submission=form_submission_mock)
     form_model_mock = Mock(spec=FormModel)
     form_model_mock.stringify.return_value = {
         'name': 'tester',
         'age': '12',
         'choice': 'red'
     }
     form_model_mock.is_entity_type_reporter.return_value = False
     message = get_success_msg_for_submission_using(response,
                                                    form_model_mock)
     self.assertEqual(expected_message, message)
Пример #11
0
 def test_should_format_success_message_for_submission_with_blank_if_no_reporter(self):
     expected_message = success_messages[SUBMISSION] % "" + "name: tester"
     submission_response = SubmissionResponse(success=True, submission_id=123, errors={}, processed_data={'name':'tester'})
     response = Response(reporters=[], submission_response=submission_response)
     message = get_success_msg_for_submission_using(response)
     self.assertEqual(expected_message, message)
Пример #12
0
 def test_should_format_success_message_for_submission_with_reporter_name(self):
     expected_message = success_messages[SUBMISSION] % "rep1" + "age: 12 name: tester choice: red"
     submission_response = SubmissionResponse(success=True, submission_id=123, errors={}, processed_data={'name':'tester','age':12,'choice':['red']})
     response = Response(reporters=[{"name": "rep1"}], submission_response=submission_response)
     message = get_success_msg_for_submission_using(response)
     self.assertEqual(expected_message, message)