<s> import os <EOL> import os . path <EOL> import unittest <EOL> import sys <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> from client_test_lib import STATUS_NOT_FOUND <EOL> from client_test_lib import Bootstrap , ActionFailureTest <EOL> from client_test_lib import file_log , get_action , random_string <EOL> from client_test_lib import raise_exception <EOL> class FailureTest ( ActionFailureTest ) : <EOL> def test_missing_url ( self ) : <EOL> self . basic_test ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_url_failure ( self ) : <EOL> self . basic_test ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> attributes = { '<STR_LIT:url>' : random_string ( ) } ) <EOL> def test_bad_file_status ( self ) : <EOL> bootstrap = Bootstrap ( ztps_default_config = True ) <EOL> config = random_string ( ) <EOL> url = '<STR_LIT>' % ( bootstrap . server , config ) <EOL> bootstrap . ztps . set_definition_response ( <EOL> actions = [ { '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:url>' : url } } ] ) <EOL> bootstrap . ztps . set_action_response ( '<STR_LIT>' , <EOL> get_action ( '<STR_LIT>' ) ) <EOL> contents = random_string ( ) <EOL> bootstrap . ztps . set_file_response ( config , contents , <EOL> status = STATUS_NOT_FOUND ) <EOL> bootstrap . start_test ( ) <EOL> try : <EOL> self . failUnless ( bootstrap . action_failure ( ) ) <EOL> msg = [ x for x in bootstrap . output . split ( '<STR_LIT:\n>' ) if x ] [ - <NUM_LIT:1> ] <EOL> self . failUnless ( '<STR_LIT>' in msg ) <EOL> except AssertionError as assertion : <EOL> print '<STR_LIT>' % bootstrap . output <EOL> print '<STR_LIT>' % bootstrap . error <EOL> raise_exception ( assertion ) <EOL> finally : <EOL> bootstrap . end_test ( ) <EOL> class SuccessTest ( unittest . TestCase ) : <EOL> def test_success ( self ) : <EOL> bootstrap = Bootstrap ( ztps_default_config = True ) <EOL> config = random_string ( ) <EOL> url = config <EOL> bootstrap . ztps . set_definition_response ( <EOL> actions = [ { '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:url>' : url } } ] ) <EOL> bootstrap . ztps . set_action_response ( '<STR_LIT>' , <EOL> get_action ( '<STR_LIT>' ) ) <EOL> contents = random_string ( ) <EOL> bootstrap . ztps . set_file_response ( config , contents ) <EOL> bootstrap . start_test ( ) <EOL> try : <EOL> self . failUnless ( os . path . isfile ( bootstrap . startup_config ) ) <EOL> self . failUnless ( contents . split ( ) == <EOL> file_log ( bootstrap . startup_config ) ) <EOL> self . failUnless ( bootstrap . success ( ) ) <EOL> except AssertionError as assertion : <EOL> print '<STR_LIT>' % bootstrap . output <EOL> print '<STR_LIT>' % bootstrap . error <EOL> raise_exception ( assertion ) <EOL> finally : <EOL> bootstrap . end_test ( ) <EOL> def test_url_success ( self ) : <EOL> bootstrap = Bootstrap ( ztps_default_config = True ) <EOL> config = random_string ( ) <EOL> url = '<STR_LIT>' % ( bootstrap . server , config ) <EOL> bootstrap . ztps . set_definition_response ( <EOL> actions = [ { '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:url>' : url } } ] ) <EOL> bootstrap . ztps . set_action_response ( '<STR_LIT>' , <EOL> get_action ( '<STR_LIT>' ) ) <EOL> contents = random_string ( ) <EOL> bootstrap . ztps . set_file_response ( config , contents ) <EOL> bootstrap . start_test ( ) <EOL> try : <EOL> self . failUnless ( os . path . isfile ( bootstrap . startup_config ) ) <EOL> self . failUnless ( contents . split ( ) == <EOL> file_log ( bootstrap . startup_config ) ) <EOL> self . failUnless ( bootstrap . success ( ) ) <EOL> except AssertionError as assertion : <EOL> print '<STR_LIT>' % bootstrap . output <EOL> print '<STR_LIT>' % bootstrap . error <EOL> raise_exception ( assertion ) <EOL> finally : <EOL> bootstrap . end_test ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
