コード例 #1
0
    def test_sections(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        repo = ProjectsRepository(data)
        if len(repo.Groups) != 2:
            for f in repo.Groups:
                fLOG(f)
            self.assertEqual(len(repo.Groups), 2)
        groups = list(sorted(repo.Groups))
        gr = groups[0]
        if gr is None or len(gr) < 2:
            raise Exception("Empty group '{0}'".format(gr))
        self.assertEqual(gr, 'group_el1')
        sections = repo.get_sections(gr)
        names = [k for k in sorted(sections)]
        self.assertEqual(
            names,
            ['', 'extrait', 'next', 'pitch', 'programme', 'rapport', 'title'])
        if sections["next"] != ['', '* module tweepy', '']:
            raise Exception(sections["next"])
        if sections["extrait"] != [
                '', '::', '', '    paragraphe 1', '', '    paragraphe 2', ''
        ]:
            raise Exception(sections["extrait"])
コード例 #2
0
    def test_sections(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        repo = ProjectsRepository(data)
        if len(repo.Groups) != 2:
            for f in repo.Groups:
                fLOG(f)
            self.assertEqual(len(repo.Groups), 2)
        groups = list(sorted(repo.Groups))
        gr = groups[0]
        if gr is None or len(gr) < 2:
            raise Exception("Empty group '{0}'".format(gr))
        self.assertEqual(gr, 'group_el1')
        sections = repo.get_sections(gr)
        names = [k for k in sorted(sections)]
        self.assertEqual(names, ['', 'extrait', 'next',
                                 'pitch', 'programme', 'rapport', 'title'])
        if sections["next"] != ['', '* module tweepy', '']:
            raise Exception(sections["next"])
        if sections["extrait"] != ['', '::', '', '    paragraphe 1', '', '    paragraphe 2', '']:
            raise Exception(sections["extrait"])
コード例 #3
0
    def test_emails(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        repo = ProjectsRepository(data)
        self.assertEqual(len(repo.Groups), 2)
        groups = list(sorted(repo.Groups))
        gr = groups[0]
        if gr is None or len(gr) < 2:
            raise Exception("Empty group '{0}'".format(gr))
        self.assertEqual(gr, 'group_el1')
        emails = repo.get_emails(gr)
        self.assertEqual(emails, ['*****@*****.**', 'name.lastname@something',
                                  '*****@*****.**', 'name.lastname@something'])
コード例 #4
0
    def test_emails(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        repo = ProjectsRepository(data)
        self.assertEqual(len(repo.Groups), 2)
        groups = list(sorted(repo.Groups))
        gr = groups[0]
        if gr is None or len(gr) < 2:
            raise Exception("Empty group '{0}'".format(gr))
        self.assertEqual(gr, 'group_el1')
        emails = repo.get_emails(gr)
        self.assertEqual(emails, [
            '*****@*****.**', 'name.lastname@something',
            '*****@*****.**', 'name.lastname@something'
        ])
コード例 #5
0
rows = [{
    "nom_prenom": mail,
    "sujet": "octobre",
    "groupe": i + 1
} for i, mail in enumerate(emails)]
df = pandas.DataFrame(rows)
fLOG("dataframe", df.shape)
df.to_excel(filename_excel)

##################################
# create folders for each student

mappings = {}
folder = dest_folder

proj = ProjectsRepository(folder, fLOG=fLOG)
groups = proj.Groups
if do_mail or len(groups) < 10:
    fLOG("creation")
    proj = ProjectsRepository.create_folders_from_dataframe(
        df,
        folder,
        col_subject="sujet",
        fLOG=fLOG,
        col_group="groupe",
        col_student="nom_prenom",
        email_function=emails,
        skip_if_nomail=False,
        must_have_email=True)
fLOG("nb groups", len(proj.Groups))
コード例 #6
0
    def test_sections(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        dfile = os.path.join(data, "notes_eleves_2104_2015.xlsx")
        df = pandas.read_excel(dfile, skiprows=5, engine='openpyxl')
        df = df[df["Groupe"] != "moyenne"].copy()
        df = df[~df["Eleves"].isna()].copy()
        fLOG(df.columns)
        fLOG(df.tail())
        fLOG(df.shape)
        emails = ["*****@*****.**".lower(),
                  "*****@*****.**"]
        temp = get_temp_folder(__file__, "temp_repository")
        try:
            proj = ProjectsRepository.create_folders_from_dataframe(
                df, temp, col_subject="sujet", fLOG=fLOG, col_group=None,
                col_student="Eleves", col_mail=None, email_function=emails,
                skip_if_nomail=True)
        except ProjectsRepository.MailNotFound:
            pass

        emails = ["*****@*****.**".lower(),
                  "*****@*****.**",
                  "*****@*****.**"]

        proj = ProjectsRepository.create_folders_from_dataframe(
            df, temp, col_subject="sujet", fLOG=fLOG, col_group=None,
            col_student="Eleves", col_mail=None, email_function=emails,
            must_have_email=False)

        do_test = True
        if do_test:
            data = os.path.abspath(os.path.join(
                os.path.dirname(__file__), "data"))
            box = MailBoxMock(data, b"unittestunittest", fLOG)
            box.login()

            email_render = EmailMessageRenderer(
                tmpl=template_email_html_short, fLOG=fLOG)
            render = EmailMessageListRenderer(title="list of mails",
                                              email_renderer=email_render, fLOG=fLOG)

            mails = proj.dump_group_mails(render, group=None,
                                          mailbox=box, subfolder="trav",
                                          date=datetime.datetime(2015, 1, 9))

            box.logout()

        suivi = os.path.join(temp, "ABOUT.firstname", "suivi.rst")
        with open(suivi, "r", encoding="utf8") as f:
            content = f.read()
        self.assertIn("* mails: [email protected]", content)

        self.assertEqual(len(proj.Groups), 3)
        mails = proj.get_emails(proj.Groups[0])
        self.assertEqual(len(mails), 1)
        self.assertIn(mails[0], emails)
        fLOG("------", os.path.exists(os.path.join(temp, "mail_style.css")))
        proj.write_run_command()
        proj.write_summary()
        fLOG("------")
        files = [os.path.join(temp, "index.html"),
                 os.path.join(
                     temp, "ABOUT.firstname", "d_2015-08-01_p_noreply-at-voyages-sncf-com_ii_8de6a63addb7c03407bc6f0caabd967e.html"),
                 os.path.join(temp, "mail_style.css")]
        nb = 0
        for name in files:
            if not os.path.exists(name):
                raise FileNotFoundError(name)
            nb += 1
            with open(name, "r", encoding="utf8") as f:
                content = f.read()
            self.assertNotIn("ut_automation_students", content)
        self.assertEqual(nb, len(files))
コード例 #7
0
    def test_sections(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        data = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(data, "data")
        dfile = os.path.join(data, "notes_eleves_2104_2015.xlsx")
        df = pandas.read_excel(dfile, skiprows=5)
        df = df[df["Groupe"] != "moyenne"].copy()
        fLOG(df.columns)
        fLOG(df.tail())
        fLOG(df.shape)
        emails = ["*****@*****.**".lower(),
                  "*****@*****.**"]
        temp = get_temp_folder(__file__, "temp_repository")
        try:
            proj = ProjectsRepository.create_folders_from_dataframe(df, temp, col_subject="sujet",
                                                                    fLOG=fLOG, col_group=None,
                                                                    col_student="Eleves",
                                                                    col_mail=None,
                                                                    email_function=emails,
                                                                    skip_if_nomail=True)
        except ProjectsRepository.MailNotFound:
            pass

        emails = ["*****@*****.**".lower(),
                  "*****@*****.**",
                  "*****@*****.**"]

        proj = ProjectsRepository.create_folders_from_dataframe(df, temp, col_subject="sujet",
                                                                fLOG=fLOG, col_group=None,
                                                                col_student="Eleves",
                                                                col_mail=None,
                                                                email_function=emails,
                                                                must_have_email=False)

        do_test = True
        if do_test:
            data = os.path.abspath(os.path.join(
                os.path.dirname(__file__), "data"))
            box = MailBoxMock(data, b"unittestunittest", fLOG)
            box.login()

            email_render = EmailMessageRenderer(
                tmpl=template_email_html_short, fLOG=fLOG)
            render = EmailMessageListRenderer(title="list of mails",
                                              email_renderer=email_render, fLOG=fLOG)

            mails = proj.dump_group_mails(render, group=None,
                                          mailbox=box, subfolder="trav",
                                          date=datetime.datetime(2015, 1, 9))

            box.logout()

        suivi = os.path.join(temp, "ABOUT.firstname", "suivi.rst")
        with open(suivi, "r", encoding="utf8") as f:
            content = f.read()
        self.assertIn("* mails: [email protected]", content)

        self.assertEqual(len(proj.Groups), 3)
        mails = proj.get_emails(proj.Groups[0])
        self.assertEqual(len(mails), 1)
        self.assertIn(mails[0], emails)
        fLOG("------", os.path.exists(os.path.join(temp, "mail_style.css")))
        proj.write_summary()
        fLOG("------")
        files = [os.path.join(temp, "index.html"),
                 os.path.join(
                     temp, "ABOUT.firstname", "d_2015-08-01_p_noreply-at-voyages-sncf-com_ii_8de6a63addb7c03407bc6f0caabd967e.html"),
                 os.path.join(temp, "mail_style.css")]
        nb = 0
        for name in files:
            if not os.path.exists(name):
                raise FileNotFoundError(name)
            nb += 1
            with open(name, "r", encoding="utf8") as f:
                content = f.read()
            self.assertNotIn("ut_automation_students", content)
        self.assertEqual(nb, len(files))
コード例 #8
0
# create a dataframe

import pandas
rows = [{"nom_prenom": mail, "sujet": "octobre", "groupe": i + 1}
        for i, mail in enumerate(emails)]
df = pandas.DataFrame(rows)
fLOG("dataframe", df.shape)
df.to_excel(filename_excel)

##################################
# create folders for each student

mappings = {}
folder = dest_folder

proj = ProjectsRepository(folder, fLOG=fLOG)
groups = proj.Groups
if do_mail or len(groups) < 10:
    fLOG("creation")
    proj = ProjectsRepository.create_folders_from_dataframe(df, folder,
                                                            col_subject="sujet", fLOG=fLOG, col_group="groupe",
                                                            col_student="nom_prenom",
                                                            email_function=emails, skip_if_nomail=False,
                                                            must_have_email=True)
fLOG("nb groups", len(proj.Groups))

#############
# dump mails

if do_mail:
    email_render = EmailMessageRenderer(