<s> from __future__ import absolute_import , unicode_literals , print_function <EOL> import os <EOL> import unittest <EOL> from datetime import datetime <EOL> import six <EOL> from httmock import urlmatch , HTTMock , response <EOL> from wechatpy import WeChatClient <EOL> from wechatpy . exceptions import WeChatClientException <EOL> from wechatpy . utils import json <EOL> _TESTS_PATH = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> _FIXTURE_PATH = os . path . join ( _TESTS_PATH , '<STR_LIT>' ) <EOL> @ urlmatch ( netloc = r'<STR_LIT>' ) <EOL> def wechat_api_mock ( url , request ) : <EOL> path = url . path . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT:/>' , '<STR_LIT:_>' ) <EOL> if path . startswith ( '<STR_LIT:_>' ) : <EOL> path = path [ <NUM_LIT:1> : ] <EOL> res_file = os . path . join ( _FIXTURE_PATH , '<STR_LIT>' % path ) <EOL> content = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' % res_file , <EOL> } <EOL> headers = { <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' <EOL> } <EOL> try : <EOL> with open ( res_file , '<STR_LIT:rb>' ) as f : <EOL> content = json . loads ( f . read ( ) . decode ( '<STR_LIT:utf-8>' ) ) <EOL> except ( IOError , ValueError ) as e : <EOL> content [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> res_file , <EOL> e <EOL> ) <EOL> return response ( <NUM_LIT:200> , content , headers , request = request ) <EOL> class WeChatClientTestCase ( unittest . TestCase ) : <EOL> app_id = '<STR_LIT>' <EOL> secret = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . client = WeChatClient ( self . app_id , self . secret ) <EOL> def test_two_client_not_equal ( self ) : <EOL> client2 = WeChatClient ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert self . client != client2 <EOL> assert self . client . user != client2 . user <EOL> assert id ( self . client . menu ) != id ( client2 . menu ) <EOL> with HTTMock ( wechat_api_mock ) : <EOL> self . client . fetch_access_token ( ) <EOL> assert self . client . access_token != client2 . access_token <EOL> def test_subclass_client_ok ( self ) : <EOL> class TestClient ( WeChatClient ) : <EOL> pass <EOL> client = TestClient ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( client , client . user . _client ) <EOL> def test_fetch_access_token ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> token = self . client . fetch_access_token ( ) <EOL> self . assertEqual ( '<STR_LIT>' , token [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT> , token [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , self . client . access_token ) <EOL> def test_upload_media ( self ) : <EOL> media_file = six . StringIO ( '<STR_LIT>' ) <EOL> with HTTMock ( wechat_api_mock ) : <EOL> media = self . client . media . upload ( '<STR_LIT:image>' , media_file ) <EOL> self . assertEqual ( '<STR_LIT:image>' , media [ '<STR_LIT:type>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , media [ '<STR_LIT>' ] ) <EOL> def test_user_get_group_id ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> group_id = self . client . user . get_group_id ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , group_id ) <EOL> def test_create_group ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> group = self . client . group . create ( '<STR_LIT:test>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , group [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( '<STR_LIT:test>' , group [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] ) <EOL> def test_group_get ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> groups = self . client . group . get ( ) <EOL> self . assertEqual ( <NUM_LIT:5> , len ( groups ) ) <EOL> def test_group_getid ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> group = self . client . group . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , group ) <EOL> def test_group_update ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . group . update ( <NUM_LIT> , '<STR_LIT:test>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_group_move_user ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . group . move_user ( '<STR_LIT:test>' , <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_group_delete ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . group . delete ( <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_text_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . send_text ( <NUM_LIT:1> , '<STR_LIT:test>' , account = '<STR_LIT:test>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_image_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . send_image ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_voice_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . send_voice ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_video_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . send_video ( <EOL> <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT:test>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_music_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . send_music ( <EOL> <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT:test>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_send_articles_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> articles = [ { <EOL> '<STR_LIT:title>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:description>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:image>' : '<STR_LIT>' <EOL> } ] <EOL> result = self . client . message . send_articles ( <NUM_LIT:1> , articles ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_get_mass_message ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . message . get_mass ( <NUM_LIT> ) <EOL> self . assertEqual ( '<STR_LIT>' , result [ '<STR_LIT>' ] ) <EOL> def test_create_menu ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . menu . create ( { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:key>' : '<STR_LIT:test>' <EOL> } <EOL> ] <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_get_menu ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> menu = self . client . menu . get ( ) <EOL> self . assertTrue ( '<STR_LIT>' in menu ) <EOL> def test_delete_menu ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . menu . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_update_menu ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . menu . update ( { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:key>' : '<STR_LIT:test>' <EOL> } <EOL> ] <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_short_url ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . misc . short_url ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , result [ '<STR_LIT>' ] ) <EOL> def test_get_wechat_ips ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . misc . get_wechat_ips ( ) <EOL> self . assertEqual ( [ '<STR_LIT:127.0.0.1>' ] , result ) <EOL> def test_get_user_info ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> openid = '<STR_LIT>' <EOL> user = self . client . user . get ( openid ) <EOL> self . assertEqual ( '<STR_LIT>' , user [ '<STR_LIT>' ] ) <EOL> def test_get_followers ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . user . get_followers ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , result [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , result [ '<STR_LIT:count>' ] ) <EOL> def test_update_user_remark ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> openid = '<STR_LIT>' <EOL> remark = '<STR_LIT:test>' <EOL> result = self . client . user . update_remark ( openid , remark ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_get_user_info_batch ( self ) : <EOL> user_list = [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . user . get_batch ( user_list ) <EOL> self . assertEqual ( user_list [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( user_list [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , result [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> def test_create_qrcode ( self ) : <EOL> data = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> } <EOL> } <EOL> } <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . qrcode . create ( data ) <EOL> self . assertEqual ( <NUM_LIT> , result [ '<STR_LIT>' ] ) <EOL> def test_get_qrcode_url_with_str_ticket ( self ) : <EOL> ticket = '<STR_LIT>' <EOL> url = self . client . qrcode . get_url ( ticket ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> url <EOL> ) <EOL> def test_get_qrcode_url_with_dict_ticket ( self ) : <EOL> ticket = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> url = self . client . qrcode . get_url ( ticket ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> url <EOL> ) <EOL> def test_customservice_add_account ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . add_account ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_update_account ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . update_account ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_delete_account ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . delete_account ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_upload_headimg ( self ) : <EOL> media_file = six . StringIO ( '<STR_LIT>' ) <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . upload_headimg ( <EOL> '<STR_LIT>' , <EOL> media_file <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_get_accounts ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_accounts ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_customservice_get_online_accounts ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_online_accounts ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_customservice_create_session ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . create_session ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_close_session ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . close_session ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_get_session ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_session ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , result [ '<STR_LIT>' ] ) <EOL> def test_customservice_get_session_list ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_session_list ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_customservice_get_wait_case ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_wait_case ( ) <EOL> self . assertEqual ( <NUM_LIT> , result [ '<STR_LIT:count>' ] ) <EOL> def test_customservice_get_records ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . customservice . get_records ( <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_datacube_get_user_summary ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_summary ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_user_cumulate ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_cumulate ( <EOL> datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:6> ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:7> ) <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_interface_summary ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_interface_summary ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_interface_summary_hour ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_interface_summary_hour ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_article_summary ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_article_summary ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_article_total ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_article_total ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_user_read ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_read ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_user_read_hour ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_read_hour ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_user_share ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_share ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_datacube_get_user_share_hour ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_user_share_hour ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_hour ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_hour ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_week ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_week ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_month ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_month ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_dist ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_dist ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_dist_week ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_dist_week ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_datacube_get_upstream_msg_dist_month ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . datacube . get_upstream_msg_dist_month ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> def test_jsapi_get_ticket ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> result = self . client . jsapi . get_ticket ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> result [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertEqual ( <NUM_LIT> , result [ '<STR_LIT>' ] ) <EOL> def test_jsapi_get_jsapi_signature ( self ) : <EOL> noncestr = '<STR_LIT>' <EOL> ticket = '<STR_LIT>' <EOL> timestamp = <NUM_LIT> <EOL> url = '<STR_LIT>' <EOL> signature = self . client . jsapi . get_jsapi_signature ( <EOL> noncestr , <EOL> ticket , <EOL> timestamp , <EOL> url <EOL> ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> signature <EOL> ) <EOL> def test_menu_get_menu_info ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> menu_info = self . client . menu . get_menu_info ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , menu_info [ '<STR_LIT>' ] ) <EOL> def test_message_get_autoreply_info ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> autoreply = self . client . message . get_autoreply_info ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , autoreply [ '<STR_LIT>' ] ) <EOL> def test_shakearound_apply_device_id ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . apply_device_id ( <NUM_LIT:1> , '<STR_LIT:test>' ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_update_device ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . update_device ( '<STR_LIT>' , comment = '<STR_LIT:test>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_bind_device_location ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . bind_device_location ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_search_device ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . search_device ( apply_id = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( res [ '<STR_LIT>' ] ) ) <EOL> def test_shakearound_add_page ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . add_page ( <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_update_page ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . update_page ( <EOL> <NUM_LIT> , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT:test>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_delete_page ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . delete_page ( <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_search_page ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . search_pages ( <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:2> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( res [ '<STR_LIT>' ] ) ) <EOL> def test_shakearound_add_material ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> media_file = six . StringIO ( '<STR_LIT>' ) <EOL> res = self . client . shakearound . add_material ( media_file , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> res [ '<STR_LIT>' ] <EOL> ) <EOL> def test_shakearound_bind_device_pages ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . bind_device_pages ( <EOL> <NUM_LIT> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_get_shake_info ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . get_shake_info ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_get_device_statistics ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . get_device_statistics ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( res ) ) <EOL> def test_shakearound_get_page_statistics ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . get_page_statistics ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( res ) ) <EOL> def test_material_get_count ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . material . get_count ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:3> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:4> , res [ '<STR_LIT>' ] ) <EOL> def test_shakearound_get_apply_status ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . shakearound . get_apply_status ( <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:4> , len ( res ) ) <EOL> def test_reraise_requests_exception ( self ) : <EOL> @ urlmatch ( netloc = r'<STR_LIT>' ) <EOL> def _wechat_api_mock ( url , request ) : <EOL> return { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:content>' : '<STR_LIT>' } <EOL> try : <EOL> with HTTMock ( _wechat_api_mock ) : <EOL> self . client . material . get_count ( ) <EOL> except WeChatClientException as e : <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) <EOL> def test_wifi_list_shops ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . list_shops ( ) <EOL> self . assertEqual ( <NUM_LIT:16> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , res [ '<STR_LIT>' ] ) <EOL> def test_wifi_add_device ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . add_device ( <EOL> <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_wifi_list_devices ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . list_devices ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , res [ '<STR_LIT>' ] ) <EOL> def test_wifi_delete_device ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . delete_device ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_wifi_get_qrcode_url ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> qrcode_url = self . client . wifi . get_qrcode_url ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> self . assertEqual ( '<STR_LIT>' , qrcode_url ) <EOL> def test_wifi_set_homepage ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . set_homepage ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_wifi_get_homepage ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . get_homepage ( <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:1> , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT:url>' ] ) <EOL> def test_wifi_list_statistics ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . wifi . list_statistics ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( res ) ) <EOL> def test_upload_mass_image ( self ) : <EOL> media_file = six . StringIO ( '<STR_LIT>' ) <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . media . upload_mass_image ( media_file ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> res <EOL> ) <EOL> def test_scan_get_merchant_info ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . get_merchant_info ( ) <EOL> self . assertEqual ( <NUM_LIT> , res [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_scan_create_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . create_product ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT>' ] ) <EOL> def test_scan_publish_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . publish_product ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_scan_unpublish_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . unpublish_product ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_scan_set_test_whitelist ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . set_test_whitelist ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_scan_get_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . get_product ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in res <EOL> def test_scan_list_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . list_product ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , res [ '<STR_LIT>' ] ) <EOL> def test_scan_update_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . update_product ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT>' ] ) <EOL> def test_scan_clear_product ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . clear_product ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , res [ '<STR_LIT>' ] ) <EOL> def test_scan_check_ticket ( self ) : <EOL> with HTTMock ( wechat_api_mock ) : <EOL> res = self . client . scan . check_ticket ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT>' ] ) </s>
