diff --git a/zds/tutorialv2/tests/tests_views.py b/zds/tutorialv2/tests/tests_views.py index f1a6729287..206103f27b 100644 --- a/zds/tutorialv2/tests/tests_views.py +++ b/zds/tutorialv2/tests/tests_views.py @@ -5073,6 +5073,32 @@ def test_republish_with_different_slug(self): tuto = PublishableContent.objects.get(pk=self.tuto.pk) self.assertEqual(tuto.public_version.pk, new_published.pk) + def test_logical_article_pagination(self): + """Test that the past is "left" and the future is "right", or in other word that the good article + are given to pagination and not the opposite""" + + article1 = PublishedContentFactory(type="ARTICLE") + + # force "article1" to be the first one by setting a publication date equals to one hour before the test + article1.public_version.publication_date = datetime.datetime.now() - datetime.timedelta(0, 1) + article1.public_version.save() + + article2 = PublishedContentFactory(type="ARTICLE") + + self.assertEqual(PublishedContent.objects.count(), 3) # both articles have been published + + # visit article 1 (so article2 is next) + result = self.client.get(reverse('article:view', kwargs={'pk': article1.pk, 'slug': article1.slug})) + self.assertEqual(result.status_code, 200) + self.assertEqual(result.context['next_article'].pk, article2.public_version.pk) + self.assertIsNone(result.context['previous_article']) + + # visit article 2 (so article1 is previous) + result = self.client.get(reverse('article:view', kwargs={'pk': article2.pk, 'slug': article2.slug})) + self.assertEqual(result.status_code, 200) + self.assertEqual(result.context['previous_article'].pk, article1.public_version.pk) + self.assertIsNone(result.context['next_article']) + def tearDown(self): if os.path.isdir(settings.ZDS_APP['content']['repo_private_path']): diff --git a/zds/tutorialv2/views/views_published.py b/zds/tutorialv2/views/views_published.py index e79e2d351b..212dd9cf64 100644 --- a/zds/tutorialv2/views/views_published.py +++ b/zds/tutorialv2/views/views_published.py @@ -82,7 +82,7 @@ def get_context_data(self, **kwargs): all_articles = \ [a for a in PublishedContent.objects .filter(content_type="ARTICLE", must_redirect=False) - .order_by('-publication_date') + .order_by('publication_date') .all()] articles_count = len(all_articles)