<s> import datetime <EOL> import unittest <EOL> from flask . ext . login import current_user <EOL> from base import BaseTestCase <EOL> from project . server import bcrypt <EOL> from project . server . models import User <EOL> from project . server . user . forms import LoginForm <EOL> class TestUserBlueprint ( BaseTestCase ) : <EOL> def test_correct_login ( self ) : <EOL> with self . client : <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , <EOL> data = dict ( email = "<STR_LIT>" , password = "<STR_LIT>" ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> self . assertTrue ( current_user . email == "<STR_LIT>" ) <EOL> self . assertTrue ( current_user . is_active ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_logout_behaves_correctly ( self ) : <EOL> with self . client : <EOL> self . client . post ( <EOL> '<STR_LIT>' , <EOL> data = dict ( email = "<STR_LIT>" , password = "<STR_LIT>" ) , <EOL> follow_redirects = True <EOL> ) <EOL> response = self . client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> self . assertFalse ( current_user . is_active ) <EOL> def test_logout_route_requires_login ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> def test_member_route_requires_login ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> def test_validate_success_login_form ( self ) : <EOL> form = LoginForm ( email = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertTrue ( form . validate ( ) ) <EOL> def test_validate_invalid_email_format ( self ) : <EOL> form = LoginForm ( email = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertFalse ( form . validate ( ) ) <EOL> def test_get_by_id ( self ) : <EOL> with self . client : <EOL> self . client . post ( '<STR_LIT>' , data = dict ( <EOL> email = '<STR_LIT>' , password = '<STR_LIT>' <EOL> ) , follow_redirects = True ) <EOL> self . assertTrue ( current_user . id == <NUM_LIT:1> ) <EOL> def test_registered_on_defaults_to_datetime ( self ) : <EOL> with self . client : <EOL> self . client . post ( '<STR_LIT>' , data = dict ( <EOL> email = '<STR_LIT>' , password = '<STR_LIT>' <EOL> ) , follow_redirects = True ) <EOL> user = User . query . filter_by ( email = '<STR_LIT>' ) . first ( ) <EOL> self . assertIsInstance ( user . registered_on , datetime . datetime ) <EOL> def test_check_password ( self ) : <EOL> user = User . query . filter_by ( email = '<STR_LIT>' ) . first ( ) <EOL> self . assertTrue ( bcrypt . check_password_hash ( user . password , '<STR_LIT>' ) ) <EOL> self . assertFalse ( bcrypt . check_password_hash ( user . password , '<STR_LIT>' ) ) <EOL> def test_validate_invalid_password ( self ) : <EOL> with self . client : <EOL> response = self . client . post ( '<STR_LIT>' , data = dict ( <EOL> email = '<STR_LIT>' , password = '<STR_LIT>' <EOL> ) , follow_redirects = True ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> def test_register_route ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> def test_user_registration ( self ) : <EOL> with self . client : <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , <EOL> data = dict ( email = "<STR_LIT>" , password = "<STR_LIT>" , <EOL> confirm = "<STR_LIT>" ) , <EOL> follow_redirects = True <EOL> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . data ) <EOL> self . assertTrue ( current_user . email == "<STR_LIT>" ) <EOL> self . assertTrue ( current_user . is_active ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
