Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/tests/test_lister.py
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | def mock_response(self, request, context): | ||||
'r', encoding='utf-8') as r: | 'r', encoding='utf-8') as r: | ||||
return r.read() | return r.read() | ||||
def request_index(self, request): | def request_index(self, request): | ||||
m = self.test_re.search(request.path_url) | m = self.test_re.search(request.path_url) | ||||
if m and (len(m.groups()) > 0): | if m and (len(m.groups()) > 0): | ||||
return self.convert_type(m.group(1)) | return self.convert_type(m.group(1)) | ||||
@requests_mock.Mocker() | def create_fl_with_db(self, http_mocker): | ||||
def test_fetch_multiple_pages_yesdb(self, http_mocker): | |||||
http_mocker.get(self.test_re, text=self.mock_response) | http_mocker.get(self.test_re, text=self.mock_response) | ||||
db = init_db() | db = init_db() | ||||
fl = self.get_fl(override_config={ | fl = self.get_fl(override_config={ | ||||
'lister': { | 'lister': { | ||||
'cls': 'local', | 'cls': 'local', | ||||
'args': {'db': db.url()} | 'args': {'db': db.url()} | ||||
} | } | ||||
}) | }) | ||||
fl.db = db | |||||
self.init_db(db, fl.MODEL) | self.init_db(db, fl.MODEL) | ||||
self.disable_scheduler(fl) | self.disable_scheduler(fl) | ||||
return fl | |||||
@requests_mock.Mocker() | |||||
def test_fetch_multiple_pages_yesdb(self, http_mocker): | |||||
fl = self.create_fl_with_db(http_mocker) | |||||
fl.run(min_bound=self.first_index) | fl.run(min_bound=self.first_index) | ||||
self.assertEqual(fl.db_last_index(), self.last_index) | self.assertEqual(fl.db_last_index(), self.last_index) | ||||
partitions = fl.db_partition_indices(5) | partitions = fl.db_partition_indices(5) | ||||
self.assertGreater(len(partitions), 0) | self.assertGreater(len(partitions), 0) | ||||
for k in partitions: | for k in partitions: | ||||
self.assertLessEqual(len(k), 5) | self.assertLessEqual(len(k), 5) | ||||
self.assertGreater(len(k), 0) | self.assertGreater(len(k), 0) | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |