Esempio n. 1
0
    def test_saving_and_deleting_categories(self):

        with test_database(db,
                           (Users, Articles, Categories, ArticleCategories)):
            Users.create_user(username="******", password="******")
            user1 = Users.select().get()

            art = Articles.create_article(title="test article1",
                                          body="test",
                                          draft=True,
                                          author=user1)
            art2 = Articles.create_article(title="test article2",
                                           body="test",
                                           draft=True,
                                           author=user1)

            art.save_article_categories([u"cat1", u"cat2", u"cat3"])

            self.assertIn("cat1", str(tuple(art.get_article_categories())))
            self.assertIn("cat2", str(tuple(art.get_article_categories())))
            self.assertIn("cat3", str(tuple(art.get_article_categories())))

            art.save_article_categories(["cat1", "cat2", "cat3"])

            cat = Categories.select().count()

            self.assertEquals(3, cat)

            cat4 = Categories.create(name="cat4")
            cat5 = Categories.create(name="cat5")
            cat6 = Categories.create(name="cat6")

            art.save_article_categories(["cat4"])
            self.assertIn("cat4", str(tuple(art.get_article_categories())))
            self.assertEquals(4, art.get_article_categories().count())

            art2.save_article_categories(("cat1", "cat4", "cat7"))

            cats = Categories.select().group_by(Categories.name)

            self.assertIn("cat7", str(tuple(cats)))
            self.assertEquals(7, cats.count())

            art.delete_instance(recursive=True)

            self.assertEquals(7, cats.count())

            self.assertEquals(
                ArticleCategories.select().group_by(
                    ArticleCategories.id).count(), 4)
            cat4.delete_instance(recursive=True)

            self.assertEquals(
                ArticleCategories.select().group_by(
                    ArticleCategories.id).count(), 3)
Esempio n. 2
0
 def get_context(self):
     existing_categories = Categories.select()
     return dict(draft=True,
                 additional_controls=True,
                 existing_categories=existing_categories,
                 title_placeholder="Title of your Article",
                 body_placeholder="and content here...")
Esempio n. 3
0
    def test_saving_and_deleting_categories(self):

        with test_database(db, (Users, Articles, Categories, ArticleCategories)):
            Users.create_user(username = "******", password = "******")
            user1 = Users.select().get()

            art = Articles.create_article(title = "test article1", body = "test", draft = True, author = user1)
            art2 = Articles.create_article(title = "test article2", body = "test", draft = True, author = user1)


            art.save_article_categories([u"cat1", u"cat2", u"cat3"])


            self.assertIn("cat1", str(tuple(art.get_article_categories())))
            self.assertIn("cat2", str(tuple(art.get_article_categories())))
            self.assertIn("cat3", str(tuple(art.get_article_categories())))

            art.save_article_categories(["cat1", "cat2", "cat3"])

            cat = Categories.select().count()

            self.assertEquals(3, cat)

            cat4 = Categories.create(name = "cat4")
            cat5 = Categories.create(name = "cat5")
            cat6 = Categories.create(name = "cat6")

            art.save_article_categories(["cat4"])
            self.assertIn("cat4", str(tuple(art.get_article_categories())))
            self.assertEquals(4, art.get_article_categories().count())

            art2.save_article_categories(("cat1", "cat4", "cat7"))

            cats = Categories.select().group_by(Categories.name)

            self.assertIn("cat7", str(tuple(cats)))
            self.assertEquals(7, cats.count())

            art.delete_instance(recursive = True)

            self.assertEquals(7, cats.count())


            self.assertEquals(ArticleCategories.select().group_by(ArticleCategories.id).count(), 4)
            cat4.delete_instance(recursive = True)

            self.assertEquals(ArticleCategories.select().group_by(ArticleCategories.id).count(), 3)