Esempio n. 1
0
    def test_box_mock(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        data = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))

        box = MailBoxMock(data, b"unittestunittest", fLOG)
        box.login()
        folders = box.folders()
        assert len(folders) == 1
        fLOG(folders)
        mails = list(box.enumerate_mails_in_folder("trav"))
        box.logout()

        fLOG(len(mails))
        assert len(mails) > 0
        mail0 = mails[0]
        # fLOG(mail0)

        bin = mail0.as_bytes()
        ema = EmailMessage.create_from_bytes(bin)
        d0 = mail0.to_dict()
        d1 = ema.to_dict()
        self.assertEqual(d0["Subject"], d1["Subject"])

        render = EmailMessageRenderer()
        html, css = render.render(
            "__LOC__", mail0, file_css="example_css.css", attachments=None)
        assert "example_css.css" in html
        # fLOG(css)
        fLOG(html)
        assert "<tr><th>Date</th><td>Sat, 1 Aug 2015 11:40:50 +0200 (CEST)</td></tr>" in html
Esempio n. 2
0
    def test_tohtml(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        data = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
        mesf = os.path.join(data, "message.pickle")

        if "anaconda" in sys.executable.lower() or "anaconda" in sys.base_prefix.lower():
            # issue with Anaconda about module pickle
            # pickle has issues when getting a file saved by pickle on another
            # distribution
            return

        with open(mesf, "rb") as f:
            try:
                import pymmails as skip__
                obj = pickle.load(f)
            except ImportError:
                path = os.path.normpath(
                    os.path.abspath(
                        os.path.join(
                            os.path.split(__file__)[0],
                            "..",
                            "..",
                            "src")))
                if path not in sys.path:
                    sys.path.append(path)
                import pymmails as skip__
                obj = pickle.load(f)
                del sys.path[-1]

        temp = get_temp_folder(__file__, "temp_dump_html")
        render = EmailMessageRenderer()
        ff = obj.dump(render, location=temp, fLOG=fLOG)
        render.flush()
        fLOG(type(ff), ff)
        with open(ff[0], "r", encoding="utf8") as f:
            content = f.read()
        if '<link rel="stylesheet" type="text/css" href="mail_style.css">' not in content:
            raise Exception(content)
        if "d_2014-12-15_p_yyyyy-matthieu-at-xxxxx-xxx_ii_48bdbc9f9fd180ab917cec5bed8ca529.html" not in ff[0]:
            raise Exception(ff[0])
        if "<h1>2014/12/15 - projet 3A - élément logiciel</h1>" not in content:
            raise Exception(content)
Esempio n. 3
0
    def test_mailbox_dump(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor():
            warnings.warn("requires a password")
            return
        import keyring
        code = keyring.get_password(
            "sdut", os.environ["COMPUTERNAME"] + "pymmails")
        temp = get_temp_folder(__file__, "temp_dump")
        box = MailBoxImap("unittest.sdpython", code,
                          "imap.gmail.com", ssl=True, fLOG=fLOG)
        render = EmailMessageRenderer()
        box.login()
        mails = box.enumerate_mails_in_folder("test4", date="1-Jan-2016")
        for mail in mails:
            mail.dump(render, location=temp, fLOG=fLOG)
        render.flush()
        box.logout()
Esempio n. 4
0
    def test_regular_expression(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        fold = os.path.abspath(os.path.dirname(__file__))

        body = """
                    </div>
                    <div><img name="14a318e16161c62a_14a31789f7a34aae_null" title="pastedImage.png" src="cid:f8b05bd4-1c83-47bc-af9d-0032ba9c018e"><br>
                    </div>
                    <div>4. Vous m&#39;avez demande d&#39;afficher l&#39;arbre de decision pour mon random forest, mais apparemment &quot;.tree_&quot; n&#39;existe que pour les decision trees . J&#39;ai donc essaye de le faire avec un DT apres avoir telecharge le logiciel pour tracer l&#39;arbre mais ca ne marche
                     pas<br>
                    </div>
                    <div><br>
                    </div>
                    <div><img name="14a318e16161c62a_14a31789f7a34aae_null" title="pastedImage.png" src="cid:1146aa0a-244a-440e-8ea5-7b272c94f89a" height="153.02644466209597" width="560"><br>
                    </div>
                    <div><br>
                    ?<sp
                    """.replace("                    ", "")

        atts = [
            (os.path.join(
                fold,
                "attachements",
                "image.png"),
                None,
                "1146aa0a-244a-440e-8ea5-7b272c94f89a")]
        em = EmailMessageRenderer().process_body_html(fold, body, atts)
        fLOG(em)
        assert "1146aa0a-244a-440e-8ea5-7b272c94f89a" not in em
        exp = 'src="attachements/image.png"'
        if exp not in em.replace("\\", "/"):
            raise Exception(
                'string "attachements/image.png" not found in\n{0}'.format(em))