Server IP : 85.214.239.14 / Your IP : 18.223.170.253 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_webmail/tests/ |
Upload File : |
# coding: utf-8 """FETCH parser tests.""" from __future__ import print_function import unittest import six from modoboa_webmail.lib.fetch_parser import FetchResponseParser from . import data def dump_bodystructure(fp, bs, depth=0): """Dump a parsed BODYSTRUCTURE.""" indentation = " " * (depth * 4) for mp in bs: if isinstance(mp, list): if isinstance(mp[0], list): print("{}multipart/{}".format(indentation, mp[1]), file=fp) dump_bodystructure(fp, mp, depth + 1) else: dump_bodystructure(fp, mp, depth) elif isinstance(mp, dict): if isinstance(mp["struct"][0], list): print("{}multipart/{}".format( indentation, mp["struct"][1]), file=fp) dump_bodystructure(fp, mp["struct"][0], depth + 1) else: print("{}{}/{}".format( indentation, *mp["struct"][:2]), file=fp) fp.seek(0) result = fp.read() return result class FetchParserTestCase(unittest.TestCase): """Test FETCH parser.""" def setUp(self): """Setup test env.""" self.parser = FetchResponseParser() def _test_bodystructure_output(self, bs, expected): """.""" r = self.parser.parse(bs) fp = six.StringIO() output = dump_bodystructure(fp, r[list(r.keys())[0]]["BODYSTRUCTURE"]) fp.close() self.assertEqual(output, expected) return r def test_parse_bodystructure(self): """Test the parsing of several responses containing BS.""" self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_1, """multipart/alternative text/plain text/html """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_2, """multipart/mixed text/plain message/rfc822 """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_3, """multipart/mixed multipart/alternative text/plain text/html application/pdf """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_4, """multipart/mixed multipart/alternative text/plain text/html application/octet-stream """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_5, """multipart/alternative text/plain text/html """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_6, """multipart/mixed multipart/related multipart/alternative text/plain text/html image/png image/jpeg application/pdf multipart/alternative text/plain text/html """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_7, """multipart/mixed multipart/mixed text/plain application/octet-stream """) self._test_bodystructure_output( data.BODYSTRUCTURE_SAMPLE_8, "text/html\n")