forked from chyroc/WechatSogou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
76 lines (60 loc) · 3.5 KB
/
test_api.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, print_function
import os
import time
import unittest
from nose.tools import assert_equal, assert_true, assert_in, assert_greater_equal
from wechatsogou.const import WechatSogouConst
from wechatsogou.api import WechatSogouAPI
from wechatsogou.identify_image import identify_image_callback_by_hand
from test import gaokao_keyword
from test.rk import identify_image_callback_ruokuai_sogou, identify_image_callback_ruokuai_weixin
ws_api = WechatSogouAPI(captcha_break_time=3)
class TestAPIReal(unittest.TestCase):
# todo use chinese
def setUp(self):
self.identify_image_callback_sogou = identify_image_callback_ruokuai_sogou if os.environ.get(
'WechatSogouCI') else identify_image_callback_by_hand
self.identify_image_callback_ruokuai_weixin = identify_image_callback_ruokuai_weixin if os.environ.get(
'WechatSogouCI') else identify_image_callback_by_hand
def test_search_gzh_real(self):
gzh_list = ws_api.search_gzh(gaokao_keyword, identify_image_callback=self.identify_image_callback_sogou)
assert_greater_equal(len(gzh_list), 8)
assert_true(any(gaokao_keyword in i['wechat_name'] for i in gzh_list))
assert_true(any(i['open_id'] != '' for i in gzh_list))
def test_get_gzh_article_by_history_real(self):
gzh_article = ws_api.get_gzh_article_by_history(gaokao_keyword,
identify_image_callback_sogou=self.identify_image_callback_sogou,
identify_image_callback_weixin=self.identify_image_callback_ruokuai_weixin)
assert_in('gzh', gzh_article)
assert_in('article', gzh_article)
assert_in('wx.qlogo.cn', gzh_article['gzh']['headimage'])
assert_greater_equal(len(gzh_article['article']), 1)
def test_get_gzh_article_by_hot_real(self):
gzh_articles = ws_api.get_gzh_article_by_hot(WechatSogouConst.hot_index.recommendation,
identify_image_callback=self.identify_image_callback_sogou)
for gzh_article in gzh_articles:
assert_in('gzh', gzh_article)
assert_in('article', gzh_article)
assert_in('http://mp.weixin.qq.com/s?src=', gzh_article['article']['url'])
assert_greater_equal(len(gzh_articles), 10)
def test_get_sugg(self):
sugg_gaokao = ws_api.get_sugg(gaokao_keyword)
assert_equal(10, len(sugg_gaokao))
def test_get_article_content(self):
gzh_article = ws_api.get_gzh_article_by_history(gaokao_keyword,
identify_image_callback_sogou=self.identify_image_callback_sogou,
identify_image_callback_weixin=self.identify_image_callback_ruokuai_weixin)
assert_in('gzh', gzh_article)
assert_in('article', gzh_article)
assert_in('wx.qlogo.cn', gzh_article['gzh']['headimage'])
assert_greater_equal(len(gzh_article['article']), 1)
# 防止测试时被封IP
time.sleep(11)
article_url = gzh_article['article'][0]['content_url']
article_info = ws_api.get_article_content(article_url,
identify_image_callback=self.identify_image_callback_sogou)
assert_in('content_html', article_info)
assert_in('content_img_list', article_info)
if __name__ == '__main__':
unittest.main()