<s> from app import create_app <EOL> from app . config import test_config <EOL> from app . database import db <EOL> from app . user . models import User <EOL> from sqlalchemy . sql . expression import func <EOL> from faker import Factory <EOL> import unittest <EOL> admin_username = '<STR_LIT>' <EOL> admin_email = '<STR_LIT>' <EOL> admin_password = '<STR_LIT>' <EOL> fake = Factory . create ( ) <EOL> class TestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> app = create_app ( test_config ) <EOL> db . app = app <EOL> self . app = app . test_client ( ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def login ( self , username , password ) : <EOL> return self . app . post ( '<STR_LIT>' , data = dict ( <EOL> username = username , <EOL> password = password <EOL> ) , follow_redirects = True ) <EOL> def register_user ( self , username , email , password ) : <EOL> return self . app . post ( '<STR_LIT>' , data = dict ( <EOL> username = username , <EOL> email = email , <EOL> password = password , <EOL> confirm = password , <EOL> accept_tos = True <EOL> ) , follow_redirects = True ) <EOL> def edit_user ( self , user , email ) : <EOL> return self . app . post ( '<STR_LIT>' % user . id , data = dict ( <EOL> username = user . username , <EOL> email = user . email , <EOL> ) , follow_redirects = True ) <EOL> def delete_user ( self , uid ) : <EOL> return self . app . get ( '<STR_LIT>' % uid , follow_redirects = True ) <EOL> def test_404 ( self ) : <EOL> resp = self . app . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert '<STR_LIT>' in resp . data <EOL> def test_index ( self ) : <EOL> resp = self . app . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert '<STR_LIT>' in resp . data <EOL> def test_login ( self ) : <EOL> resp = self . login ( admin_username , admin_password ) <EOL> assert '<STR_LIT>' in resp . data <EOL> def test_logout ( self ) : <EOL> resp = self . login ( admin_username , admin_password ) <EOL> resp = self . app . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert '<STR_LIT>' in resp . data <EOL> def test_register_user ( self ) : <EOL> username = fake . userName ( ) <EOL> email = fake . email ( ) <EOL> password = fake . word ( ) + fake . word ( ) <EOL> resp = self . register_user ( username , email , password ) <EOL> assert '<STR_LIT>' % email in resp . data <EOL> def test_edit_user ( self ) : <EOL> user = User . query . order_by ( func . random ( ) ) . first ( ) <EOL> resp = self . login ( admin_username , admin_password ) <EOL> resp = self . edit_user ( user , email = fake . email ( ) ) <EOL> assert '<STR_LIT>' % user . username in resp . data <EOL> def test_delete_user ( self ) : <EOL> user = User . query . order_by ( func . random ( ) ) . first ( ) <EOL> resp = self . login ( admin_username , admin_password ) <EOL> resp = self . delete_user ( user . id ) <EOL> assert '<STR_LIT>' % user . username in resp . data <EOL> def test_user_list ( self ) : <EOL> resp = self . login ( admin_username , admin_password ) <EOL> resp = self . app . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert '<STR_LIT>' in resp . data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
