<s> """<STR_LIT>""" <EOL> import os <EOL> import pprint <EOL> import operator <EOL> import random <EOL> import md5 <EOL> import datetime <EOL> import chimpy <EOL> chimp = None <EOL> EMAIL_ADDRESS = '<STR_LIT>' <EOL> EMAIL_ADDRESS2 = '<STR_LIT>' <EOL> LIST_NAME = '<STR_LIT>' <EOL> LIST_ID = None <EOL> def setup_module ( ) : <EOL> assert '<STR_LIT>' in os . environ , "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> global chimp <EOL> chimp = chimpy . Connection ( os . environ [ '<STR_LIT>' ] ) <EOL> def test_ping ( ) : <EOL> assert chimp . ping ( ) == "<STR_LIT>" <EOL> def test_lists ( ) : <EOL> lists = chimp . lists ( ) <EOL> pprint . pprint ( lists ) <EOL> list_names = map ( lambda x : x [ '<STR_LIT:name>' ] , lists ) <EOL> assert LIST_NAME in list_names <EOL> def list_id ( ) : <EOL> global LIST_ID <EOL> if LIST_ID is None : <EOL> test_list = [ x for x in chimp . lists ( ) if x [ '<STR_LIT:name>' ] == LIST_NAME ] . pop ( ) <EOL> LIST_ID = test_list [ '<STR_LIT:id>' ] <EOL> return LIST_ID <EOL> def test_list_subscribe_and_unsubscribe ( ) : <EOL> result = chimp . list_subscribe ( list_id ( ) , EMAIL_ADDRESS , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> double_optin = False ) <EOL> pprint . pprint ( result ) <EOL> assert result == True <EOL> members = chimp . list_members ( list_id ( ) ) [ '<STR_LIT:data>' ] <EOL> print members <EOL> emails = map ( lambda x : x [ '<STR_LIT:email>' ] , members ) <EOL> print members <EOL> assert EMAIL_ADDRESS in emails <EOL> result = chimp . list_unsubscribe ( list_id ( ) , <EOL> EMAIL_ADDRESS , <EOL> delete_member = True , <EOL> send_goodbye = False , <EOL> send_notify = False ) <EOL> pprint . pprint ( result ) <EOL> assert result == True <EOL> def test_list_batch_subscribe_and_batch_unsubscribe ( ) : <EOL> batch = [ { '<STR_LIT>' : EMAIL_ADDRESS , '<STR_LIT>' : '<STR_LIT:html>' } , <EOL> { '<STR_LIT>' : EMAIL_ADDRESS2 , '<STR_LIT>' : '<STR_LIT:text>' } ] <EOL> result = chimp . list_batch_subscribe ( list_id ( ) , <EOL> batch , <EOL> double_optin = False , <EOL> update_existing = False , <EOL> replace_interests = False ) <EOL> assert result [ '<STR_LIT>' ] == <NUM_LIT:2> <EOL> members = chimp . list_members ( list_id ( ) ) [ '<STR_LIT:data>' ] <EOL> emails = map ( lambda x : x [ '<STR_LIT:email>' ] , members ) <EOL> assert EMAIL_ADDRESS in emails <EOL> assert EMAIL_ADDRESS2 in emails <EOL> result = chimp . list_batch_unsubscribe ( list_id ( ) , <EOL> [ EMAIL_ADDRESS , EMAIL_ADDRESS2 ] , <EOL> delete_member = True , <EOL> send_goodbye = False , <EOL> send_notify = False ) <EOL> assert result [ '<STR_LIT>' ] == <NUM_LIT:2> <EOL> def test_list_interest_groups_add_and_delete ( ) : <EOL> grouping_id = chimp . list_interest_groupings_add ( list_id ( ) , '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert len ( chimp . list_interest_groups ( list_id ( ) , grouping_id ) [ '<STR_LIT>' ] ) == <NUM_LIT:1> <EOL> assert chimp . list_interest_group_add ( list_id ( ) , '<STR_LIT:test>' , grouping_id ) <EOL> assert len ( chimp . list_interest_groups ( list_id ( ) , grouping_id ) [ '<STR_LIT>' ] ) == <NUM_LIT:2> <EOL> assert chimp . list_interest_group_del ( list_id ( ) , '<STR_LIT:test>' , grouping_id ) <EOL> assert len ( chimp . list_interest_groups ( list_id ( ) , grouping_id ) [ '<STR_LIT>' ] ) == <NUM_LIT:1> <EOL> assert ( chimp . list_interest_groupings_del ( grouping_id ) ) <EOL> def test_list_merge_vars_add_and_delete ( ) : <EOL> pprint . pprint ( chimp . list_merge_vars ( list_id ( ) ) ) <EOL> assert len ( chimp . list_merge_vars ( list_id ( ) ) ) == <NUM_LIT:3> <EOL> assert chimp . list_merge_var_add ( list_id ( ) , '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> assert len ( chimp . list_merge_vars ( list_id ( ) ) ) == <NUM_LIT:4> <EOL> assert chimp . list_merge_var_del ( list_id ( ) , '<STR_LIT:test>' ) <EOL> assert len ( chimp . list_merge_vars ( list_id ( ) ) ) == <NUM_LIT:3> <EOL> def test_list_update_member_and_member_info ( ) : <EOL> assert chimp . list_subscribe ( list_id ( ) , EMAIL_ADDRESS , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> double_optin = False ) <EOL> assert chimp . list_merge_var_add ( list_id ( ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> grouping_id = chimp . list_interest_groupings_add ( list_id ( ) , '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert chimp . list_update_member ( list_id ( ) , EMAIL_ADDRESS , <EOL> { '<STR_LIT>' : '<STR_LIT:abc>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , replace_interests = False ) <EOL> info = chimp . list_member_info ( list_id ( ) , EMAIL_ADDRESS ) <EOL> pprint . pprint ( info ) <EOL> assert chimp . list_merge_var_del ( list_id ( ) , '<STR_LIT>' ) <EOL> assert chimp . list_interest_group_del ( list_id ( ) , '<STR_LIT>' , grouping_id ) <EOL> assert chimp . list_interest_groupings_del ( grouping_id ) <EOL> assert chimp . list_unsubscribe ( list_id ( ) , EMAIL_ADDRESS , <EOL> delete_member = True , <EOL> send_goodbye = False , <EOL> send_notify = False ) <EOL> assert '<STR_LIT>' in info [ '<STR_LIT>' ] <EOL> assert info [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT:abc>' <EOL> def test_create_delete_campaign ( ) : <EOL> uid = md5 . new ( str ( random . random ( ) ) ) . hexdigest ( ) <EOL> subject = '<STR_LIT>' % uid <EOL> options = { '<STR_LIT>' : list_id ( ) , <EOL> '<STR_LIT>' : subject , <EOL> '<STR_LIT>' : EMAIL_ADDRESS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> segment_opts = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : '<STR_LIT:date>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:value>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT:email>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:value>' : '<STR_LIT:@>' } ] } <EOL> html = """<STR_LIT>""" <EOL> content = { '<STR_LIT:html>' : html } <EOL> cid = chimp . campaign_create ( '<STR_LIT>' , options , content , segment_opts = segment_opts ) <EOL> assert isinstance ( cid , basestring ) <EOL> campaigns = chimp . campaigns ( filter_subject = subject ) <EOL> assert len ( campaigns [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> <EOL> assert campaigns [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == cid <EOL> final_content = chimp . campaign_content ( cid ) <EOL> assert '<STR_LIT>' in final_content [ '<STR_LIT:html>' ] <EOL> assert '<STR_LIT>' in final_content [ '<STR_LIT:text>' ] <EOL> chimp . campaign_delete ( cid ) <EOL> def test_replicate_update_campaign ( ) : <EOL> """<STR_LIT>""" <EOL> uid = md5 . new ( str ( random . random ( ) ) ) . hexdigest ( ) <EOL> subject = '<STR_LIT>' % uid <EOL> options = { '<STR_LIT>' : list_id ( ) , <EOL> '<STR_LIT>' : subject , <EOL> '<STR_LIT>' : EMAIL_ADDRESS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> html = """<STR_LIT>""" <EOL> content = { '<STR_LIT:html>' : html } <EOL> cid = chimp . campaign_create ( '<STR_LIT>' , options , content ) <EOL> newcid = chimp . campaign_replicate ( cid = cid ) <EOL> assert isinstance ( newcid , basestring ) <EOL> newsubject = '<STR_LIT>' + uid <EOL> newtitle = '<STR_LIT>' + uid <EOL> res = chimp . campaign_update ( newcid , '<STR_LIT>' , newsubject ) <EOL> assert res is True <EOL> res = chimp . campaign_update ( newcid , '<STR_LIT:title>' , newtitle ) <EOL> assert res is True <EOL> chimp . campaign_delete ( newcid ) <EOL> chimp . campaign_delete ( cid ) <EOL> def test_schedule_campaign ( ) : <EOL> """<STR_LIT>""" <EOL> uid = md5 . new ( str ( random . random ( ) ) ) . hexdigest ( ) <EOL> subject = '<STR_LIT>' % uid <EOL> options = { '<STR_LIT>' : list_id ( ) , <EOL> '<STR_LIT>' : subject , <EOL> '<STR_LIT>' : EMAIL_ADDRESS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> html = """<STR_LIT>""" <EOL> content = { '<STR_LIT:html>' : html } <EOL> cid = chimp . campaign_create ( '<STR_LIT>' , options , content ) <EOL> schedule_time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> chimp . campaign_schedule ( cid , schedule_time ) <EOL> campaign = chimp . campaigns ( filter_subject = subject ) [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> assert campaign [ '<STR_LIT:status>' ] == '<STR_LIT>' <EOL> assert campaign [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> chimp . campaign_unschedule ( cid ) <EOL> campaign = chimp . campaigns ( filter_subject = subject ) [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> assert campaign [ '<STR_LIT:status>' ] == '<STR_LIT>' <EOL> chimp . campaign_delete ( cid ) <EOL> def test_rss_campaign ( ) : <EOL> """<STR_LIT>""" <EOL> uid = md5 . new ( str ( random . random ( ) ) ) . hexdigest ( ) <EOL> subject = '<STR_LIT>' % uid <EOL> options = { '<STR_LIT>' : list_id ( ) , <EOL> '<STR_LIT>' : subject , <EOL> '<STR_LIT>' : EMAIL_ADDRESS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> html = """<STR_LIT>""" <EOL> content = { '<STR_LIT:html>' : html } <EOL> type_opts = { '<STR_LIT:url>' : '<STR_LIT>' } <EOL> cid = chimp . campaign_create ( '<STR_LIT>' , options , content , type_opts = type_opts ) <EOL> campaign = chimp . campaigns ( filter_subject = subject ) [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> assert campaign [ '<STR_LIT:type>' ] == '<STR_LIT>' <EOL> chimp . campaign_delete ( cid ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> setup_module ( ) <EOL> for f in globals ( ) . keys ( ) : <EOL> if f . startswith ( '<STR_LIT>' ) and callable ( globals ( ) [ f ] ) : <EOL> print f <EOL> globals ( ) [ f ] ( ) </s>
