Esempio n. 1
0
    def test_should_send(self):
        template = MagicMock()
        email = Email(sender='ben',
                      recipients=['bob', 'betty'],
                      subject='email',
                      template=template,
                      data={})

        negative_render_return_cases = ['', ' ', ' \n ', ' \t ', ' \n\t ']
        for test_case in negative_render_return_cases:
            email.template.render.return_value = test_case
            self.assertIsInstance(
                email.should_send(), NoContent,
                "Should not send if rendered output is '%s'" % test_case)

        positive_render_return_cases = ['foo', '\nfoo']
        for test_case in positive_render_return_cases:
            email.template.render.return_value = test_case
            self.assertIsInstance(
                email.should_send(), OK,
                "Should send if rendered output is '%s'" % test_case)

        email.template.render.side_effect = Exception(
            "Fake template rendering exception")
        self.assertIsInstance(
            email.should_send(), Failure,
            "Should not send if rendering raises an Exception")
Esempio n. 2
0
  def test_should_send(self):
    template = MagicMock()
    email = Email(sender='ben', recipients=['bob', 'betty'], subject='email', template=template, data={})

    negative_render_return_cases = ['', ' ', ' \n ', ' \t ', ' \n\t ']
    for test_case in negative_render_return_cases:
      email.template.render.return_value = test_case
      self.assertIsInstance(email.should_send(), NoContent, "Should not send if rendered output is '%s'" % test_case)

    positive_render_return_cases = ['foo', '\nfoo']
    for test_case in positive_render_return_cases :
      email.template.render.return_value = test_case
      self.assertIsInstance(email.should_send(), OK, "Should send if rendered output is '%s'" % test_case)

    email.template.render.side_effect = Exception("Fake template rendering exception")
    self.assertIsInstance(email.should_send(), Failure, "Should not send if rendering raises an Exception")