Skip to content

Commit 30275f9

Browse files
committed
improve tests
1 parent d7647e2 commit 30275f9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

atwiki/test/test_core.py

Lines changed: 18 additions & 2 deletions
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,17 +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)
101115
count = 0
102116
for page in self._api.get_list('曲'):
103117
count += 1
104-
if 100 < count:
118+
if 50*3 <= count:
105119
break
106120
else:
107121
assert False, "unexpected number of pages for the tag"
108122

123+
# Get list from the last listing.
109124
pages = list(self._api.get_list('曲', _start=last_index))
110125
assert 1 <= len(pages) <= 50
111126

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

0 commit comments

Comments
 (0)