def _test_fetch_version(self, version, from_date=None, reviews_api=False): """Test whether the pages with their reviews are returned""" HTTPServer.routes(version) # Test fetch pages with their reviews mediawiki = MediaWiki(MEDIAWIKI_SERVER_URL) if from_date: # Set flag to ignore MAX_RECENT_DAYS exception mediawiki._test_mode = True pages = [ page for page in mediawiki.fetch(from_date=from_date, reviews_api=reviews_api) ] else: pages = [page for page in mediawiki.fetch(reviews_api=reviews_api)] if version == "1.28" and reviews_api: # 2 pages in all name spaces self.assertEqual(len(pages), 2) elif version == "1.23" or not reviews_api: if not from_date: # 2 pages per each of the 5 name spaces self.assertEqual(len(pages), 10) else: # 1 page in recent changes self.assertEqual(len(pages), 1) HTTPServer.check_pages_contents(self, pages)
def test_fetch_max_recent_days(self, mock_utcnow): """Test whether the pages with their reviews are returned""" HTTPServer.routes("1.23") mock_utcnow.return_value = datetime.datetime(2100, 6, 10, tzinfo=dateutil.tz.tzutc()) from_date = dateutil.parser.parse("2016-06-23 15:35") mediawiki = MediaWiki(MEDIAWIKI_SERVER_URL) mediawiki._test_mode = True with self.assertRaises(BackendError): _ = [page for page in mediawiki.fetch(from_date=from_date)]