Exemplo n.º 1
0
 def test_first_page_default(self):
     """
     Test that the first page is returned by default.
     """
     create_articles(11)
     self.assertEqual(Article.get_articles()[0],
                      Article.get_articles(page=1)[0])
Exemplo n.º 2
0
 def test_doesnt_return_unpublished(self):
     """
     Test that only published articles are returned, and unpublished
     articles are left out.
     """
     published_article = Article.objects.create(published=True)
     Article.objects.create(published=False)
     self.assertEqual(len(Article.get_articles()), 1)
     self.assertEqual(published_article, Article.get_articles()[0])
Exemplo n.º 3
0
 def test_pagination(self):
     """
     Test that articles are returned in pages, with the first page
     containing the most recent articles.
     """
     create_articles(11)
     second_article = Article.get_articles(page=1)[9]
     first_article = Article.get_articles(page=2)[0]
     self.assertEqual(second_article.id, 2)
     self.assertEqual(first_article.id, 1)
Exemplo n.º 4
0
 def test_returns_published_articles(self):
     """
     Test that the Article model has a get_articles method that
     returns published articles.
     """
     article = Article.objects.create(published=True)
     self.assertEqual(article, Article.get_articles()[0])
Exemplo n.º 5
0
 def test_order_by_published_date(self):
     """
     Test that the articles returned are ordered by published date
     descending.
     """
     create_articles(10)
     dates = []
     for article in Article.get_articles():
         dates.append(article.date)
     dates_diff = [i - j for i, j in zip(dates[:-1], dates[1:])]
     dates_diff_is_positive = [i.total_seconds() > 0 for i in dates_diff]
     self.assertTrue(all(dates_diff_is_positive))
Exemplo n.º 6
0
 def test_returns_ten_articles(self):
     """
     Test that a maximum of 10 articles are returned.
     """
     create_articles(11)
     self.assertEqual(len(Article.get_articles()), 10)