def setUpClass(cls): url = 'http://www.zhihu.com/question/24825703/answer/30975949' file_path = os.path.join(TEST_DATA_PATH, 'answer.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) answer_saved_path = os.path.join(TEST_DATA_PATH, 'answer.md') with open(answer_saved_path, 'rb') as f: cls.answer_saved = f.read() cls.answer = Answer(url) cls.answer._session = None cls.answer.soup = soup cls.expected = { 'id': 30975949, 'aid': 7775236, 'xsrf': 'cfd489623d34ca03adfdc125368c6426', 'html': soup.prettify(), 'author_id': 'tian-ge-xia', 'author_name': '甜阁下', 'question_id': 24825703, 'question_title': '关系亲密的人之间要说「谢谢」吗?', 'upvote_num': 1164, 'upvoter_name': 'Mikuroneko', 'upvoter_id': 'guo-yi-hui-23' }
def setUpClass(cls): url = 'http://www.zhihu.com/question/24825703' file_path = os.path.join(TEST_DATA_PATH, 'question.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) cls.question = Question(url) cls.question._session = None cls.question.soup = soup cls.expected = {'id': 24825703, 'qid': 2112271, 'xsrf': 'cfd489623d34ca03adfdc125368c6426', 'html': soup.prettify(), 'title': '关系亲密的人之间要说「谢谢」吗?', 'details': description, 'answer_num': 621, 'follower_num': 4427, 'top_answer_id': 39753456, 'top_answer_author_name': '芝士就是力量', 'top_answer_upvote_num': 97, 'top_50_ans_id': 31003847, 'top_50_ans_author_name': '圭多达莱佐', 'top_50_ans_upvote_num': 31, 'more_ans_id': 39958704, 'more_ans_author_name': '柳蜻蜓', 'more_ans_upvote_num': 1, 'topics': ['心理学', '恋爱', '社会', '礼仪', '亲密关系'], } more_ans_file_path = os.path.join(TEST_DATA_PATH, 'question_more_answer.html') with open(more_ans_file_path, 'rb') as f: cls.more_ans_html = f.read()
def setUpClass(cls): url = 'http://www.zhihu.com/question/24825703' file_path = os.path.join(TEST_DATA_PATH, 'question.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) cls.question = Question(url) cls.question._session = None cls.question.soup = soup cls.expected = { 'id': 24825703, 'qid': 2112271, 'xsrf': 'cfd489623d34ca03adfdc125368c6426', 'html': soup.prettify(), 'title': '关系亲密的人之间要说「谢谢」吗?', 'details': description, 'answer_num': 621, 'follower_num': 4427, 'top_answer_id': 39753456, 'top_answer_author_name': '芝士就是力量', 'top_answer_upvote_num': 97, 'top_50_ans_id': 31003847, 'top_50_ans_author_name': '圭多达莱佐', 'top_50_ans_upvote_num': 31, 'more_ans_id': 39958704, 'more_ans_author_name': '柳蜻蜓', 'more_ans_upvote_num': 1, 'topics': ['心理学', '恋爱', '社会', '礼仪', '亲密关系'], } more_ans_file_path = os.path.join(TEST_DATA_PATH, 'question_more_answer.html') with open(more_ans_file_path, 'rb') as f: cls.more_ans_html = f.read()
def test_parse_author_soup(self): fpath = os.path.join(TEST_DATA_PATH, 'answer_upvoter.html') with open(fpath, 'rb') as f: html = f.read().decode('utf-8') soup = BeautifulSoup(html) upvoter = self.answer._parse_author_soup(soup) self.assertEqual(self.expected['upvoter_name'], upvoter.name) self.assertEqual(self.expected['upvoter_id'], upvoter.id)
def setUpClass(cls): url = 'http://www.zhihu.com/question/24825703/answer/30975949' file_path = os.path.join(TEST_DATA_PATH, 'answer.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) answer_saved_path = os.path.join(TEST_DATA_PATH, 'answer.md') with open(answer_saved_path, 'rb') as f: cls.answer_saved = f.read() cls.answer = Answer(url) cls.answer._session = None cls.answer.soup = soup cls.expected = {'id': 30975949, 'aid': 7775236, 'xsrf': 'cfd489623d34ca03adfdc125368c6426', 'html': soup.prettify(), 'author_id': 'tian-ge-xia', 'author_name': '甜阁下', 'question_id': 24825703, 'question_title': '关系亲密的人之间要说「谢谢」吗?', 'upvote_num': 1164, 'upvoter_name': 'Mikuroneko', 'upvoter_id': 'guo-yi-hui-23'}
def setUpClass(cls): url = 'http://www.zhihu.com/question/24825703' file_path = os.path.join(TEST_DATA_PATH, 'question.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) cls.question = Question(url) cls.question._session = None cls.question.soup = soup act_time = datetime.datetime.fromtimestamp(1439395600) act_type = ActType.FOLLOW_QUESTION cls.activity = Activity(act_type, act_time, question=cls.question)
def setUpClass(cls): url = 'http://www.zhihu.com/collection/28698204' file_path = os.path.join(TEST_DATA_PATH, 'collection.html') with open(file_path, 'rb') as f: html = f.read() soup = BeautifulSoup(html) cls.collection = Collection(url) cls.collection._session = None cls.collection.soup = soup cls.expected = {'cid': 3725428, 'name': '可以用来背的答案', 'xsrf': 'cfd489623d34ca03adfdc125368c6426', 'owner_id': 'buhuilengyoumo', 'owner_name': '树叶', 'follower_num': 6328, 'top_ques_id': 26092705, 'top_ques_title': ('一直追求(吸引)不到喜欢的异性,' '感觉累了怎么办?'), 'top_ans_id': 32989919, 'top_ans_author_name': '朱炫', 'top_ans_upvote_num': 16595, 'top_ans_author_id': 'zhu-xuan-86' }