-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathanswer.py
More file actions
43 lines (35 loc) · 1.45 KB
/
answer.py
File metadata and controls
43 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# encoding: utf-8
from zhihu import Answer
import unittest
import time
class AnswerTestCase(unittest.TestCase):
def test_vote_up_with_id(self):
data = Answer(id=14005147).vote_up()
self.assertIn("voting", data)
self.assertIn("voteup_count", data)
def test_vote_up_with_url(self):
time.sleep(1)
answer = Answer(url="https://www.zhihu.com/question/19761434/answer/14005147")
data = answer.vote_up()
self.assertEqual("14005147", answer.id)
self.assertIn("voting", data)
self.assertIn("voteup_count", data)
def test_vote_down_with_id(self):
time.sleep(1)
data = Answer(id=14005147).vote_down()
self.assertIn("voting", data)
self.assertIn("voteup_count", data)
def test_vote_neutral_with_url(self):
time.sleep(1)
data = Answer(url="https://www.zhihu.com/question/19761434/answer/14005147").vote_neutral()
self.assertIn("voting", data)
self.assertIn("voteup_count", data)
def test_thank_with_url(self):
time.sleep(1)
data = Answer(url="https://www.zhihu.com/question/19761434/answer/14005147").thank()
self.assertEqual({"is_thanked": True}, data)
def test_thank_cancel_with_url(self):
time.sleep(1)
data = Answer(url="https://www.zhihu.com/question/19761434/answer/14005147").thank_cancel()
self.assertIn("is_thanked", data)
self.assertEqual({"is_thanked": False}, data)