<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_config import cfg <EOL> import pecan <EOL> import pecan . testing <EOL> from six . moves . urllib import parse as urlparse <EOL> from ironic . tests . unit . db import base <EOL> PATH_PREFIX = '<STR_LIT>' <EOL> cfg . CONF . import_group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class BaseApiTest ( base . DbTestCase ) : <EOL> """<STR_LIT>""" <EOL> SOURCE_DATA = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> def setUp ( self ) : <EOL> super ( BaseApiTest , self ) . setUp ( ) <EOL> cfg . CONF . set_override ( "<STR_LIT>" , "<STR_LIT>" , <EOL> group = '<STR_LIT>' ) <EOL> cfg . CONF . set_override ( "<STR_LIT>" , "<STR_LIT>" , <EOL> group = '<STR_LIT>' ) <EOL> self . app = self . _make_app ( ) <EOL> def reset_pecan ( ) : <EOL> pecan . set_config ( { } , overwrite = True ) <EOL> self . addCleanup ( reset_pecan ) <EOL> p = mock . patch ( '<STR_LIT>' ) <EOL> self . _check_version = p . start ( ) <EOL> self . addCleanup ( p . stop ) <EOL> def _make_app ( self , enable_acl = False ) : <EOL> root_dir = self . path_get ( ) <EOL> self . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:root>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' % root_dir , <EOL> '<STR_LIT>' : '<STR_LIT>' % root_dir , <EOL> '<STR_LIT>' : enable_acl , <EOL> '<STR_LIT>' : [ '<STR_LIT:/>' , '<STR_LIT>' ] , <EOL> } , <EOL> } <EOL> return pecan . testing . load_test_app ( self . config ) <EOL> def _request_json ( self , path , params , expect_errors = False , headers = None , <EOL> method = "<STR_LIT>" , extra_environ = None , status = None , <EOL> path_prefix = PATH_PREFIX ) : <EOL> """<STR_LIT>""" <EOL> full_path = path_prefix + path <EOL> print ( '<STR_LIT>' % ( method . upper ( ) , full_path , params ) ) <EOL> response = getattr ( self . app , "<STR_LIT>" % method ) ( <EOL> str ( full_path ) , <EOL> params = params , <EOL> headers = headers , <EOL> status = status , <EOL> extra_environ = extra_environ , <EOL> expect_errors = expect_errors <EOL> ) <EOL> print ( '<STR_LIT>' % response ) <EOL> return response <EOL> def put_json ( self , path , params , expect_errors = False , headers = None , <EOL> extra_environ = None , status = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _request_json ( path = path , params = params , <EOL> expect_errors = expect_errors , <EOL> headers = headers , extra_environ = extra_environ , <EOL> status = status , method = "<STR_LIT>" ) <EOL> def post_json ( self , path , params , expect_errors = False , headers = None , <EOL> extra_environ = None , status = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _request_json ( path = path , params = params , <EOL> expect_errors = expect_errors , <EOL> headers = headers , extra_environ = extra_environ , <EOL> status = status , method = "<STR_LIT>" ) <EOL> def patch_json ( self , path , params , expect_errors = False , headers = None , <EOL> extra_environ = None , status = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _request_json ( path = path , params = params , <EOL> expect_errors = expect_errors , <EOL> headers = headers , extra_environ = extra_environ , <EOL> status = status , method = "<STR_LIT>" ) <EOL> def delete ( self , path , expect_errors = False , headers = None , <EOL> extra_environ = None , status = None , path_prefix = PATH_PREFIX ) : <EOL> """<STR_LIT>""" <EOL> full_path = path_prefix + path <EOL> print ( '<STR_LIT>' % ( full_path ) ) <EOL> response = self . app . delete ( str ( full_path ) , <EOL> headers = headers , <EOL> status = status , <EOL> extra_environ = extra_environ , <EOL> expect_errors = expect_errors ) <EOL> print ( '<STR_LIT>' % response ) <EOL> return response <EOL> def get_json ( self , path , expect_errors = False , headers = None , <EOL> extra_environ = None , q = [ ] , path_prefix = PATH_PREFIX , ** params ) : <EOL> """<STR_LIT>""" <EOL> full_path = path_prefix + path <EOL> query_params = { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> for query in q : <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:value>' ] : <EOL> query_params [ '<STR_LIT>' % name ] . append ( query . get ( name , '<STR_LIT>' ) ) <EOL> all_params = { } <EOL> all_params . update ( params ) <EOL> if q : <EOL> all_params . update ( query_params ) <EOL> print ( '<STR_LIT>' % ( full_path , all_params ) ) <EOL> response = self . app . get ( full_path , <EOL> params = all_params , <EOL> headers = headers , <EOL> extra_environ = extra_environ , <EOL> expect_errors = expect_errors ) <EOL> if not expect_errors : <EOL> response = response . json <EOL> print ( '<STR_LIT>' % response ) <EOL> return response <EOL> def validate_link ( self , link , bookmark = False ) : <EOL> """<STR_LIT>""" <EOL> url_parts = list ( urlparse . urlparse ( link ) ) <EOL> url_parts [ <NUM_LIT:0> ] = url_parts [ <NUM_LIT:1> ] = '<STR_LIT>' <EOL> if bookmark and url_parts [ <NUM_LIT:2> ] . startswith ( PATH_PREFIX ) : <EOL> return False <EOL> full_path = urlparse . urlunparse ( url_parts ) <EOL> try : <EOL> self . get_json ( full_path , path_prefix = '<STR_LIT>' ) <EOL> return True <EOL> except Exception : <EOL> return False </s>
