Example #1
0
 def test_can_properly_paginate_a_queryset_using_a_list_of_localidentifiers(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     localidentifiers = []
     for i in range(0, 10):
         lid = 'lid-{0}'.format(i)
         localidentifiers.append(lid)
         ArticleFactory.create(issue=issue, localidentifier=lid)
     request = Request(self.factory.get('/', data={'page': 1}))
     paginator = EruditDocumentPagination()
     # Run
     object_list = paginator.paginate(10, localidentifiers, Article.objects.all(), request)
     # Check
     self.assertEqual(
         object_list,
         list(Article.objects.filter(localidentifier__in=localidentifiers[:10])
              .order_by('localidentifier')))
Example #2
0
 def test_can_provide_valid_pagination_data(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     localidentifiers = []
     for i in range(0, 50):
         lid = 'lid-{0}'.format(i)
         localidentifiers.append(lid)
         ArticleFactory.create(issue=issue, localidentifier=lid)
     request = Request(self.factory.get('/', data={'page': 2}))
     paginator = EruditDocumentPagination()
     # Run
     paginator.paginate(200, localidentifiers, Article.objects.all(), request)
     response = paginator.get_paginated_response({})
     # Check
     self.assertEqual(response.data['pagination']['count'], 200)
     self.assertEqual(response.data['pagination']['num_pages'], 20)
     self.assertEqual(response.data['pagination']['current_page'], 2)
     self.assertEqual(response.data['pagination']['next_page'], 3)
     self.assertEqual(response.data['pagination']['previous_page'], 1)
     self.assertEqual(response.data['pagination']['page_size'], 10)
Example #3
0
 def test_can_provide_valid_pagination_data(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     localidentifiers = []
     for i in range(0, 50):
         lid = {'Corpus_fac': 'Article', 'ID': 'lid-{0}'.format(i)}
         localidentifiers.append(lid)
         ArticleFactory.create(issue=issue, localidentifier=lid['ID'])
     request = Request(self.factory.get('/', data={'page': 2}))
     paginator = EruditDocumentPagination()
     # Run
     paginator.paginate(200, localidentifiers, Article.objects.all(),
                        request)
     response = paginator.get_paginated_response({})
     # Check
     self.assertEqual(response.data['pagination']['count'], 200)
     self.assertEqual(response.data['pagination']['num_pages'], 20)
     self.assertEqual(response.data['pagination']['current_page'], 2)
     self.assertEqual(response.data['pagination']['next_page'], 3)
     self.assertEqual(response.data['pagination']['previous_page'], 1)
     self.assertEqual(response.data['pagination']['page_size'], 10)
Example #4
0
 def test_can_properly_paginate_a_queryset_using_a_list_of_localidentifiers(
         self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     localidentifiers = []
     for i in range(0, 10):
         lid = {'Corpus_fac': 'Article', 'ID': 'lid-{0}'.format(i)}
         localidentifiers.append(lid)
         ArticleFactory.create(issue=issue, localidentifier=lid['ID'])
     request = Request(self.factory.get('/', data={'page': 1}))
     paginator = EruditDocumentPagination()
     # Run
     object_list = paginator.paginate(10, localidentifiers,
                                      Article.objects.all(), request)
     # Check
     self.assertEqual(
         object_list,
         list(
             Article.objects.filter(localidentifier__in=[
                 l['ID'] for l in localidentifiers[:10]
             ]).order_by('localidentifier')))