#NEWLINE# def _cast_ballot( self , election_id , username , password , need_login = True , check_user_logged_in = False ) : #NEWLINE# #INDENT# '\n        check_user_logged_in looks for the "you\'re already logged" message\n        ' #NEWLINE# response = self . app . post ( ( '/helios/elections/%s/encrypt-ballot' % election_id ) , { #NEWLINE# #INDENT# 'answers_json' : utils . to_json ( [ [ 1 ] ] ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertContains ( response , 'answers' ) #NEWLINE# the_ballot = utils . from_json ( response . testbody ) #NEWLINE# assert the_ballot [ 'answers' ] [ 0 ] . has_key ( 'randomness' ) , 'no randomness' #NEWLINE# assert ( len ( the_ballot [ 'answers' ] [ 0 ] [ 'randomness' ] ) == 2 ) , 'not enough randomness' #NEWLINE# ballot = datatypes . LDObject . fromDict ( utils . from_json ( response . testbody ) , type_hint = 'legacy/EncryptedVote' ) #NEWLINE# encrypted_vote = ballot . serialize ( ) #NEWLINE# response = self . app . post ( ( '/helios/elections/%s/cast' % election_id ) , { #NEWLINE# #INDENT# 'encrypted_vote' : encrypted_vote , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertRedirects ( response , ( '%s/helios/elections/%s/cast_confirm' % ( settings . SECURE_URL_HOST , election_id ) ) ) #NEWLINE# cast_confirm_page = response . follow ( ) #NEWLINE# if need_login : #NEWLINE# #INDENT# if check_user_logged_in : #NEWLINE# #INDENT# self . assertContains ( cast_confirm_page , 'You are logged in as' ) #NEWLINE# self . assertContains ( cast_confirm_page , 'requires election-specific credentials' ) #NEWLINE# #UNINDENT# login_form = cast_confirm_page . form #NEWLINE# login_form [ 'voter_id' ] = username #NEWLINE# login_form [ 'password' ] = password #NEWLINE# response = login_form . submit ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertContains ( cast_confirm_page , 'CAST this ballot' ) #NEWLINE# cast_form = cast_confirm_page . form #NEWLINE# if ( 'status_update' in cast_form . fields . keys ( ) ) : #NEWLINE# #INDENT# cast_form [ 'status_update' ] = False #NEWLINE# #UNINDENT# response = cast_form . submit ( ) #NEWLINE# #UNINDENT# self . assertRedirects ( response , ( '%s/helios/elections/%s/cast_done' % ( settings . URL_HOST , election_id ) ) ) #NEWLINE# email_message = mail . outbox [ ( len ( mail . outbox ) - 1 ) ] #NEWLINE# url = re . search ( 'http://[^/]+(/[^ \n]*)' , email_message . body ) . group ( 1 ) #NEWLINE# if ( not need_login ) : #NEWLINE# #INDENT# login_page = self . app . get ( ( '/helios/elections/%s/password_voter_login' % election_id ) ) #NEWLINE# if ( login_page . status_int != 302 ) : #NEWLINE# #INDENT# login_form = login_page . form #NEWLINE# login_form [ 'voter_id' ] = ( ( '  ' + username ) + '   ' ) #NEWLINE# login_form [ 'password' ] = ( ( '  ' + password ) + '      ' ) #NEWLINE# login_form . submit ( ) #NEWLINE# #UNINDENT# #UNINDENT# response = self . app . get ( url ) #NEWLINE# self . assertContains ( response , ballot . hash ) #NEWLINE# self . assertContains ( response , html_escape ( encrypted_vote ) ) #NEWLINE# response = self . app . get ( ( '/helios/elections/%s/cast_done' % election_id ) )