Skip to content

Commit dd427bd

Browse files
authored
Merge pull request #33 from kmaehashi/fix-pageirze
Fix pagerized requests for tags not working
2 parents 9448afb + 30275f9 commit dd427bd

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

atwiki/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_list(self, tag=None, _start=1):
3737
if tag:
3838
soup = self._request(self._uri.tag(tag, index))
3939
links = soup.find('div', attrs={'class': 'cmd_tag'}).find('ul').select('a')
40-
pager = soup.find('div', attrs={'class': 'cmd_tag'}).select_one('a[href$="?&p={}"]'.format(index + 1))
40+
pager = soup.find('div', attrs={'class': 'cmd_tag'}).select_one('a[href$="?p={}"]'.format(index + 1))
4141
else:
4242
soup = self._request(self._uri.list('create', index))
4343
links = soup.find('table', attrs={'class': 'pagelist'}).findAll('a', href=True, title=True)

atwiki/test/test_core.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ def setUp(self):
6969
self._api = AtWikiAPI(self._uri)
7070

7171
def test_get_list(self):
72+
# Get the first page from the first listing.
7273
top_page = next(self._api.get_list())
7374
assert top_page == {'id': 1, 'name': 'トップページ'}
7475

76+
# Detect number of all pages.
7577
soup = self._api._request(self._uri.list(sort='create', index=1))
7678
text = soup.find('div', class_='pagelist').text
7779
m = re.search(r'計 (\d+) ページ / 1 から 100 を表示', text)
@@ -80,16 +82,27 @@ def test_get_list(self):
8082
assert 45000 < count < 90000
8183
last_index = math.ceil(count / 100)
8284

83-
# Get list from the last page.
85+
# Ensure listing pagerize works. (retrieve 3 listing, 100 pages in each)
86+
count = 0
87+
for page in self._api.get_list():
88+
count += 1
89+
if 100*3 <= count:
90+
break
91+
else:
92+
assert False, "unexpected number of pages"
93+
94+
# Get list from the last listing.
8495
# N.B. The page counter is not updated immediately.
8596
pages = list(self._api.get_list(_start=last_index))
8697
expected = (count % 100)
8798
assert max(0, (expected - 50)) < len(pages) < min(100, (expected + 50))
8899

100+
# Get out-of-bounds listing. (expected to wrap around)
89101
top_page = next(self._api.get_list(_start=last_index + 1))
90102
assert top_page == {'id': 1, 'name': 'トップページ'}
91103

92104
def test_get_list_tag(self):
105+
# Detect number of listings.
93106
soup = self._api._request(self._uri.tag('曲', index=1))
94107
last_index = 1
95108
for link in soup.find('div', class_='cmd_tag').find_all('a'):
@@ -98,9 +111,20 @@ def test_get_list_tag(self):
98111
last_index += 1
99112
assert 750 <= last_index
100113

114+
# Ensure listing pagerize works. (retrieve 3 listing, 50 pages in each)
115+
count = 0
116+
for page in self._api.get_list('曲'):
117+
count += 1
118+
if 50*3 <= count:
119+
break
120+
else:
121+
assert False, "unexpected number of pages for the tag"
122+
123+
# Get list from the last listing.
101124
pages = list(self._api.get_list('曲', _start=last_index))
102125
assert 1 <= len(pages) <= 50
103126

127+
# Get out-of-bounds listing.
104128
pages = list(self._api.get_list('曲', _start=last_index + 1))
105129
assert len(pages) == 0
106130

0 commit comments

Comments
 (0)