def test_save_attachments_on_save(self):
        '''When saving it also calls the save an attachment'''
        email_answer = EmailAnswer()
        email_answer.subject = 'prueba4'
        email_answer.content_text = 'prueba4lafieritaespeluda'
        email_answer.add_attachment(self.photo_fiera)
        email_answer.add_attachment(self.pdf_file)
        any_answer = Answer.objects.first()

        with patch('requests.Session.post') as post:
            post.return_value = PostMock()
            with patch('mailit.bin.handleemail.EmailAnswer.save_attachment') as save_attachment:
                with patch('mailit.bin.handleemail.EmailAnswer.save') as save_answer:
                    save_answer.return_value = any_answer
                    email_answer.send_back()
                    save_attachment.assert_any_call(any_answer, self.photo_fiera)
                    save_attachment.assert_any_call(any_answer, self.pdf_file)
Example #2
0
    def test_logs_the_result_of_send_back(self):
        email_answer = EmailAnswer()
        email_answer.subject = 'prueba4'
        email_answer.content_text = 'prueba4lafieritaespeluda'
        email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
        email_answer.email_from = '*****@*****.**'
        email_answer.when = 'Wed Jun 26 21:05:33 2013'
        with patch('logging.info') as info:
            info.return_value = None
            with patch('requests.Session.post') as post:
                post.return_value = PostMock()

                with patch('logging.info') as info:
                    expected_log = "When sent to %(location)s the status code was 201" % {
                        'location': self.where_to_post_creation_of_the_answer
                        }
                    email_answer.send_back()
                    info.assert_called_with(expected_log)
Example #3
0
    def test_logs_the_result_of_send_back(self):
        email_answer = EmailAnswer()
        email_answer.subject = 'prueba4'
        email_answer.content_text = 'prueba4lafieritaespeluda'
        email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
        email_answer.email_from = '*****@*****.**'
        email_answer.when = 'Wed Jun 26 21:05:33 2013'
        with patch('logging.info') as info:
            info.return_value = None
            with patch('requests.Session.post') as post:
                post.return_value = PostMock()

                with patch('logging.info') as info:
                    expected_log = "When sent to %(location)s the status code was 201" % {
                        'location': self.where_to_post_creation_of_the_answer
                    }
                    email_answer.send_back()
                    info.assert_called_with(expected_log)
Example #4
0
 def test_send_back_also_returns_an_answer(self):
     '''the method EmailAnswer.send_back returns an answer'''
     email_answer = EmailAnswer()
     email_answer.subject = 'prueba4'
     email_answer.content_text = 'prueba4lafieritaespeluda'
     email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
     email_answer.email_from = '*****@*****.**'
     email_answer.when = 'Wed Jun 26 21:05:33 2013'
     # so when I execute email_answer.save, it will return
     # the first answer that we have in our fixtures
     # it doesn't really matter as long as it returns an answer
     answer = Answer.objects.first()
     with patch('requests.Session.post') as post:
         post.return_value = PostMock()
         with patch('mailit.bin.handleemail.EmailAnswer.save') as save_answer:
             save_answer.return_value = answer
             result = email_answer.send_back()
             self.assertEquals(result, answer)
Example #5
0
 def test_send_back_also_returns_an_answer(self):
     '''the method EmailAnswer.send_back returns an answer'''
     email_answer = EmailAnswer()
     email_answer.subject = 'prueba4'
     email_answer.content_text = 'prueba4lafieritaespeluda'
     email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
     email_answer.email_from = '*****@*****.**'
     email_answer.when = 'Wed Jun 26 21:05:33 2013'
     # so when I execute email_answer.save, it will return
     # the first answer that we have in our fixtures
     # it doesn't really matter as long as it returns an answer
     answer = Answer.objects.first()
     with patch('requests.Session.post') as post:
         post.return_value = PostMock()
         with patch(
                 'mailit.bin.handleemail.EmailAnswer.save') as save_answer:
             save_answer.return_value = answer
             result = email_answer.send_back()
             self.assertEquals(result, answer)