<s> from nose . tools import * <EOL> from app . model . mailinglist import * <EOL> from email . utils import parseaddr <EOL> from webapp . librelist . models import MailingList , Subscription <EOL> from lamson . mail import MailRequest , MailResponse <EOL> from lamson . testing import * <EOL> user_full_address = '<STR_LIT>' <EOL> user_name , user_address = parseaddr ( user_full_address ) <EOL> list_name = "<STR_LIT>" <EOL> def setup ( ) : <EOL> MailingList . objects . all ( ) . delete ( ) <EOL> Subscription . objects . all ( ) . delete ( ) <EOL> def test_create_list ( ) : <EOL> mlist = create_list ( list_name ) <EOL> assert mlist <EOL> mlist_found = find_list ( list_name ) <EOL> assert mlist_found <EOL> assert_equal ( mlist . name , mlist_found . name ) <EOL> create_list ( list_name ) <EOL> assert_equal ( MailingList . objects . filter ( name = list_name ) . count ( ) , <NUM_LIT:1> ) <EOL> delete_list ( list_name ) <EOL> def test_delete_list ( ) : <EOL> delete_list ( list_name ) <EOL> mlist = find_list ( list_name ) <EOL> assert not mlist , "<STR_LIT>" % mlist <EOL> def test_remove_all_subscriptions ( ) : <EOL> test_add_subscriber ( ) <EOL> remove_all_subscriptions ( user_full_address ) <EOL> subs = find_subscriptions ( user_full_address ) <EOL> assert_equal ( len ( subs ) , <NUM_LIT:0> ) <EOL> def test_add_subscriber ( ) : <EOL> remove_all_subscriptions ( user_full_address ) <EOL> sub = add_subscriber ( user_full_address , list_name ) <EOL> assert sub <EOL> assert_equal ( sub . subscriber_address , user_address ) <EOL> assert_equal ( sub . subscriber_name , user_name ) <EOL> subs = find_subscriptions ( user_full_address ) <EOL> assert_equal ( len ( subs ) , <NUM_LIT:1> ) <EOL> def test_remove_subscriber ( ) : <EOL> test_add_subscriber ( ) <EOL> remove_subscriber ( user_full_address , list_name ) <EOL> subs = find_subscriptions ( user_full_address , list_name = list_name ) <EOL> assert_equal ( len ( subs ) , <NUM_LIT:0> ) <EOL> def test_post_message ( ) : <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> add_subscriber ( user_full_address , list_name ) <EOL> sample = MailResponse ( To = list_name + "<STR_LIT>" , <EOL> From = user_full_address , <EOL> Subject = "<STR_LIT>" , <EOL> Body = "<STR_LIT>" ) <EOL> sample [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> msg = MailRequest ( "<STR_LIT>" , sample [ '<STR_LIT>' ] , sample [ '<STR_LIT:to>' ] , str ( sample ) ) <EOL> post_message ( relay ( port = <NUM_LIT> ) , msg , list_name , "<STR_LIT>" ) <EOL> def test_disable_enable_all_subscriptions ( ) : <EOL> test_add_subscriber ( ) <EOL> disable_all_subscriptions ( user_address ) <EOL> assert not find_subscriptions ( user_address ) <EOL> enable_all_subscriptions ( user_address ) <EOL> assert find_subscriptions ( user_address ) <EOL> def test_similarily_named_lists ( ) : <EOL> test_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for name in test_names : <EOL> create_list ( name ) <EOL> similar = similar_named_lists ( list_name ) <EOL> assert_equal ( len ( similar ) , <NUM_LIT:2> ) <EOL> nothing = similar_named_lists ( "<STR_LIT>" ) <EOL> assert not nothing <EOL> similar = similar_named_lists ( '<STR_LIT>' ) <EOL> assert_equal ( len ( similar ) , <NUM_LIT:1> ) <EOL> def test_craft_response_attachment ( ) : <EOL> sample = MailResponse ( To = list_name + "<STR_LIT>" , <EOL> From = user_full_address , <EOL> Subject = "<STR_LIT>" , <EOL> Body = "<STR_LIT>" ) <EOL> sample . attach ( filename = "<STR_LIT>" , <EOL> content_type = "<STR_LIT>" , <EOL> disposition = "<STR_LIT>" ) <EOL> sample [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> im = sample . to_message ( ) <EOL> assert_equal ( len ( [ x for x in im . walk ( ) ] ) , <NUM_LIT:3> ) <EOL> inmsg = MailRequest ( "<STR_LIT>" , None , None , str ( sample ) ) <EOL> assert_equal ( len ( inmsg . all_parts ( ) ) , <NUM_LIT:2> ) <EOL> outmsg = craft_response ( inmsg , list_name , list_name + <EOL> "<STR_LIT>" ) <EOL> om = outmsg . to_message ( ) <EOL> assert_equal ( len ( [ x for x in om . walk ( ) ] ) , <EOL> len ( [ x for x in im . walk ( ) ] ) ) <EOL> assert '<STR_LIT>' in outmsg <EOL> def test_craft_response_no_attachment ( ) : <EOL> sample = MailResponse ( To = list_name + "<STR_LIT>" , <EOL> From = user_full_address , <EOL> Subject = "<STR_LIT>" , <EOL> Body = "<STR_LIT>" ) <EOL> im = sample . to_message ( ) <EOL> assert_equal ( len ( [ x for x in im . walk ( ) ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( im . get_payload ( ) , sample . Body ) <EOL> inmsg = MailRequest ( "<STR_LIT>" , None , None , str ( sample ) ) <EOL> assert_equal ( len ( inmsg . all_parts ( ) ) , <NUM_LIT:0> ) <EOL> assert_equal ( inmsg . body ( ) , sample . Body ) <EOL> outmsg = craft_response ( inmsg , list_name , list_name + <EOL> "<STR_LIT>" ) <EOL> om = outmsg . to_message ( ) <EOL> assert_equal ( om . get_payload ( ) , sample . Body ) <EOL> assert_equal ( len ( [ x for x in om . walk ( ) ] ) , <EOL> len ( [ x for x in im . walk ( ) ] ) ) </s>
