<s> import json <EOL> import mock <EOL> import unittest <EOL> from nose . tools import eq_ , ok_ <EOL> from . . constants import CONST <EOL> from . . test_base import TestCase <EOL> from pywechat . services . basic import Basic <EOL> from pywechat . services . wechat_shake import ShakeService <EOL> class ShakeServiceTest ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> TestCase . setUp ( self ) <EOL> with mock . patch . object ( Basic , '<STR_LIT>' , autospec = True ) : <EOL> self . shake_service = self . service . init_service ( '<STR_LIT>' ) <EOL> def test_apply_devices ( self ) : <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> apply_id = CONST . NUMBER <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . STRING <EOL> major = CONST . NUMBER <EOL> minor = CONST . NUMBER <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : apply_id , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : device_id , <EOL> "<STR_LIT>" : uuid , <EOL> "<STR_LIT>" : major , <EOL> "<STR_LIT>" : minor <EOL> } <EOL> ] <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> apply_reason = CONST . STRING <EOL> comment = CONST . STRING <EOL> data = self . shake_service . apply_devices ( <NUM_LIT:1> , <EOL> apply_reason , comment ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , apply_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , device_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , uuid ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , major ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , minor ) <EOL> def test_update_device ( self ) : <EOL> comment = CONST . STRING <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . NUMBER <EOL> major = CONST . NUMBER <EOL> minor = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . update_device ( comment , device_id ) <EOL> self . assertIsNotNone ( data ) <EOL> data = self . shake_service . update_device ( comment , uuid = uuid , <EOL> major = major , minor = minor ) <EOL> self . assertIsNotNone ( data ) <EOL> def test_bind_location ( self ) : <EOL> poi_id = CONST . NUMBER <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . NUMBER <EOL> major = CONST . NUMBER <EOL> minor = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . bind_location ( poi_id , device_id ) <EOL> self . assertIsNotNone ( data ) <EOL> data = self . shake_service . bind_location ( poi_id , uuid = uuid , <EOL> major = major , minor = minor ) <EOL> self . assertIsNotNone ( data ) <EOL> def test_search_device ( self ) : <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . NUMBER <EOL> major = CONST . NUMBER <EOL> minor = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : device_id , <EOL> "<STR_LIT>" : major , <EOL> "<STR_LIT>" : minor , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : uuid <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . search_device ( device_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , device_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , uuid ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , major ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , minor ) <EOL> data = self . shake_service . search_device ( uuid = uuid , <EOL> major = major , minor = minor ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , device_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , uuid ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , major ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , minor ) <EOL> def test_search_devices ( self ) : <EOL> apply_id = CONST . NUMBER <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . NUMBER <EOL> major = CONST . NUMBER <EOL> minor = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : device_id , <EOL> "<STR_LIT>" : major , <EOL> "<STR_LIT>" : minor , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : uuid <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . search_devices ( <NUM_LIT:0> , <NUM_LIT:1> , apply_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , device_id ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , uuid ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , major ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , minor ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> def test_upload_material ( self ) : <EOL> image = CONST . STRING <EOL> pic_url = CONST . STRING <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : pic_url <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . upload_material ( image ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , pic_url ) <EOL> def test_add_page ( self ) : <EOL> title = CONST . STRING <EOL> description = CONST . STRING <EOL> page_url = CONST . STRING <EOL> icon_url = CONST . STRING <EOL> comment = CONST . STRING <EOL> page_id = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : page_id <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . add_page ( title , description , page_url , <EOL> icon_url , comment ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , page_id ) <EOL> def test_update_page ( self ) : <EOL> title = CONST . STRING <EOL> description = CONST . STRING <EOL> page_url = CONST . STRING <EOL> icon_url = CONST . STRING <EOL> comment = CONST . STRING <EOL> page_id = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : page_id <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . update_page ( page_id , title , description , page_url , <EOL> icon_url , comment ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , page_id ) <EOL> def test_search_page_by_ids ( self ) : <EOL> title = CONST . STRING <EOL> description = CONST . STRING <EOL> page_url = CONST . STRING <EOL> icon_url = CONST . STRING <EOL> comment = CONST . STRING <EOL> page_id = CONST . NUMBER <EOL> page_ids = [ page_id ] <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : comment , <EOL> "<STR_LIT:description>" : description , <EOL> "<STR_LIT>" : icon_url , <EOL> "<STR_LIT>" : page_id , <EOL> "<STR_LIT>" : page_url , <EOL> "<STR_LIT:title>" : title <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . search_page_by_ids ( page_ids ) <EOL> page_data = { <EOL> "<STR_LIT>" : comment , <EOL> "<STR_LIT:description>" : description , <EOL> "<STR_LIT>" : icon_url , <EOL> "<STR_LIT>" : page_id , <EOL> "<STR_LIT>" : page_url , <EOL> "<STR_LIT:title>" : title <EOL> } <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , page_data ) <EOL> def test_search_page_by_counts ( self ) : <EOL> title = CONST . STRING <EOL> description = CONST . STRING <EOL> page_url = CONST . STRING <EOL> icon_url = CONST . STRING <EOL> comment = CONST . STRING <EOL> page_id = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : comment , <EOL> "<STR_LIT:description>" : description , <EOL> "<STR_LIT>" : icon_url , <EOL> "<STR_LIT>" : page_id , <EOL> "<STR_LIT>" : page_url , <EOL> "<STR_LIT:title>" : title <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . search_page_by_counts ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> page_data = { <EOL> "<STR_LIT>" : comment , <EOL> "<STR_LIT:description>" : description , <EOL> "<STR_LIT>" : icon_url , <EOL> "<STR_LIT>" : page_id , <EOL> "<STR_LIT>" : page_url , <EOL> "<STR_LIT:title>" : title <EOL> } <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , page_data ) <EOL> def test_delete_page ( self ) : <EOL> page_id = CONST . NUMBER <EOL> page_ids = [ page_id ] <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . delete_page ( page_ids ) <EOL> self . assertIsNotNone ( data ) <EOL> def test_bind_page ( self ) : <EOL> page_id = CONST . NUMBER <EOL> page_ids = [ page_id ] <EOL> bind = <NUM_LIT:0> <EOL> append = <NUM_LIT:0> <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . STRING <EOL> major = CONST . STRING <EOL> minor = CONST . STRING <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . bind_location ( page_ids ) <EOL> self . assertIsNotNone ( data ) <EOL> def test_get_shake_info ( self ) : <EOL> ticket = CONST . NUMBER <EOL> need_poi = <NUM_LIT:1> <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : { <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . get_shake_info ( ticket , need_poi ) <EOL> self . assertIsNotNone ( data ) <EOL> def test_device_statistics ( self ) : <EOL> begin_date = CONST . STRING <EOL> end_date = CONST . STRING <EOL> device_id = CONST . NUMBER <EOL> uuid = CONST . STRING <EOL> major = CONST . STRING <EOL> minor = CONST . STRING <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> ftime = CONST . NUMBER <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : [ <EOL> { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : ftime , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . device_statistics ( begin_date , end_date , <EOL> device_id , uuid , major , minor ) <EOL> statistics = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : ftime , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ <NUM_LIT:0> ] , statistics ) <EOL> def test_page_statistics ( self ) : <EOL> begin_date = CONST . STRING <EOL> end_date = CONST . STRING <EOL> page_id = CONST . NUMBER <EOL> with mock . patch . object ( ShakeService , '<STR_LIT>' ) as mock_method : <EOL> ftime = CONST . NUMBER <EOL> mock_method . return_value = { <EOL> "<STR_LIT:data>" : [ <EOL> { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : ftime , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> data = self . shake_service . page_statistics ( page_id , begin_date , <EOL> end_date ) <EOL> statistics = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : ftime , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> eq_ ( data [ "<STR_LIT:data>" ] [ <NUM_LIT:0> ] , statistics ) </s>
