weixin_39752434 2020-11-29 14:59
浏览 0

[Django 2]: Test failures: Mail handler has excess item in outbox

Blocks: #6172 (Upgrade to Django 2)

One of our tests fails under Django 2 with:


________________________ LoggingTests.test_mail_handler ________________________ 
Traceback (most recent call last):                                               
  File "/app/kuma/core/tests/test_views.py", line 81, in test_mail_handler       
    assert 1 == len(mail.outbox)                                                 
AssertionError: assert 1 == 2                                                    
 +  where 2 = len([<django.core.mail.message.emailmultialternatives object at>, <django.core.mail.message.emailmultialternatives object at>])
 +    where [<django.core.mail.message.emailmultialternatives object at>, <django.core.mail.message.emailmultialternatives object at>] = mail.outbox
------------------------------ Captured log call ------------------------------- 
ERROR    django.security.SuspiciousOperation:exception.py:75 Raising exception to test logging.
WARNING  django.request:log.py:222 Bad Request: /en-US/suspicious/
</django.core.mail.message.emailmultialternatives></django.core.mail.message.emailmultialternatives></django.core.mail.message.emailmultialternatives></django.core.mail.message.emailmultialternatives>

I have not yet investigated this failure.

该提问来源于开源项目:mdn/kuma

  • 写回答

5条回答 默认 最新

  • weixin_39752434 2020-11-29 14:59
    关注

    The test in question is effectively:

    python
    class LoggingTests(KumaTestCase):
        logger = logging.getLogger("django")
        suspicous_path = "/en-US/suspicious/"
    
        def test_mail_handler(self):
            self.logger.handlers = [AdminEmailHandler()]
            response = self.client.get(self.suspicous_path)
            assert 400 == response.status_code
            assert 1 == len(mail.outbox)
    
            assert "admin.com" in mail.outbox[0].to
            assert self.suspicous_path in mail.outbox[0].body
    

    It's expecting a single message in the outbox, with /en-US/suspicious/ in the body.

    And both messages have that.

    • [0].subject: [mdn] ERROR (internal IP): Raising exception to test logging.

      
      Raising exception to test logging.
      <p>Report at /en-US/suspicious/
      ...
      </p>
    • [1].subject: [mdn] WARNING (internal IP): Bad Request: /en-US/suspicious/

      
      Bad Request: /en-US/suspicious/
      <p>Report at /en-US/suspicious/
      ...
      </p>

    ...so what's the expected behavior?

    评论

报告相同问题?