Skip to content

Commit

Permalink
Merge pull request #3178 from pierre-24/fix_pagination_pour_Eskimon
Browse files Browse the repository at this point in the history
Inverse la pagination des articles
  • Loading branch information
Eskimon committed Nov 9, 2015
2 parents 307ab31 + 381a639 commit 8ca82f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']):
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8ca82f2

Please sign in to comment.