Esempio n. 1
0
    def test_category(self):
        resp = self.app.get("/category/actus")
        self.assertEqual(resp.status_int, 302)
        resp = resp.follow()
        self.assertEqual(resp.status_int, 200)

        # adding an article
        create_form = resp.forms[1]
        create_form["title"] = "New article"
        resp = create_form.submit("cat_add_actus")

        # we should be redirected to the article
        article_page = resp.follow().follow()
        self.assertEqual(article_page.status_int, 200)
        self.assertEqual(article_page.form["title"].value, "New article")

        # lets make sure we generated a proper article on disk
        cat_dir = dict(self.config["actus"])["path"]
        filename = os.path.join(cat_dir, "new-article.rst")
        parsed = parse_article(filename)
        self.assertEqual(parsed["metadata"]["category"], u"Actualités")

        # let's change its body and date
        article_page.forms[0]["body"] = "blah"
        article_page.forms[0]["date"] = "16/11/2012"
        resp = article_page.forms[0].submit()
        body = resp.follow().follow().forms[0]["body"].value
        self.assertEqual(body.strip(), "blah")

        # let's create a new article with the same title
        resp = self.app.get("/category/actus")
        self.assertEqual(resp.status_int, 302)
        resp = resp.follow()
        self.assertEqual(resp.status_int, 200)

        # adding the 2nd article
        create_form = resp.forms[2]
        create_form["title"] = "New article"
        resp = create_form.submit("cat_add_actus")
        filename2 = os.path.join(cat_dir, "new-article1.rst")
        self.assertTrue(os.path.exists(filename2))
        os.remove(filename2)

        # let's suppress the first article
        resp = self.app.get("/category/actus").follow()
        for form in resp.forms.values():
            if "new-article" in form.action:
                form.submit()
                break

        # should be gone
        resp = self.app.get("/category/actus").follow()
        self.assertTrue("New article" not in resp.text)
Esempio n. 2
0
    def test_parse(self):
        for file in os.listdir(SAMPLE_DIR):
            if not file.endswith(".rst"):
                continue
            filename = os.path.join(SAMPLE_DIR, file)
            article = parse_article(filename)
            rendered = article.render().strip()

            with open(filename) as f:
                source = f.read().strip()
                source = source.expandtabs(4).decode("utf8")

            if source != rendered:
                lev_ = distance(source, rendered)
                jaro_ = jaro(source, rendered)

                if lev_ > 10 and jaro_ < 0.8 and file not in MUTATED_FILES:
                    print("%d %f %s" % (lev_, jaro_, filename))
                    raise AssertionError(filename)