Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Fix answer.deleted attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
laike9m committed Feb 10, 2016
1 parent 5c6563b commit fe5546a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [add] 添加 answer.latest_comments 属性
- [fix] 获取头像失败
- [add] zhihu.ANONYMOUS 表示匿名用户
- [fix] answer.deleted 属性错误

0.3.9-1
-------
Expand Down
8 changes: 6 additions & 2 deletions test/zhihu-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def test_answer():
url = 'http://www.zhihu.com/question/24825703/answer/30975949'
answer = client.answer(url)

assert answer.deleted == False

# 获取答案url
print(answer.url)

Expand Down Expand Up @@ -234,9 +236,11 @@ def test_answer():
assert answer.deleted == False

# test deleted answer
url = 'https://www.zhihu.com/question/39271193/answer/80747935'
url = 'https://www.zhihu.com/question/40185501/answer/85271078'
answer = client.answer(url)
assert answer.deleted == True
answer.refresh()
assert answer.deleted == True

# test answer without collection
url = 'https://www.zhihu.com/question/23138285/answer/81246171'
Expand Down Expand Up @@ -779,7 +783,7 @@ def test():


if __name__ == '__main__':
Cookies_File = 'test.json'
Cookies_File = 'test.json' # TODO: update cookie
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
TEST_DIR = os.path.join(BASE_DIR, 'test')

Expand Down
6 changes: 3 additions & 3 deletions zhihu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def _get_content(self):
resp = self._session.get(self.url)

if self.__class__.__name__ == 'Answer':
if resp.history and resp.history[0].status_code in (301, 302):
self._deleted = True
else:
if 'answer' in resp.url:
self._deleted = False
else:
self._deleted = True

return resp.content

Expand Down

0 comments on commit fe5546a

Please sign in to comment.