<s> from flask import url_for , session <EOL> from common . tests import BaseTestCase <EOL> from common . utils import get_signer <EOL> from accounts . models import User <EOL> from application import mail <EOL> class LoginViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to_about = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> resp = self . client . get ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> def test_form ( self ) : <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:username>' ] <EOL> ) <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:password>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( username = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:username>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:password>' ] <EOL> ) <EOL> with self . app . test_client ( ) as c : <EOL> self . assertFalse ( '<STR_LIT>' in session ) <EOL> resp = c . post ( <EOL> self . url , <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> self . assertTrue ( '<STR_LIT>' in session ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> self . assertTrue ( context [ '<STR_LIT:g>' ] . user ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp . data <EOL> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> next = self . redirect_to_about <EOL> ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to_about ) <EOL> class LogoutViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to_about = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> with self . app . test_client ( ) as c : <EOL> self . login ( username = '<STR_LIT>' , password = '<STR_LIT>' , client = c ) <EOL> self . assertTrue ( '<STR_LIT>' in session ) <EOL> resp = c . get ( self . url ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> self . assertFalse ( '<STR_LIT>' in session ) <EOL> with self . app . test_client ( ) as c : <EOL> self . login ( username = '<STR_LIT>' , password = '<STR_LIT>' , client = c ) <EOL> self . assertTrue ( '<STR_LIT>' in session ) <EOL> resp = c . get ( self . url + '<STR_LIT>' + self . redirect_to_about ) <EOL> self . assertRedirects ( resp , self . redirect_to_about ) <EOL> self . assertFalse ( '<STR_LIT>' in session ) <EOL> class SignupViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> resp = self . client . get ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> def test_form ( self ) : <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:email>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:email>' ] <EOL> ) <EOL> with mail . record_messages ( ) as outbox : <EOL> self . assertEquals ( len ( outbox ) , <NUM_LIT:0> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> self . assertEquals ( len ( outbox ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( <EOL> outbox [ <NUM_LIT:0> ] . subject , <EOL> u'<STR_LIT>' <EOL> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp . data <EOL> ) <EOL> class SignupConfirmViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . s = get_signer ( ) <EOL> self . data = { <EOL> '<STR_LIT:email>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> self . token = self . s . dumps ( self . data ) <EOL> self . data [ '<STR_LIT:email>' ] = u'<STR_LIT>' <EOL> self . token2 = self . s . dumps ( self . data ) <EOL> self . token3 = self . token + '<STR_LIT:a>' <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' , token = self . token ) <EOL> self . url2 = url_for ( '<STR_LIT>' , token = self . token2 ) <EOL> self . url3 = url_for ( '<STR_LIT>' , token = self . token3 ) <EOL> self . redirect_invalid = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to_about = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> resp = self . client . get ( self . url3 ) <EOL> self . assertRedirects ( resp , self . redirect_invalid ) <EOL> resp = self . client . get ( self . url3 , follow_redirects = True ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . data ) <EOL> resp = self . client . get ( self . url2 ) <EOL> self . assertRedirects ( resp , self . redirect_invalid ) <EOL> resp = self . client . get ( self . url2 , follow_redirects = True ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . data ) <EOL> resp = self . client . get ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> def test_form ( self ) : <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:name>' ] <EOL> ) <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:username>' ] <EOL> ) <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:password>' ] <EOL> ) <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( username = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:username>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( password = '<STR_LIT>' , password_confirm = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT>' ] <EOL> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> name = '<STR_LIT>' , <EOL> username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> password_confirm = '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> user . delete ( ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> name = '<STR_LIT>' , <EOL> username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> password_confirm = '<STR_LIT>' , <EOL> next = self . redirect_to_about <EOL> ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to_about ) <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> user . delete ( ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> name = '<STR_LIT>' , <EOL> username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> password_confirm = '<STR_LIT>' <EOL> ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp . data <EOL> ) <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> class RecoverPasswordViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> resp = self . client . get ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> def test_form ( self ) : <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:email>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:email>' ] <EOL> ) <EOL> with mail . record_messages ( ) as outbox : <EOL> self . assertEquals ( len ( outbox ) , <NUM_LIT:0> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> self . assertEquals ( len ( outbox ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( <EOL> outbox [ <NUM_LIT:0> ] . subject , <EOL> u'<STR_LIT>' <EOL> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( email = '<STR_LIT>' ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp . data <EOL> ) <EOL> class RecoverPasswordConfirmViewTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . s = get_signer ( ) <EOL> self . data = { <EOL> '<STR_LIT:email>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> self . token = self . s . dumps ( self . data ) <EOL> self . data [ '<STR_LIT:email>' ] = u'<STR_LIT>' <EOL> self . token2 = self . s . dumps ( self . data ) <EOL> self . token3 = self . token + '<STR_LIT:a>' <EOL> self . user = User ( <EOL> username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) . save ( ) <EOL> self . url = url_for ( '<STR_LIT>' , token = self . token ) <EOL> self . url2 = url_for ( '<STR_LIT>' , token = self . token2 ) <EOL> self . url3 = url_for ( '<STR_LIT>' , token = self . token3 ) <EOL> self . redirect_invalid = url_for ( '<STR_LIT>' ) <EOL> self . redirect_to = url_for ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> User . drop_collection ( ) <EOL> def test_render ( self ) : <EOL> resp = self . client . get ( self . url3 ) <EOL> self . assertRedirects ( resp , self . redirect_invalid ) <EOL> resp = self . client . get ( self . url3 , follow_redirects = True ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . data ) <EOL> resp = self . client . get ( self . url2 ) <EOL> self . assertRedirects ( resp , self . redirect_invalid ) <EOL> resp = self . client . get ( self . url2 , follow_redirects = True ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . data ) <EOL> resp = self . client . get ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> def test_form ( self ) : <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( self . url ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT:password>' ] <EOL> ) <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT>' ] <EOL> ) <EOL> with self . captured_templates ( self . app ) as templates : <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( password = '<STR_LIT>' , password_confirm = '<STR_LIT>' ) <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> template , context = templates [ <NUM_LIT:0> ] <EOL> form = context [ '<STR_LIT>' ] <EOL> self . assertTrue ( <EOL> u'<STR_LIT>' in form . errors [ '<STR_LIT>' ] <EOL> ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> password = '<STR_LIT>' , <EOL> password_confirm = '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertRedirects ( resp , self . redirect_to ) <EOL> self . user = User . objects . get ( pk = self . user . pk ) <EOL> self . assertTrue ( self . user . check_password ( '<STR_LIT>' ) ) <EOL> resp = self . client . post ( <EOL> self . url , <EOL> data = dict ( <EOL> password = '<STR_LIT>' , <EOL> password_confirm = '<STR_LIT>' <EOL> ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertStatus ( resp , <NUM_LIT:200> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp . data <EOL> ) <EOL> self . user = User . objects . get ( pk = self . user . pk ) <EOL> self . assertTrue ( self . user . check_password ( '<STR_LIT>' ) ) </s>
