<s> import base64 <EOL> import json <EOL> import os . path <EOL> import uuid <EOL> import mock <EOL> from oslo_config import cfg <EOL> from solum . common import exception <EOL> from solum . openstack . common . gettextutils import _ <EOL> from solum . tests import base <EOL> from solum . tests import fakes <EOL> from solum . tests import utils <EOL> from solum . worker . handlers import shell as shell_handler <EOL> def mock_environment ( ) : <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } <EOL> def mock_git_info ( ) : <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def mock_request_hdr ( token ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' + token , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } <EOL> def mock_req_pending_body ( log_url ) : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> return json . dumps ( data ) <EOL> def mock_req_success_body ( log_url ) : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT:success>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> return json . dumps ( data ) <EOL> def mock_req_failure_body ( log_url ) : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> return json . dumps ( data ) <EOL> def mock_http_response ( ) : <EOL> return { '<STR_LIT:status>' : '<STR_LIT>' } , '<STR_LIT>' <EOL> class HandlerTest ( base . BaseTestCase ) : <EOL> scenarios = [ <EOL> ( '<STR_LIT>' , <EOL> dict ( base_image_id = '<STR_LIT>' , <EOL> expected_img_id = '<STR_LIT>' , <EOL> img_name = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> dict ( base_image_id = '<STR_LIT>' , <EOL> expected_img_id = '<STR_LIT>' , <EOL> img_name = '<STR_LIT>' ) ) ] <EOL> def setUp ( self ) : <EOL> super ( HandlerTest , self ) . setUp ( ) <EOL> self . ctx = utils . dummy_context ( ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_get_du_details_glance ( self , mock_client ) : <EOL> handler = shell_handler . Handler ( ) <EOL> du_id = '<STR_LIT>' <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> fake_du = fakes . FakeImage ( ) <EOL> fake_du . id = <NUM_LIT:2> <EOL> fake_du . name = '<STR_LIT:name>' <EOL> mock_glance = mock_client . return_value . glance <EOL> mock_get = mock_glance . return_value . images . get <EOL> mock_get . return_value = fake_du <EOL> du_loc , du_name = handler . get_du_details ( self . ctx , du_id ) <EOL> self . assertTrue ( mock_get . called ) <EOL> self . assertTrue ( du_loc , <NUM_LIT:2> ) <EOL> self . assertTrue ( du_name , '<STR_LIT:name>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_get_du_details_GLANCE ( self , mock_client ) : <EOL> handler = shell_handler . Handler ( ) <EOL> du_id = '<STR_LIT>' <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> fake_du = fakes . FakeImage ( ) <EOL> fake_du . id = <NUM_LIT:2> <EOL> fake_du . name = '<STR_LIT:name>' <EOL> mock_glance = mock_client . return_value . glance <EOL> mock_get = mock_glance . return_value . images . get <EOL> mock_get . return_value = fake_du <EOL> du_loc , du_name = handler . get_du_details ( self . ctx , du_id ) <EOL> self . assertTrue ( mock_get . called ) <EOL> self . assertTrue ( du_loc , <NUM_LIT:2> ) <EOL> self . assertTrue ( du_name , '<STR_LIT:name>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_get_du_details_swift ( self , mock_client ) : <EOL> handler = shell_handler . Handler ( ) <EOL> du_id = '<STR_LIT>' <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> try : <EOL> handler . get_du_details ( self . ctx , du_id ) <EOL> self . assertTrue ( False ) <EOL> except exception . NotImplemented : <EOL> self . assertTrue ( True ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build ( self , mock_popen , mock_deploy , mock_b_update , mock_uas , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . build ( self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , <EOL> name = '<STR_LIT>' , base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> assembly_id = <NUM_LIT> , run_cmd = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , <EOL> stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> fake_glance_id , fake_image_name , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> assert not mock_deploy . called <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_swft ( self , mock_popen , mock_deploy , mock_b_update , mock_uas , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_by_uuid . return_value = fake_image <EOL> mock_registry . Image . get_lp_by_name_or_uuid = fake_image <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . build ( self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , name = '<STR_LIT>' , <EOL> base_image_id = fake_image . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> assembly_id = <NUM_LIT> , run_cmd = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> expected_loc = fake_image . external_ref <EOL> expected_tag = fake_image . docker_image_name <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> expected_loc , expected_tag ] , <EOL> env = test_env , <EOL> stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> fake_glance_id , fake_image_name , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> assert not mock_deploy . called <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_with_private_github_repo ( <EOL> self , mock_ast , mock_popen , mock_deploy , mock_uas , mock_b_update , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> handler . _update_assembly_status = mock . MagicMock ( ) <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> mock_ast . return_value = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> git_info = mock_git_info ( ) <EOL> handler . launch_workflow ( <EOL> self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , <EOL> workflow = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , ports = [ <NUM_LIT> ] , <EOL> name = '<STR_LIT>' , base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , <EOL> test_cmd = None , run_cmd = None , du_id = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> fake_glance_id , fake_image_name , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> expected = [ mock . call ( assembly_id = <NUM_LIT> , image_loc = fake_glance_id , <EOL> image_name = fake_image_name , <EOL> ports = [ <NUM_LIT> ] ) ] <EOL> self . assertEqual ( expected , mock_deploy . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_with_private_github_repo_with_shelve ( <EOL> self , mock_ast , mock_shelve , mock_popen , <EOL> mock_deploy , mock_uas , mock_b_update , mock_registry , <EOL> mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> handler . _update_assembly_status = mock . MagicMock ( ) <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <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> mock_shelve . return_value = mock . MagicMock ( ) <EOL> base64 . b64decode = mock . MagicMock ( ) <EOL> mock_ast . return_value = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> git_info = mock_git_info ( ) <EOL> handler . launch_workflow ( <EOL> self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , <EOL> workflow = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , ports = [ <NUM_LIT> ] , <EOL> name = '<STR_LIT>' , base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , <EOL> test_cmd = None , run_cmd = None , du_id = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> fake_glance_id , fake_image_name , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> expected = [ mock . call ( assembly_id = <NUM_LIT> , image_loc = fake_glance_id , <EOL> image_name = fake_image_name , <EOL> ports = [ <NUM_LIT> ] ) ] <EOL> self . assertEqual ( expected , mock_deploy . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_fail ( self , mock_popen , mock_uas , mock_b_update , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . build ( self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , name = '<STR_LIT>' , <EOL> base_image_id = self . base_image_id , source_format = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , run_cmd = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , None , None , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_error ( self , mock_popen , mock_uas , mock_b_update , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . call . return_value = ValueError <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . build ( self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , name = '<STR_LIT>' , <EOL> base_image_id = self . base_image_id , source_format = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , run_cmd = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , None , None , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) , <EOL> mock . call ( <NUM_LIT> , { '<STR_LIT:status>' : '<STR_LIT>' } ) ] <EOL> self . assertEqual ( expected , mock_uas . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_unittest ( self , mock_a_update , mock_popen , mock_registry , <EOL> mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> mock_popen . return_value . wait . return_value = <NUM_LIT:0> <EOL> git_info = mock_git_info ( ) <EOL> handler . unittest ( self . ctx , build_id = <NUM_LIT:5> , name = '<STR_LIT>' , <EOL> base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> assembly_id = fake_assembly . id , <EOL> git_info = git_info , test_cmd = '<STR_LIT>' ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , <EOL> '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( self . ctx , <NUM_LIT:8> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT:8> , '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected , mock_a_update . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_unittest_failure ( self , mock_a_update , mock_popen , <EOL> mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> mock_popen . return_value . wait . return_value = <NUM_LIT:1> <EOL> git_info = mock_git_info ( ) <EOL> handler . unittest ( self . ctx , build_id = <NUM_LIT:5> , name = '<STR_LIT>' , <EOL> assembly_id = fake_assembly . id , <EOL> base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' , <EOL> git_info = git_info , test_cmd = '<STR_LIT>' ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , <EOL> '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant , <EOL> self . expected_img_id , <EOL> self . img_name ] , <EOL> env = test_env , stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( self . ctx , <NUM_LIT:8> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT:8> , '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected , mock_a_update . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_unittest_build_deploy ( self , mock_deploy , mock_a_update , <EOL> mock_b_update , mock_popen , mock_registry , <EOL> mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_assembly = fakes . FakeAssembly ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Assembly . get_by_id . return_value = fake_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . return_value . wait . return_value = <NUM_LIT:0> <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . launch_workflow ( <EOL> self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , <EOL> workflow = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , ports = [ <NUM_LIT> ] , <EOL> name = '<STR_LIT>' , base_image_id = self . base_image_id , <EOL> source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , <EOL> test_cmd = '<STR_LIT>' , run_cmd = None , du_id = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> util_dir = os . path . join ( proj_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u_script = os . path . join ( util_dir , '<STR_LIT>' ) <EOL> b_script = os . path . join ( util_dir , '<STR_LIT>' ) <EOL> expected = [ <EOL> mock . call ( [ u_script , '<STR_LIT>' , '<STR_LIT>' , <EOL> self . ctx . tenant , self . expected_img_id , <EOL> self . img_name ] , env = test_env , <EOL> stdout = - <NUM_LIT:1> ) , <EOL> mock . call ( [ b_script , '<STR_LIT>' , '<STR_LIT>' , <EOL> self . ctx . tenant , self . expected_img_id , <EOL> self . img_name ] , env = test_env , <EOL> stdout = - <NUM_LIT:1> ) ] <EOL> self . assertEqual ( expected , mock_popen . call_args_list ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> None , None , <NUM_LIT> ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' , <EOL> fake_glance_id , fake_image_name , <NUM_LIT> ) ] <EOL> self . assertEqual ( expected , mock_b_update . call_args_list ) <EOL> expected = [ mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected , mock_a_update . call_args_list ) <EOL> expected = [ mock . call ( assembly_id = <NUM_LIT> , image_loc = fake_glance_id , <EOL> image_name = fake_image_name , <EOL> ports = [ <NUM_LIT> ] ) ] <EOL> self . assertEqual ( expected , mock_deploy . call_args_list ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_unittest_no_build ( self , mock_registry , mock_a_update , mock_popen , <EOL> mock_get_env , mock_do_build ) : <EOL> handler = shell_handler . Handler ( ) <EOL> mock_assembly = mock . MagicMock ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = mock_assembly <EOL> fake_image = fakes . FakeImage ( ) <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . return_value . wait . return_value = <NUM_LIT:1> <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . launch_workflow ( <EOL> self . ctx , build_id = <NUM_LIT:5> , git_info = git_info , name = '<STR_LIT>' , <EOL> base_image_id = self . base_image_id , source_format = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' , assembly_id = <NUM_LIT> , ports = [ <NUM_LIT> ] , <EOL> test_cmd = '<STR_LIT>' , run_cmd = None , workflow = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> du_id = None ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> util_dir = os . path . join ( proj_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u_script = os . path . join ( util_dir , '<STR_LIT>' ) <EOL> expected = [ <EOL> mock . call ( [ u_script , '<STR_LIT>' , '<STR_LIT>' , <EOL> self . ctx . tenant , self . expected_img_id , <EOL> self . img_name ] , env = test_env , <EOL> stdout = - <NUM_LIT:1> ) ] <EOL> self . assertEqual ( expected , mock_popen . call_args_list ) <EOL> expected = [ mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) , <EOL> mock . call ( self . ctx , <NUM_LIT> , '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected , mock_a_update . call_args_list ) <EOL> assert not mock_do_build . called <EOL> class HandlerUtilityTest ( base . BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( HandlerUtilityTest , self ) . setUp ( ) <EOL> self . ctx = utils . dummy_context ( ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_echo ( self , fake_LOG ) : <EOL> shell_handler . Handler ( ) . echo ( { } , '<STR_LIT:foo>' ) <EOL> fake_LOG . debug . assert_called_once_with ( _ ( '<STR_LIT:%s>' ) % '<STR_LIT:foo>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_get_parameter_files ( self , mock_mkdirs , mock_open , mock_param ) : <EOL> mock_param . return_value = { "<STR_LIT>" : { '<STR_LIT:key>' : '<STR_LIT>' } } <EOL> fake_build_id = '<STR_LIT>' <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> path = '<STR_LIT>' + fake_build_id <EOL> handler = shell_handler . Handler ( ) <EOL> handler . _get_parameter_env ( self . ctx , '<STR_LIT>' , <EOL> <NUM_LIT:8> , fake_build_id ) <EOL> mock_mkdirs . assert_called_once_with ( path , <NUM_LIT> ) <EOL> expected = [ mock . call ( path + '<STR_LIT>' , '<STR_LIT:w>' ) , <EOL> mock . call ( path + '<STR_LIT>' , '<STR_LIT:w>' ) ] <EOL> self . assertEqual ( expected , mock_open . call_args_list ) <EOL> mock_file = mock_open . return_value . __enter__ . return_value <EOL> expected_params = [ mock . call ( '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected_params , mock_file . write . call_args_list ) <EOL> class TestNotifications ( base . BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNotifications , self ) . setUp ( ) <EOL> self . ctx = utils . dummy_context ( ) <EOL> self . db = self . useFixture ( utils . Database ( ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_update_assembly_status ( self , mock_registry , mock_uas ) : <EOL> mock_assembly = mock . MagicMock ( ) <EOL> mock_registry . Assembly . get_by_id . return_value = mock_assembly <EOL> shell_handler . update_assembly_status ( self . ctx , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( mock_registry . Assembly . get_by_id . call_count , <NUM_LIT:0> ) <EOL> self . assertEqual ( mock_registry . save . call_count , <NUM_LIT:0> ) <EOL> self . assertEqual ( mock_uas . call_count , <NUM_LIT:1> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_update_assembly_status_pass ( self , mock_registry , mock_uas ) : <EOL> shell_handler . update_assembly_status ( self . ctx , None , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( mock_registry . call_count , <NUM_LIT:0> ) <EOL> class TestBuildCommand ( base . BaseTestCase ) : <EOL> scenarios = [ <EOL> ( '<STR_LIT>' , <EOL> dict ( source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> base_image_id = '<STR_LIT>' , artifact_type = None , <EOL> expect_b = '<STR_LIT>' , <EOL> expect_u = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> dict ( source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> base_image_id = '<STR_LIT>' , artifact_type = None , <EOL> expect_b = '<STR_LIT>' , <EOL> expect_u = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> dict ( source_format = '<STR_LIT>' , image_format = '<STR_LIT>' , <EOL> base_image_id = '<STR_LIT>' , artifact_type = None , <EOL> expect_b = '<STR_LIT>' , <EOL> expect_u = '<STR_LIT>' ) ) ] <EOL> def test_build_cmd ( self ) : <EOL> ctx = utils . dummy_context ( ) <EOL> handler = shell_handler . Handler ( ) <EOL> cmd = handler . _get_build_command ( ctx , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> self . base_image_id , <EOL> self . source_format , <EOL> self . image_format , '<STR_LIT>' , <EOL> self . artifact_type ) <EOL> self . assertIn ( self . expect_b , cmd [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( ctx . tenant , cmd [ <NUM_LIT:3> ] ) <EOL> if self . base_image_id == '<STR_LIT>' and self . image_format == '<STR_LIT>' : <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:4> ] ) <EOL> else : <EOL> self . assertEqual ( self . base_image_id , cmd [ <NUM_LIT:4> ] ) <EOL> def test_unittest_cmd ( self ) : <EOL> ctx = utils . dummy_context ( ) <EOL> handler = shell_handler . Handler ( ) <EOL> cmd = handler . _get_build_command ( ctx , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> self . base_image_id , <EOL> self . source_format , <EOL> self . image_format , '<STR_LIT>' , <EOL> self . artifact_type ) <EOL> self . assertIn ( self . expect_u , cmd [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( ctx . tenant , cmd [ <NUM_LIT:3> ] ) <EOL> class TestLanguagePackBuildCommand ( base . BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestLanguagePackBuildCommand , self ) . setUp ( ) <EOL> self . ctx = utils . dummy_context ( ) <EOL> def test_languagepack_build_cmd ( self ) : <EOL> ctx = utils . dummy_context ( ) <EOL> handler = shell_handler . Handler ( ) <EOL> cmd = handler . _get_build_command ( ctx , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , cmd [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , cmd [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( ctx . tenant , cmd [ <NUM_LIT:3> ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_build_lp ( self , mock_popen , mock_ui , mock_registry , mock_get_env ) : <EOL> handler = shell_handler . Handler ( ) <EOL> fake_image = fakes . FakeImage ( ) <EOL> fake_glance_id = str ( uuid . uuid4 ( ) ) <EOL> fake_image_name = '<STR_LIT>' <EOL> mock_registry . Image . get_lp_by_name_or_uuid . return_value = fake_image <EOL> mock_popen . return_value . communicate . return_value = [ <EOL> '<STR_LIT>' % <EOL> ( fake_glance_id , fake_image_name ) , None ] <EOL> test_env = mock_environment ( ) <EOL> mock_get_env . return_value = test_env <EOL> git_info = mock_git_info ( ) <EOL> handler . build_lp ( self . ctx , image_id = <NUM_LIT:5> , git_info = git_info , <EOL> name = '<STR_LIT>' , source_format = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' , artifact_type = '<STR_LIT>' ) <EOL> proj_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> script = os . path . join ( proj_dir , '<STR_LIT>' ) <EOL> mock_popen . assert_called_once_with ( [ script , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . ctx . tenant ] , <EOL> env = test_env , <EOL> stdout = - <NUM_LIT:1> ) <EOL> expected = [ mock . call ( <NUM_LIT:5> , '<STR_LIT>' , None , None ) , <EOL> mock . call ( <NUM_LIT:5> , '<STR_LIT>' , fake_glance_id , fake_image_name ) ] <EOL> self . assertEqual ( expected , mock_ui . call_args_list ) </s>
