コード例 #1
0
 def test_no_debug_logging(self):
     # Make sure it doesn't output anything when DEBUG_API_REQUESTS is not set
     message = AnymailMessage('Subject', 'Text Body', '*****@*****.**', ['*****@*****.**'])
     message._payload_init = dict(
         data="Request body",
         headers={
             "Content-Type": "text/plain",
             "Accept": "application/json",
         },
     )
     with self.assertPrints("", match="equal"):
         message.send()
コード例 #2
0
    def test_debug_logging(self):
        message = AnymailMessage('Subject', 'Text Body', '*****@*****.**', ['*****@*****.**'])
        message._payload_init = dict(
            data="Request body",
            headers={
                "Content-Type": "text/plain",
                "Accept": "application/json",
            },
        )
        with self.assertPrints("===== Anymail API request") as outbuf:
            message.send()

        # Header order and response data vary to much to do a full comparison, but make sure
        # that the output contains some expected pieces of the request and the response"
        output = outbuf.getvalue()
        self.assertIn("\nPOST https://httpbin.org/post\n", output)
        self.assertIn("\nUser-Agent: django-anymail/", output)
        self.assertIn("\nAccept: application/json\n", output)
        self.assertIn("\nContent-Type: text/plain\n", output)  # request
        self.assertIn("\n\nRequest body\n", output)
        self.assertIn("\n----- Response\n", output)
        self.assertIn("\nHTTP 200 OK\n", output)
        self.assertIn("\nContent-Type: application/json\n", output)  # response