Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals, print_function

import io
import os
import unittest
from nose.tools import assert_equal

import httpretty

from wechatsogou.request import WechatSogouRequest
from wechatsogou.api import WechatSogouAPI
from test import fake_data_path, gaokao_keyword

ws_api = WechatSogouAPI()


class TestAPI(unittest.TestCase):
    @httpretty.activate
    def test_search_gzh(self):
        url = WechatSogouRequest.gen_search_gzh_url(gaokao_keyword)
        file_name = '{}/{}/{}'.format(os.getcwd(), fake_data_path,
                                      'search-gaokao-gzh.html')
        with io.open(file_name, encoding='utf-8') as f:
            search_gaokao_gzh_error = f.read()
            httpretty.register_uri(httpretty.GET,
                                   url,
                                   body=search_gaokao_gzh_error)

        gzh_list = ws_api.search_gzh(gaokao_keyword)