<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import mock <EOL> from viewfinder . backend . base import util <EOL> from viewfinder . backend . db . episode import Episode <EOL> from viewfinder . backend . db . follower import Follower <EOL> from viewfinder . backend . db . identity import Identity <EOL> from viewfinder . backend . db . operation import Operation <EOL> from viewfinder . backend . db . post import Post <EOL> from viewfinder . backend . db . settings import AccountSettings <EOL> from viewfinder . backend . db . user import User <EOL> from viewfinder . backend . db . viewpoint import Viewpoint <EOL> from viewfinder . backend . www import system_users <EOL> from viewfinder . backend . www . system_users import CreateSystemUsers <EOL> from viewfinder . backend . www . test import service_base_test <EOL> class CreateProspectiveTestCase ( service_base_test . ServiceBaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( CreateProspectiveTestCase , self ) . setUp ( ) <EOL> self . _CreateSimpleTestAssets ( ) <EOL> self . _vp_id , self . _ep_id = self . _ShareSimpleTestAssets ( [ self . _user2 . user_id ] ) <EOL> def testProspectiveUser ( self ) : <EOL> """<STR_LIT>""" <EOL> user , vp_id , ep_id = self . _CreateProspectiveUser ( ) <EOL> self . assertEqual ( user . asset_id_seq , <NUM_LIT:1> ) <EOL> settings = self . _RunAsync ( AccountSettings . QueryByUser , self . _client , user . user_id , None ) <EOL> self . assertEqual ( settings . email_alerts , AccountSettings . EMAIL_ON_SHARE_NEW ) <EOL> self . assertEqual ( settings . sms_alerts , AccountSettings . SMS_NONE ) <EOL> self . assertEqual ( settings . push_alerts , AccountSettings . PUSH_NONE ) <EOL> @ mock . patch . object ( system_users , '<STR_LIT>' , None ) <EOL> def testWelcomeUsers ( self ) : <EOL> """<STR_LIT>""" <EOL> def _TestUser ( email ) : <EOL> identity = self . _RunAsync ( Identity . Query , self . _client , '<STR_LIT>' % email , None ) <EOL> self . assertEqual ( identity . authority , '<STR_LIT>' ) <EOL> user = self . _RunAsync ( User . Query , self . _client , identity . user_id , None ) <EOL> self . assertTrue ( user . IsRegistered ( ) ) <EOL> self . assertTrue ( user . IsSystem ( ) ) <EOL> self . assertEqual ( user . email , email ) <EOL> settings = self . _RunAsync ( AccountSettings . QueryByUser , self . _client , identity . user_id , None ) <EOL> self . assertEqual ( settings . email_alerts , AccountSettings . EMAIL_NONE ) <EOL> return user . name , user . given_name , user . family_name <EOL> def _TestUpload ( user , upload_request ) : <EOL> cookie = self . _GetSecureUserCookie ( user , user . webapp_dev_id ) <EOL> ep_select = self . _tester . CreateEpisodeSelection ( upload_request [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> get_attributes = True , <EOL> get_photos = True ) <EOL> response_dict = self . _tester . SendRequest ( '<STR_LIT>' , cookie , { '<STR_LIT>' : [ ep_select ] } ) <EOL> ep_dict = response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( upload_request [ '<STR_LIT>' ] ) , len ( ep_dict [ '<STR_LIT>' ] ) ) <EOL> for ph_dict in response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] : <EOL> for suffix , size_attr in ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> response = self . _tester . GetPhotoImage ( cookie , ep_dict [ '<STR_LIT>' ] , ph_dict [ '<STR_LIT>' ] , suffix ) <EOL> self . assertEqual ( len ( response . body ) , ph_dict [ size_attr ] ) <EOL> self . _RunAsync ( CreateSystemUsers , self . _client ) <EOL> self . assertEqual ( _TestUser ( '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' , None ) ) <EOL> _TestUpload ( system_users . NARRATOR_USER , system_users . NARRATOR_UPLOAD_PHOTOS ) <EOL> @ mock . patch . object ( Operation , '<STR_LIT>' , True ) <EOL> @ mock . patch . object ( system_users , '<STR_LIT>' , None ) <EOL> def testWelcomeConversation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _validate = False <EOL> validator = self . _tester . validator <EOL> self . _RunAsync ( CreateSystemUsers , self . _client ) <EOL> request_dict = { '<STR_LIT>' : self . _tester . CreateActivityDict ( self . _cookie ) , <EOL> '<STR_LIT>' : self . _vp_id , <EOL> '<STR_LIT>' : self . _tester . CreateContactDicts ( [ '<STR_LIT>' , '<STR_LIT>' ] ) } <EOL> response_dict = self . _tester . SendRequest ( '<STR_LIT>' , self . _cookie , request_dict ) <EOL> identity = self . _RunAsync ( Identity . Query , self . _client , '<STR_LIT>' , None ) <EOL> user = self . _RunAsync ( User . Query , self . _client , identity . user_id , None ) <EOL> welcome_vp_id = Viewpoint . ConstructViewpointId ( user . webapp_dev_id , <NUM_LIT:1> ) <EOL> viewpoint = self . _RunAsync ( Viewpoint . Query , self . _client , welcome_vp_id , None ) <EOL> query_expr = ( '<STR_LIT>' , { '<STR_LIT:id>' : system_users . NARRATOR_UPLOAD_PHOTOS [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> cover_photo_ep = self . _RunAsync ( Episode . IndexQuery , self . _client , query_expr , None ) [ <NUM_LIT:0> ] <EOL> cover_photo = { '<STR_LIT>' : cover_photo_ep . episode_id , <EOL> '<STR_LIT>' : system_users . NARRATOR_UPLOAD_PHOTOS [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] } <EOL> validator . ValidateUpdateDBObject ( Viewpoint , <EOL> viewpoint_id = welcome_vp_id , <EOL> user_id = system_users . NARRATOR_USER . user_id , <EOL> title = '<STR_LIT>' , <EOL> type = Viewpoint . SYSTEM , <EOL> timestamp = util . _TEST_TIME , <EOL> update_seq = <NUM_LIT> , <EOL> cover_photo = cover_photo ) <EOL> followers , _ = self . _RunAsync ( Viewpoint . QueryFollowers , self . _client , welcome_vp_id ) <EOL> for follower in followers : <EOL> if follower . user_id != user . user_id : <EOL> self . assertTrue ( follower . IsRemoved ( ) ) <EOL> self . assertEqual ( follower . viewed_seq , viewpoint . update_seq ) <EOL> else : <EOL> self . assertTrue ( not follower . IsRemoved ( ) ) <EOL> self . assertEqual ( follower . viewed_seq , <NUM_LIT:0> ) <EOL> episodes , _ = self . _RunAsync ( Viewpoint . QueryEpisodes , self . _client , welcome_vp_id ) <EOL> self . assertEqual ( len ( episodes ) , <NUM_LIT:3> ) <EOL> num_posts = sum ( len ( self . _RunAsync ( Post . RangeQuery , self . _client , episode . episode_id , None , None , None ) ) <EOL> for episode in episodes ) <EOL> self . assertEqual ( num_posts , <NUM_LIT:9> ) <EOL> cookie = self . _GetSecureUserCookie ( user , user . webapp_dev_id ) <EOL> vp_select = self . _tester . CreateViewpointSelection ( welcome_vp_id ) <EOL> response_dict = self . _tester . SendRequest ( '<STR_LIT>' , cookie , { '<STR_LIT>' : [ vp_select ] } ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:12> ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:3> ) <EOL> ep_select_list = [ self . _tester . CreateEpisodeSelection ( ep_dict [ '<STR_LIT>' ] ) <EOL> for ep_dict in response_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ] <EOL> response_dict = self . _tester . SendRequest ( '<STR_LIT>' , cookie , { '<STR_LIT>' : ep_select_list } ) <EOL> self . assertEqual ( len ( [ ph_dict for ep_dict in response_dict [ '<STR_LIT>' ] for ph_dict in ep_dict [ '<STR_LIT>' ] ] ) , <NUM_LIT:9> ) <EOL> validator . ValidateAccounting ( ) </s>
