<s> import os <EOL> import time <EOL> import unittest <EOL> from adnpy . cursor import cursor <EOL> from adnpy . utils import get_app_access_token <EOL> from config import AdnpyTestCase <EOL> test_post_id = <NUM_LIT:1> <EOL> class AdnpyAPITests ( AdnpyTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_posts_stream_global ( self ) : <EOL> self . api . posts_stream_global ( ) <EOL> def test_post ( self ) : <EOL> text = u'<STR_LIT>' <EOL> post , meta = self . api . create_post ( data = { '<STR_LIT:text>' : text } ) <EOL> self . assertEquals ( post . text , text ) <EOL> post , meta = self . api . get_post ( post ) <EOL> post , meta = self . api . delete_post ( post ) <EOL> post , meta = self . api . create_post ( data = { '<STR_LIT:text>' : text } ) <EOL> post , meta = post . delete ( ) <EOL> post , meta = self . api . repost_post ( <NUM_LIT> ) <EOL> post , meta = self . api . unrepost_post ( <NUM_LIT> ) <EOL> post , meta = self . api . star_post ( <NUM_LIT> ) <EOL> post , meta = self . api . unstar_post ( <NUM_LIT> ) <EOL> posts , meta = self . api . get_posts ( ids = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( posts ) , <NUM_LIT:3> ) <EOL> posts , meta = self . api . users_posts ( <NUM_LIT:3> ) <EOL> posts , meta = self . api . users_starred_posts ( <NUM_LIT:3> ) <EOL> posts , meta = self . api . users_mentioned_posts ( <NUM_LIT:3> ) <EOL> posts , meta = self . api . posts_with_hashtag ( '<STR_LIT>' ) <EOL> posts , meta = self . api . posts_with_hashtag ( <NUM_LIT:1> ) <EOL> posts , meta = self . api . users_post_stream ( ) <EOL> posts , meta = self . api . users_post_stream_unified ( ) <EOL> posts , meta = self . api . posts_stream_global ( ) <EOL> posts , meta = self . api . post_search ( text = '<STR_LIT>' ) <EOL> def test_user ( self ) : <EOL> display_name = u'<STR_LIT>' % ( time . time ( ) ) <EOL> user , meta = self . api . get_user ( '<STR_LIT>' ) <EOL> self . assertEquals ( self . username , user . username ) <EOL> old_name = user . name <EOL> user . name = display_name <EOL> cwd = os . path . dirname ( __file__ ) <EOL> del user . description [ '<STR_LIT>' ] <EOL> user , meta = self . api . update_user ( '<STR_LIT>' , data = user ) <EOL> self . assertEquals ( display_name , user . name ) <EOL> user , meta = self . api . patch_user ( '<STR_LIT>' , data = { '<STR_LIT:name>' : old_name } ) <EOL> self . assertEquals ( old_name , user . name ) <EOL> users , meta = self . api . get_users ( ids = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( users ) , <NUM_LIT:3> ) <EOL> with open ( cwd + '<STR_LIT>' ) as avatar : <EOL> user , meta = self . api . update_avatar ( '<STR_LIT>' , files = { '<STR_LIT>' : avatar } ) <EOL> with open ( cwd + '<STR_LIT>' ) as cover : <EOL> user , meta = self . api . update_cover ( '<STR_LIT>' , files = { '<STR_LIT>' : cover } ) <EOL> user , meta = self . api . follow_user ( <NUM_LIT:3> ) <EOL> user , meta = self . api . unfollow_user ( <NUM_LIT:3> ) <EOL> user , meta = self . api . mute_user ( <NUM_LIT:3> ) <EOL> user , meta = self . api . unmute_user ( <NUM_LIT:3> ) <EOL> user , meta = self . api . block_user ( <NUM_LIT:3> ) <EOL> user , meta = self . api . unblock_user ( <NUM_LIT:3> ) <EOL> users , meta = self . api . user_search ( q = '<STR_LIT>' ) <EOL> users , meta = self . api . users_following ( <NUM_LIT:3> ) <EOL> users , meta = self . api . users_followers ( <NUM_LIT:3> ) <EOL> users , meta = self . api . users_following_ids ( <NUM_LIT:3> ) <EOL> users , meta = self . api . users_followers_ids ( <NUM_LIT:3> ) <EOL> users , meta = self . api . users_muted_users ( '<STR_LIT>' ) <EOL> users , meta = self . api . users_muted_users_ids ( '<STR_LIT>' ) <EOL> users , meta = self . api . users_blocked_users ( '<STR_LIT>' ) <EOL> users , meta = self . api . users_reposted_post ( <NUM_LIT:1> ) <EOL> users , meta = self . api . users_starred_post ( <NUM_LIT:1> ) <EOL> def test_channel ( self ) : <EOL> channels , meta = self . api . subscribed_channels ( ) <EOL> channel , meta = self . api . create_channel ( data = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> } ) <EOL> channel_fetched , meta = self . api . get_channel ( channel ) <EOL> self . assertEquals ( channel . id , channel_fetched . id ) <EOL> channels , meta = self . api . get_channels ( ids = channel_fetched . id ) <EOL> channels , meta = self . api . users_channels ( ) <EOL> num_unread , meta = self . api . num_unread_pm_channels ( ) <EOL> channel_update = { <EOL> '<STR_LIT:id>' : channel . id , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> } <EOL> channel , meta = self . api . update_channel ( channel , data = channel_update ) <EOL> self . assertEquals ( channel_update [ '<STR_LIT>' ] [ '<STR_LIT>' ] , channel . writers . user_ids ) <EOL> channel , meta = self . api . subscribe_channel ( <NUM_LIT> ) <EOL> channel , meta = self . api . unsubscribe_channel ( <NUM_LIT> ) <EOL> users , meta = self . api . subscribed_users ( <NUM_LIT> ) <EOL> users , meta = self . api . subscribed_user_ids ( <NUM_LIT> ) <EOL> channel_user_ids , meta = self . api . subscribed_user_ids_for_channels ( ids = '<STR_LIT>' ) <EOL> channel , meta = self . api . mute_channel ( <NUM_LIT> ) <EOL> channels , meta = self . api . muted_channels ( <NUM_LIT> ) <EOL> channel , meta = self . api . unmute_channel ( <NUM_LIT> ) <EOL> def test_message ( self ) : <EOL> message1 , meta = self . api . create_message ( <NUM_LIT> , data = { '<STR_LIT:text>' : "<STR_LIT>" } ) <EOL> message2 , meta = self . api . create_message ( <NUM_LIT> , data = { '<STR_LIT:text>' : "<STR_LIT>" } ) <EOL> message , meta = self . api . get_message ( <NUM_LIT> , message1 ) <EOL> messages , meta = self . api . get_messages ( ids = '<STR_LIT>' % ( message1 . id , message2 . id ) ) <EOL> messages , meta = self . api . users_messages ( ) <EOL> messages , meta = self . api . get_channel_messages ( <NUM_LIT> ) <EOL> message , meta = self . api . delete_message ( <NUM_LIT> , message1 ) <EOL> message , meta = self . api . delete_message ( <NUM_LIT> , message2 ) <EOL> def test_file ( self ) : <EOL> cwd = os . path . dirname ( __file__ ) <EOL> ids = [ ] <EOL> with open ( cwd + '<STR_LIT>' ) as avatar : <EOL> file_ , meta = self . api . create_file ( files = { '<STR_LIT:content>' : avatar } , data = { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> ids += [ file_ . id ] <EOL> file_ , meta = self . api . get_file ( file_ . id ) <EOL> partial_file , meta = self . api . create_file ( data = { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> ids += [ file_ . id ] <EOL> self . api . update_file ( file_ . id , data = { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : { <EOL> '<STR_LIT:test>' : '<STR_LIT:test>' <EOL> } <EOL> } ] <EOL> } ) <EOL> self . api . create_custom_derived_file ( partial_file . id , '<STR_LIT>' , data = { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> with open ( cwd + '<STR_LIT>' ) as cover : <EOL> self . api . set_custom_derived_file_content ( partial_file . id , '<STR_LIT>' , data = cover , headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> with open ( cwd + '<STR_LIT>' ) as avatar : <EOL> self . api . set_file_content ( partial_file . id , data = avatar , headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> file_ , meta = self . api . get_file ( partial_file . id ) <EOL> files , meta = self . api . get_files ( ids = '<STR_LIT:U+002C>' . join ( ids ) ) <EOL> self . assertEquals ( len ( files ) , <NUM_LIT:2> ) <EOL> files , meta = self . api . get_my_files ( ) <EOL> self . assertGreaterEqual ( len ( files ) , <NUM_LIT:2> ) <EOL> self . api . get_file_content ( partial_file . id ) <EOL> self . api . get_custom_derived_file_content ( partial_file . id , '<STR_LIT>' ) <EOL> def test_interactions ( self ) : <EOL> interactions , meta = self . api . interactions_with_user ( ) <EOL> def test_text_process ( self ) : <EOL> text , meta = self . api . text_process ( data = { '<STR_LIT:text>' : "<STR_LIT>" } ) <EOL> def test_places ( self ) : <EOL> places , meta = self . api . search_places ( q = '<STR_LIT>' , latitude = '<STR_LIT>' , longitude = '<STR_LIT>' , radius = '<STR_LIT>' ) <EOL> place , meta = self . api . get_place ( places [ <NUM_LIT:0> ] ) <EOL> def test_token ( self ) : <EOL> token , meta = self . api . get_token ( ) <EOL> self . assertIsNotNone ( token . get ( '<STR_LIT:user>' ) ) <EOL> def test_config ( self ) : <EOL> config , meta = self . api . get_config ( ) <EOL> def test_explore_stream ( self ) : <EOL> explore_streams , meta = self . api . get_explore_streams ( ) <EOL> posts , meta = self . api . get_explore_stream ( explore_streams [ <NUM_LIT:0> ] ) <EOL> def test_stream_filters ( self ) : <EOL> stream_filters , meta = self . api . delete_all_filters ( ) <EOL> filter_def = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:value>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> "<STR_LIT:id>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" <EOL> } <EOL> stream_filter , meta = self . api . create_filter ( data = filter_def ) <EOL> stream_filter , meta = self . api . get_filter ( stream_filter ) <EOL> filter_def [ '<STR_LIT>' ] += [ { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:value>" : "<STR_LIT>" <EOL> } ] <EOL> stream_filter , meta = self . api . update_filter ( stream_filter , data = filter_def ) <EOL> self . assertEquals ( len ( stream_filter . clauses ) , <NUM_LIT:2> ) <EOL> stream_filter , meta = self . api . delete_filter ( stream_filter ) <EOL> stream_filter , meta = self . api . create_filter ( data = filter_def ) <EOL> filter_def [ '<STR_LIT:id>' ] = '<STR_LIT:2>' <EOL> stream_filter , meta = self . api . create_filter ( data = filter_def ) <EOL> stream_filters , meta = self . api . get_filters ( ) <EOL> self . assertEquals ( len ( stream_filters ) , <NUM_LIT:2> ) <EOL> stream_filters , meta = self . api . delete_all_filters ( ) <EOL> stream_filters , meta = self . api . get_filters ( ) <EOL> self . assertEquals ( len ( stream_filters ) , <NUM_LIT:0> ) <EOL> def test_app_stream ( self ) : <EOL> app_access_token , token = get_app_access_token ( self . client_id , self . client_secret ) <EOL> self . api . add_authorization_token ( app_access_token ) <EOL> self . api . delete_all_streams ( ) <EOL> stream_def = { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" <EOL> } <EOL> app_stream , meta = self . api . create_stream ( data = stream_def ) <EOL> app_stream , meta = self . api . get_stream ( app_stream ) <EOL> stream_def [ '<STR_LIT>' ] += [ "<STR_LIT>" ] <EOL> app_stream , meta = self . api . update_stream ( app_stream , data = stream_def ) <EOL> self . assertEquals ( len ( app_stream . object_types ) , <NUM_LIT:2> ) <EOL> app_stream , meta = self . api . delete_stream ( app_stream ) <EOL> app_stream , meta = self . api . create_stream ( data = stream_def ) <EOL> stream_def [ '<STR_LIT:key>' ] = "<STR_LIT>" <EOL> app_stream , meta = self . api . create_stream ( data = stream_def ) <EOL> app_streams , meta = self . api . get_streams ( ) <EOL> self . assertEquals ( len ( app_streams ) , <NUM_LIT:2> ) <EOL> app_streams , meta = self . api . delete_all_streams ( ) <EOL> app_streams , meta = self . api . get_streams ( ) <EOL> self . assertEquals ( len ( app_streams ) , <NUM_LIT:0> ) <EOL> def test_cursor ( self ) : <EOL> iterator = cursor ( self . api . posts_stream_global , count = <NUM_LIT:1> ) <EOL> post1 = iterator . next ( ) <EOL> post2 = iterator . next ( ) <EOL> self . assertNotEquals ( post1 . id , post2 . id ) <EOL> iterator = cursor ( self . api . get_explore_stream , '<STR_LIT>' ) <EOL> post1 = iterator . next ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
