コード例 #1
0
    def test_getting_article_info(self):

        with test_database(db, (Users, Articles)):
            user1 = Users.create_user(username="******", password="******")
            article = Articles.create_article(title = "test article 1", \
                                    body = "test",
                                    author = user1)

            self.assertEquals("test-article-1", article.slug)
            self.assertEquals(article,
                              Articles.get_article_by_slug("test-article-1"))
            article2 = Articles.create_article(title="test article 2",
                                               body="test",
                                               author=user1)
            self.assertEquals(article2, article.get_next_article(True))
            self.assertEquals(0, article.get_previous_article())
            self.assertEquals(article, article2.get_previous_article(True))
            self.assertEquals(0, article2.get_next_article())

            article3 = Articles.create_article(title = "test article 3",\
                                    body = "test",\
                                    draft = False,\
                                    author = user1)

            self.assertEquals(1, Articles.get_count(drafts=False))
            self.assertEquals(3, Articles.get_count(drafts=True))
            self.assertTrue(Articles.check_exists("test article 1"))
            self.assertFalse(Articles.check_exists("nonexistent"))

            for x in range(4, 10):
                title = "test article %d" % x
                Articles.create_article(title=title,
                                        body="test",
                                        author=user1,
                                        draft=False)

            self.assertEquals(9, Articles.get_count(True))

            paginated = Articles.get_index_articles(3, 3)

            self.assertEquals(7, paginated.wrapped_count())

            self.assertIn("test article 3", str(tuple(paginated)))
            self.assertNotIn("test article 1", str(tuple(paginated)))
            self.assertNotIn("test article 9", str(tuple(paginated)))

            paginated = Articles.get_index_articles(1, 3)

            self.assertIn("test article 9", str(tuple(paginated)))
            self.assertIn("test article 7", str(tuple(paginated)))
コード例 #2
0
ファイル: test_articles.py プロジェクト: agatka21/subrosa
    def test_getting_article_info(self):

        with test_database(db, (Users, Articles)):
            user1 = Users.create_user(username = "******", password = "******")
            article = Articles.create_article(title = "test article 1", \
                                    body = "test",
                                    author = user1)

            self.assertEquals("test-article-1", article.slug)
            self.assertEquals(article, Articles.get_article_by_slug("test-article-1"))
            article2 = Articles.create_article(title = "test article 2", body = "test", author = user1)
            self.assertEquals(article2, article.get_next_article(True))
            self.assertEquals(0,article.get_previous_article())
            self.assertEquals(article, article2.get_previous_article(True))
            self.assertEquals(0, article2.get_next_article())

            article3 = Articles.create_article(title = "test article 3",\
                                    body = "test",\
                                    draft = False,\
                                    author = user1)

            self.assertEquals(1, Articles.get_count(drafts = False))
            self.assertEquals(3, Articles.get_count(drafts = True))
            self.assertTrue(Articles.check_exists("test article 1"))
            self.assertFalse(Articles.check_exists("nonexistent"))

            for x in range(4,10):
                title = "test article %d" % x
                Articles.create_article(title = title, body = "test", author = user1, draft = False)

            self.assertEquals(9, Articles.get_count(True))

            paginated = Articles.get_index_articles(3, 3)

            self.assertEquals(7, paginated.wrapped_count())

            self.assertIn("test article 3", str(tuple(paginated)))
            self.assertNotIn("test article 1", str(tuple(paginated)))
            self.assertNotIn("test article 9", str(tuple(paginated)))

            paginated = Articles.get_index_articles(1, 3)

            self.assertIn("test article 9", str(tuple(paginated)))
            self.assertIn("test article 7", str(tuple(paginated)))