コード例 #1
0
 def setUp(self):
     raw_message = read_file(
         f"{settings.BASE_DIR}/apps/restricted/fixtures/emails/valid.txt")
     parser = EmailParser(raw_message, "*****@*****.**",
                          ParserMessageType.STRING)
     self.message = parser.parse()
     self.processor = MessageProcessor("*****@*****.**", self.message, {})
コード例 #2
0
ファイル: test_utils.py プロジェクト: vhellem/lego
    def test_parse_message_no_token(self):
        """Parsing a message with no token has no effect, the function returns None"""
        raw_message = read_file(
            f'{settings.BASE_DIR}/apps/restricted/fixtures/emails/no_token.txt'
        )
        parser = EmailParser(raw_message, '*****@*****.**',
                             ParserMessageType.STRING)
        message = parser.parse()

        token = get_mail_token(message)
        self.assertIsNone(token)
コード例 #3
0
    def test_parse_valid_email(self):
        """Try to parse a valid message, make sure we add the correct properties to the message."""
        raw_message = read_file(
            f"{settings.BASE_DIR}/apps/restricted/fixtures/emails/valid.txt"
        )

        parser = EmailParser(raw_message, "*****@*****.**", ParserMessageType.STRING)
        message = parser.parse()

        self.assertIsInstance(message, Message)
        self.assertEquals(message.original_size, len(raw_message))
        self.assertEquals(message["X-MailFrom"], "*****@*****.**")
        self.assertEquals(message["To"], "*****@*****.**")
コード例 #4
0
    def test_rewrite_message(self):
        """Remove headers that may cause problems. Only keep a few required headers."""
        raw_message = read_file(
            f'{settings.BASE_DIR}/apps/restricted/fixtures/emails/clean_headers.txt'
        )
        parser = EmailParser(raw_message, '*****@*****.**',
                             ParserMessageType.STRING)
        message = parser.parse()
        new_message = self.processor.rewrite_message(message, '*****@*****.**')

        self.assertCountEqual(
            ['From', 'Subject', 'Content-Type', 'MIME-Version', 'Sender'],
            new_message.keys())
コード例 #5
0
ファイル: test_utils.py プロジェクト: vhellem/lego
    def test_parse_valid_message(self):
        """Try to parse a valid message and make sure ve remove the token payload"""
        raw_message = read_file(
            f'{settings.BASE_DIR}/apps/restricted/fixtures/emails/valid.txt')
        parser = EmailParser(raw_message, '*****@*****.**',
                             ParserMessageType.STRING)
        message = parser.parse()
        payloads = len(message.get_payload())

        token = get_mail_token(message)
        self.assertEquals('test_token', token)

        self.assertEquals(len(message.get_payload()), payloads - 1)
コード例 #6
0
    def test_send(self):
        """Test the outbox and make sure we have correct headers in the messages."""
        raw_message = read_file(
            f'{settings.BASE_DIR}/apps/restricted/fixtures/emails/clean_headers.txt'
        )
        parser = EmailParser(raw_message, '*****@*****.**',
                             ParserMessageType.STRING)
        message = parser.parse()
        new_message = self.processor.rewrite_message(message, '*****@*****.**')

        messages = self.processor.send(['*****@*****.**', '*****@*****.**'],
                                       '*****@*****.**', new_message)
        self.assertEquals(2, messages)

        outbox = mail.outbox
        first_message = outbox[0].message()
        self.assertSequenceEqual([
            'Subject', 'Content-Type', 'MIME-Version', 'Sender', 'From', 'To'
        ], first_message.keys())
コード例 #7
0
    def test_send(self):
        """Test the outbox and make sure we have correct headers in the messages."""
        raw_message = read_file(
            f"{settings.BASE_DIR}/apps/restricted/fixtures/emails/clean_headers.txt"
        )
        parser = EmailParser(raw_message, "*****@*****.**",
                             ParserMessageType.STRING)
        message = parser.parse()
        new_message = self.processor.rewrite_message(message, "*****@*****.**")

        messages = self.processor.send(["*****@*****.**", "*****@*****.**"],
                                       "*****@*****.**", new_message)
        self.assertEquals(2, messages)

        outbox = mail.outbox
        first_message = outbox[0].message()
        self.assertSequenceEqual(
            [
                "Subject", "Content-Type", "MIME-Version", "Sender", "From",
                "To"
            ],
            first_message.keys(),
        )