def test_iter(self): """ the iteration method should handle pagination automatically based on rows and max_rows; use the mock solr server to query data row by row and ensure that the data return as expected """ sq = SearchQuery(q="unittest", rows=1, max_pages=20, start=0) with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(sq._query['start'], 0) self.assertEqual(next(sq).bibcode, '1971Sci...174..142S') self.assertEqual(len(sq.articles), 1) self.assertEqual(sq._query['start'], 1) self.assertEqual(next(sq).bibcode, '2012GCN..13229...1S') self.assertEqual(len(list(sq)), 18) # 2 already returned with six.assertRaisesRegex(self, StopIteration, "Maximum number of pages queried"): next(sq) sq.max_pages = 500 self.assertEqual(len(list(sq)), 28 - 18 - 2) with six.assertRaisesRegex(self, StopIteration, "All records found"): next(sq) # not setting max_pages should return the exact number of rows requests sq = SearchQuery(q="unittest", rows=3) with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(len(list(sq)), 3) # Default should use cursorMark sq = SearchQuery(q="unittest", sort="date") with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(next(sq).bibcode, '1971Sci...174..142S') self.assertEqual(sq.query['cursorMark'], sq.response.json['nextCursorMark'])
def test_iter(self): """ the iteration method should handle pagination automatically based on rows and max_rows; use the mock solr server to query data row by row and ensure that the data return as expected """ sq = SearchQuery(q="unittest", rows=1, max_pages=20) with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(sq._query['start'], 0) self.assertEqual(next(sq).bibcode, '1971Sci...174..142S') self.assertEqual(len(sq.articles), 1) self.assertEqual(sq._query['start'], 1) self.assertEqual(next(sq).bibcode, '2012GCN..13229...1S') self.assertEqual(len(list(sq)), 19) # 2 already returned with self.assertRaisesRegexp( StopIteration, "Maximum number of pages queried"): next(sq) sq.max_pages = 500 self.assertEqual(len(list(sq)), 28-19-2) with self.assertRaisesRegexp( StopIteration, "All records found"): next(sq)
def test_iter(self): """ the iteration method should handle pagination automatically based on rows and max_rows; use the mock solr server to query data row by row and ensure that the data return as expected """ sq = SearchQuery(q="unittest", rows=1, max_pages=20, start=0) with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(sq._query['start'], 0) self.assertEqual(next(sq).bibcode, '1971Sci...174..142S') self.assertEqual(len(sq.articles), 1) self.assertEqual(sq._query['start'], 1) self.assertEqual(next(sq).bibcode, '2012GCN..13229...1S') self.assertEqual(len(list(sq)), 18) # 2 already returned with self.assertRaisesRegexp( StopIteration, "Maximum number of pages queried"): next(sq) sq.max_pages = 500 self.assertEqual(len(list(sq)), 28-18-2) with self.assertRaisesRegexp( StopIteration, "All records found"): next(sq) # not setting max_pages should return the exact number of rows requests sq = SearchQuery(q="unittest", rows=3) with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(len(list(sq)), 3) # Default should use cursorMark sq = SearchQuery(q="unittest", sort="date") with MockSolrResponse(sq.HTTP_ENDPOINT): self.assertEqual(next(sq).bibcode, '1971Sci...174..142S') self.assertEqual( sq.query['cursorMark'], sq.response.json['nextCursorMark'] )