<s> import json <EOL> import mock <EOL> from oslo_config import cfg <EOL> from solum . api . controllers . v1 import trigger <EOL> from solum . tests import base <EOL> from solum . tests import fakes <EOL> @ mock . patch ( '<STR_LIT>' , new_callable = fakes . FakePecanRequest ) <EOL> @ mock . patch ( '<STR_LIT>' , new_callable = fakes . FakePecanResponse ) <EOL> @ mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class TestTriggerController ( base . BaseTestCase ) : <EOL> def test_trigger_get_workflow_with_empty_body ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> workflow = obj . _get_workflow ( { } ) <EOL> self . assertEqual ( None , workflow ) <EOL> def test_trigger_get_workflow_with_deploy ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> query = { '<STR_LIT>' : '<STR_LIT>' } <EOL> workflow = obj . _get_workflow ( query ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , list ( workflow ) ) <EOL> def test_trigger_get_workflow_with_build_deploy ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> query = { '<STR_LIT>' : '<STR_LIT>' } <EOL> workflow = obj . _get_workflow ( query ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , list ( workflow ) ) <EOL> def test_trigger_get_workflow_with_all ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> query = { '<STR_LIT>' : '<STR_LIT>' } <EOL> workflow = obj . _get_workflow ( query ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , list ( workflow ) ) <EOL> def test_trigger_get_workflow_with_invalid_stage ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> query = { '<STR_LIT>' : '<STR_LIT>' } <EOL> workflow = obj . _get_workflow ( query ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , list ( workflow ) ) <EOL> def test_trigger_process_request_private_repo ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : { '<STR_LIT>' : '<STR_LIT:u>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : True } } <EOL> obj = trigger . TriggerController ( ) <EOL> commit_sha , collab_url = obj . _process_request ( body_dict ) <EOL> self . assertEqual ( None , collab_url ) <EOL> self . assertEqual ( '<STR_LIT>' , commit_sha ) <EOL> def test_trigger_process_request_on_valid_pub_repo ( self , <EOL> assem_mock , resp_mock , <EOL> request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : { '<STR_LIT>' : '<STR_LIT:u>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : False } } <EOL> obj = trigger . TriggerController ( ) <EOL> commit_sha , collab_url = obj . _process_request ( body_dict ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> collab_url ) <EOL> self . assertEqual ( '<STR_LIT>' , commit_sha ) <EOL> def test_trigger_post_with_empty_body ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> def test_trigger_post_on_github_webhook ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> status_url = '<STR_LIT>' <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url } } <EOL> expected_st_url = '<STR_LIT>' <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> tw . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , expected_st_url , None , <EOL> workflow = None ) <EOL> def test_trigger_post_on_github_comment_webhook ( self , <EOL> assem_mock , resp_mock , <EOL> request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : { '<STR_LIT>' : '<STR_LIT:u>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : True } } <EOL> expected_st_url = '<STR_LIT>' <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> tw . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , expected_st_url , None , <EOL> workflow = None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_trigger_post_on_mismatch_comment_pub_repo ( self , http_mock , <EOL> assem_mock , resp_mock , <EOL> request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : { '<STR_LIT>' : '<STR_LIT:u>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : False } } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> http_mock . return_value = ( { '<STR_LIT:status>' : '<STR_LIT>' } , '<STR_LIT>' ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_trigger_post_on_valid_comment_pub_repo ( self , http_mock , <EOL> assem_mock , resp_mock , <EOL> request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : { '<STR_LIT>' : '<STR_LIT:u>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : False } } <EOL> expected_st_url = '<STR_LIT>' <EOL> expected_clb_url = '<STR_LIT>' <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> http_mock . return_value = ( { '<STR_LIT:status>' : '<STR_LIT>' } , '<STR_LIT>' ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> tw . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , expected_st_url , <EOL> expected_clb_url , workflow = None ) <EOL> def test_trigger_post_on_comment_missing_login ( self , <EOL> assem_mock , resp_mock , <EOL> request_mock ) : <EOL> cfg . CONF . api . rebuild_phrase = "<STR_LIT>" <EOL> status_url = '<STR_LIT>' <EOL> collab_url = ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url , <EOL> '<STR_LIT>' : collab_url , <EOL> '<STR_LIT>' : False } } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> def test_trigger_post_on_wrong_github_webhook ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> status_url = '<STR_LIT>' <EOL> body_dict = { '<STR_LIT>' : { '<STR_LIT:url>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : status_url } } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> def test_trigger_post_on_unknown_git_webhook ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> body_dict = { "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> def test_trigger_post_on_non_github_webhook ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> body_dict = { "<STR_LIT>" : { "<STR_LIT:url>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called <EOL> def test_trigger_post_on_github_ping_webhook ( self , assem_mock , <EOL> resp_mock , request_mock ) : <EOL> body_dict = { "<STR_LIT>" : { "<STR_LIT:url>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> request_mock . body = json . dumps ( body_dict ) <EOL> obj = trigger . TriggerController ( ) <EOL> obj . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , resp_mock . status ) <EOL> tw = assem_mock . return_value . trigger_workflow <EOL> assert not tw . called </s>
