<s> import unittest <EOL> import os <EOL> from app import db , app <EOL> from app . models import Url <EOL> from app . views import random_key <EOL> basedir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> test_db_path = '<STR_LIT>' + os . path . join ( basedir , '<STR_LIT>' ) <EOL> class TestShrt ( unittest . TestCase ) : <EOL> test_url = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . client = app . test_client ( ) <EOL> app . config [ '<STR_LIT>' ] = test_db_path <EOL> app . config [ '<STR_LIT>' ] = True <EOL> self . key = random_key ( self . test_url ) <EOL> db . create_all ( ) <EOL> def tearDown ( self ) : <EOL> db . session . remove ( ) <EOL> db . drop_all ( ) <EOL> def test_index ( self ) : <EOL> r = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> assert '<STR_LIT>' in r . data <EOL> def test_flash_messages ( self ) : <EOL> form = { '<STR_LIT:url>' : '<STR_LIT>' } <EOL> r = self . client . post ( '<STR_LIT>' , data = form ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> assert "<STR_LIT>" in r . data <EOL> def test_404_error_handler ( self ) : <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> assert "<STR_LIT>" in r . data <EOL> def test_form ( self ) : <EOL> form = { '<STR_LIT:url>' : self . test_url } <EOL> r = self . client . post ( '<STR_LIT>' , data = form ) <EOL> l = Url . query . filter_by ( url = self . test_url ) . first ( ) <EOL> self . assertIsNotNone ( l ) <EOL> self . assertEqual ( l . random_code , self . key ) <EOL> def test_expand_shortened_link ( self ) : <EOL> link = Url ( self . key , self . test_url ) <EOL> db . session . add ( link ) <EOL> db . session . commit ( ) <EOL> r = self . client . get ( self . key ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> assert self . test_url and "<STR_LIT>" in r . data <EOL> def test_expand_unshortened_link ( self ) : <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> assert "<STR_LIT:/>" and "<STR_LIT>" in r . data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
