<s> import unittest <EOL> from cachebrowser . bootstrap import LocalBootstrapSource , BootstrapSourceError , BaseBootstrapSource , Bootstrapper , BootstrapValidationError , HostNotAvailableError , CDNNotAvailableError <EOL> from cachebrowser . models import initialize_database , Host , CDN <EOL> class LocalBootstrapSourceTest ( unittest . TestCase ) : <EOL> def test_valid_file ( self ) : <EOL> local_source = LocalBootstrapSource ( '<STR_LIT>' ) <EOL> host = local_source . lookup_host ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , host [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( True , host [ '<STR_LIT>' ] ) <EOL> cdn = local_source . lookup_cdn ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , cdn [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cdn [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( local_source . lookup_host ( "<STR_LIT>" ) ) <EOL> self . assertIsNone ( local_source . lookup_cdn ( "<STR_LIT>" ) ) <EOL> def test_no_type ( self ) : <EOL> with self . assertRaises ( BootstrapSourceError ) : <EOL> LocalBootstrapSource ( '<STR_LIT>' ) <EOL> def test_host_no_name ( self ) : <EOL> with self . assertRaises ( BootstrapSourceError ) : <EOL> LocalBootstrapSource ( '<STR_LIT>' ) <EOL> def test_host_no_cdn ( self ) : <EOL> with self . assertRaises ( BootstrapSourceError ) : <EOL> LocalBootstrapSource ( '<STR_LIT>' ) <EOL> def test_cdn_no_id ( self ) : <EOL> with self . assertRaises ( BootstrapSourceError ) : <EOL> LocalBootstrapSource ( '<STR_LIT>' ) <EOL> class BootstrapperTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> initialize_database ( "<STR_LIT>" , reset = True ) <EOL> self . source = BaseBootstrapSource ( ) <EOL> def lookup_host ( hostname ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } . get ( hostname , None ) <EOL> def lookup_cdn ( cdn_id ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> } . get ( cdn_id , None ) <EOL> self . source . lookup_host = lookup_host <EOL> self . source . lookup_cdn = lookup_cdn <EOL> self . bootstrapper = Bootstrapper ( ) <EOL> self . bootstrapper . add_source ( self . source ) <EOL> def test_bootstrap ( self ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> self . assertTrue ( Host . select ( ) . where ( Host . hostname == '<STR_LIT>' ) . exists ( ) ) <EOL> self . assertTrue ( CDN . select ( ) . where ( CDN . id == '<STR_LIT>' ) . exists ( ) ) <EOL> def test_unavailable_host__host_not_in_db ( self ) : <EOL> with self . assertRaises ( HostNotAvailableError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_unavailable_host__host_in_db__unavailable_cdn__cdn_in_db_with_no_edge ( self ) : <EOL> cdn = CDN . create ( id = "<STR_LIT>" ) <EOL> Host . create ( hostname = "<STR_LIT>" , cdn = cdn ) <EOL> with self . assertRaises ( CDNNotAvailableError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_unavailable_host__host_in_db__available_cdn__cdn_in_db_with_no_edge ( self ) : <EOL> cdn = CDN . create ( id = "<STR_LIT>" ) <EOL> Host . create ( hostname = "<STR_LIT>" , cdn = cdn ) <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_invalid_hostname ( self ) : <EOL> with self . assertRaises ( BootstrapValidationError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_invalid_host_data ( self ) : <EOL> with self . assertRaises ( BootstrapValidationError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_hostname_mismatch ( self ) : <EOL> with self . assertRaises ( BootstrapValidationError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) <EOL> def test_invalid_cdn_data ( self ) : <EOL> with self . assertRaises ( BootstrapValidationError ) : <EOL> self . bootstrapper . bootstrap ( '<STR_LIT>' ) </s>
