Пример #1
0
    def test_class_answer(self):

        email_answer = EmailAnswer()
        self.assertTrue(hasattr(email_answer, 'subject'))
        self.assertTrue(hasattr(email_answer, '_content_text'))
        self.assertTrue(hasattr(email_answer, 'content_html'))
        self.assertTrue(hasattr(email_answer, 'outbound_message_identifier'))
        self.assertTrue(hasattr(email_answer, 'email_from'))
        self.assertTrue(hasattr(email_answer, 'email_to'))
        self.assertTrue(hasattr(email_answer, 'when'))
        self.assertTrue(hasattr(email_answer, 'message_id'))
        email_answer.subject = 'prueba4'
        email_answer.content_text = 'prueba4lafieritaespeluda'
        email_answer.content_html = '<p>prueba4lafieritaespeluda</p>'
        email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
        email_answer.email_from = '*****@*****.**'
        email_answer.email_to = 'Felipe <*****@*****.**>'
        email_answer.when = 'Wed Jun 26 21:05:33 2013'
        email_answer.message_id = '<CAA5PczfGfdhf29wgK=8t6j7hm8HYsBy8Qg87iTU2pF42Ez3VcQ@mail.gmail.com>'

        self.assertTrue(email_answer)
        self.assertEquals(email_answer.subject, 'prueba4')
        self.assertEquals(email_answer.content_text, 'prueba4lafieritaespeluda')
        self.assertEquals(email_answer.outbound_message_identifier, '8974aabsdsfierapulgosa')
        self.assertEquals(email_answer.email_from, '*****@*****.**')
        self.assertEquals(email_answer.email_to, 'Felipe <*****@*****.**>')
        self.assertEquals(email_answer.when, 'Wed Jun 26 21:05:33 2013')
        self.assertEquals(email_answer.message_id, '<CAA5PczfGfdhf29wgK=8t6j7hm8HYsBy8Qg87iTU2pF42Ez3VcQ@mail.gmail.com>')
        self.assertEquals(email_answer.content_html, '<p>prueba4lafieritaespeluda</p>')
        self.assertFalse(email_answer.is_bounced)
Пример #2
0
    def test_getter_removes_the_identifier(self):
        email_answer = EmailAnswer()
        email_answer.subject = 'prueba4'
        email_answer.outbound_message_identifier = '8974aabsdsfierapulgosa'
        email_answer.content_text = 'prueba4lafieritaespeluda y lo mandé desde este mail [email protected]'

        self.assertFalse(email_answer.outbound_message_identifier in email_answer.content_text)
        self.assertNotIn("*****@*****.**", email_answer.content_text)
Пример #3
0
    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)
Пример #4
0
 def test_the_email_answer_can_have_attachments(self):
     '''An email answer can have attachments'''
     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)
     self.assertTrue(email_answer.attachments)
     self.assertIn(self.photo_fiera, email_answer.attachments)
     self.assertIn(self.pdf_file, email_answer.attachments)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
0
 def test_it_doesnt_contain_anything_of_the_original_email(self):
     '''If I set the "To" header in the email and use it in the email_answer.recipient
     then I should not be getting her/his email address in the content'''
     email_answer = EmailAnswer()
     email_answer.subject = 'prueba5'
     email_answer.email_to = 'Tony <*****@*****.**>'
     email_answer.outbound_message_identifier = 'identifier123'
     email_answer.content_text = (
         u'Thank you for your enquiry. I am completely in favour of this measure,\n'
         u'and will certainly be voting for it.\n'
         u'Tony \n'
         u'<*****@*****.**>:')
     # There is an intended extra space after the word 'Tony'
     self.assertNotIn('<instance-', email_answer.content_text)
     self.assertNotIn('> :', email_answer.content_text)
     self.assertNotIn('Tony', email_answer.content_text)