def test_validate_auth_vars_valid(): action = stubs.StubAction(stubs.StubCliContext()) try: action.validate_auth_vars() except AuthValuesError: # Valid parameters should not raise an AuthValuesError assert False
def test_create_configdocs_201_with_val_fails(*args): succ_resp = stubs.gen_err_resp(message='Validations failed', sub_message='Some reason', sub_error_count=2, sub_info_count=1, reason='Validation', code=400) responses.add(responses.POST, 'http://shiptest/configdocs/design', body=succ_resp, status=201) filename = 'tests/unit/cli/create/sample_yaml/sample.yaml' document_data = yaml.dump_all(filename) file_list = (filename,) response = CreateConfigdocs(stubs.StubCliContext(), 'design', 'append', False, document_data, file_list).invoke_and_return_resp() assert 'Configuration documents added.' in response assert 'Status: Validations failed' in response assert 'Reason: Validation' in response assert 'Some reason-1' in response
def test_create_configdocs_409(*args): err_resp = stubs.gen_err_resp(message='Invalid collection', sub_message='Buffer is either not...', sub_error_count=1, sub_info_count=0, reason='Buffermode : append', code=409) responses.add(responses.POST, 'http://shiptest/configdocs/design', body=err_resp, status=409) filename = 'tests/unit/cli/create/sample_yaml/sample.yaml' document_data = yaml.dump_all(filename) file_list = (filename,) response = CreateConfigdocs(stubs.StubCliContext(), 'design', 'append', False, document_data, file_list).invoke_and_return_resp() assert 'Error: Invalid collection' in response assert 'Reason: Buffermode : append' in response assert 'Buffer is either not...' in response
def test_commit_configdocs(*args): responses.add(responses.POST, 'http://shiptest/commitconfigdocs?force=false', body=None, status=200) response = CommitConfigdocs(stubs.StubCliContext(), False, False).invoke_and_return_resp() assert response == 'Configuration documents committed.\n'
def test_get_actions_empty(*args): responses.add(responses.GET, 'http://shiptest/actions', body="[]", status=200) response = GetActions(stubs.StubCliContext()).invoke_and_return_resp() assert 'None' in response assert 'Lifecycle' in response
def test_get_renderedconfigdocs(*args): responses.add(responses.GET, 'http://shiptest/renderedconfigdocs?version=buffer', body=GET_RENDEREDCONFIGDOCS_API_RESP, status=200) response = GetRenderedConfigdocs( stubs.StubCliContext(), version='buffer').invoke_and_return_resp() assert response == GET_RENDEREDCONFIGDOCS_API_RESP
def test_get_workflows_empty(*args): responses.add(responses.GET, 'http://shiptest/workflows', body="[]", status=200) response = GetWorkflows(stubs.StubCliContext()).invoke_and_return_resp() assert 'None' in response assert 'State' in response
def test_get_actions(*args): responses.add(responses.GET, 'http://shiptest/actions', body=GET_ACTIONS_API_RESP, status=200) response = GetActions(stubs.StubCliContext()).invoke_and_return_resp() assert 'deploy_site' in response assert 'action/01BTP9T2WCE1PAJR2DWYXG805V' in response assert 'Lifecycle' in response
def test_get_configdocs(*args): responses.add(responses.GET, 'http://shiptest/configdocs/design?version=buffer', body=GET_CONFIGDOCS_API_RESP, status=200) response = GetConfigdocs(stubs.StubCliContext(), collection='design', version='buffer').invoke_and_return_resp() assert response == GET_CONFIGDOCS_API_RESP
def test_commit_configdocs_dryrun(*args): responses.add(responses.POST, 'http://shiptest/commitconfigdocs?force=false', body=None, status=200) response = CommitConfigdocs(stubs.StubCliContext(), False, True).invoke_and_return_resp() assert response == ('Configuration documents were not committed. Currently' ' in dryrun mode.\n')
def test_get_workflows(*args): responses.add(responses.GET, 'http://shiptest/workflows', body=GET_WORKFLOWS_API_RESP, status=200) response = GetWorkflows(stubs.StubCliContext()).invoke_and_return_resp() assert 'deploy_site__2017-10-09T21:19:03.000000' in response assert 'deploy_site__2017-10-09T21:18:56.000000' in response assert 'State' in response assert 'Workflow' in response
def test_describe_step(*args): responses.add( responses.GET, 'http://shiptest/actions/01BTTMFVDKZFRJM80FGD7J1AKN/steps/preflight', body=GET_STEP_API_RESP, status=200) response = DescribeStep(stubs.StubCliContext(), '01BTTMFVDKZFRJM80FGD7J1AKN', 'preflight').invoke_and_return_resp() assert 'step/01BTTMFVDKZFRJM80FGD7J1AKN/preflight' in response
def test_get_configdocs_status(test_input, expected, *args): responses.add(responses.GET, 'http://shiptest/configdocs', body=test_input, status=200) with patch.object(cli_format_common, 'gen_collection_table') as mock_method: response = GetConfigdocsStatus( stubs.StubCliContext()).invoke_and_return_resp() mock_method.assert_called_once_with(expected)
def test_get_actions_unparseable_note(*args): responses.add(responses.GET, 'http://shiptest/actions', body=GET_ACTIONS_API_RESP_UNPARSEABLE_NOTE, status=200) response = GetActions(stubs.StubCliContext()).invoke_and_return_resp() assert 'deploy_site' in response assert 'action/01BTP9T2WCE1PAJR2DWYXG805V' in response assert 'Lifecycle' in response assert 'This is the first note for some action' in response assert "{'note_val': 'This note is broken'}" in response assert 'The previous note is bad' in response
def test_control_409(*args): responses.add( responses.POST, 'http://shiptest/actions/01BTG32JW87G0YKA1K29TKNAFX/control/pause', body=resp_body, status=409) control_verb = 'pause' id = '01BTG32JW87G0YKA1K29TKNAFX' response = Control(stubs.StubCliContext(), control_verb, id).invoke_and_return_resp() # test correct function was called assert 'Unable to pause action' in response
def test_control_stop(*args): responses.add( responses.POST, 'http://shiptest/actions/01BTG32JW87G0YKA1K29TKNAFX/control/stop', body=None, status=202) control_verb = 'stop' id = '01BTG32JW87G0YKA1K29TKNAFX' response = Control(stubs.StubCliContext(), control_verb, id).invoke_and_return_resp() # test correct function was called assert response == ('stop successfully submitted for action' ' 01BTG32JW87G0YKA1K29TKNAFX')
def test_get_site_statuses(*args): responses.add(responses.GET, 'http://shiptest/site_statuses', body=GET_SITE_STATUSES_API_RESP, status=200) response = GetSiteStatuses(stubs.StubCliContext()).invoke_and_return_resp() assert 'xyz.abc.com' in response assert 'def.abc.com' in response assert 'deployed' in response assert 'on' in response assert 'off' in response assert 'provisioning' in response assert 'Nodes Provision Status:' in response assert 'Machines Power State:' in response
def test_get_actions(*args): responses.add(responses.GET, 'http://shiptest/actions', body=GET_ACTIONS_API_RESP, status=200) response = GetActions(stubs.StubCliContext()).invoke_and_return_resp() assert 'deploy_site' in response assert 'action/01BTP9T2WCE1PAJR2DWYXG805V' in response assert 'Lifecycle' in response assert '2/1/0' in response assert 'This is a note for the concurrency check' not in response assert "Action Footnotes" in response assert (" - Info available with 'describe notedetails/" "ABCDEFGHIJKLMNOPQRSTUVWXYA'") in response
def test_describe_action(*args): responses.add(responses.GET, 'http://shiptest/actions/01BTTMFVDKZFRJM80FGD7J1AKN', body=GET_ACTION_API_RESP, status=200) response = DescribeAction( stubs.StubCliContext(), '01BTTMFVDKZFRJM80FGD7J1AKN').invoke_and_return_resp() assert 'action/01BTTMFVDKZFRJM80FGD7J1AKN' in response assert 'step/01BTTMFVDKZFRJM80FGD7J1AKN/action_xcom' in response assert 'Steps' in response assert 'Commands' in response assert 'Validations:' in response
def test_create_action_409(*args): responses.add(responses.POST, 'http://shiptest/actions', body=stubs.gen_err_resp(message='Error_409', reason='bad validations'), status=409) response = CreateAction( stubs.StubCliContext(), action_name='deploy_site', param=None, allow_intermediate_commits=False).invoke_and_return_resp() assert 'Error_409' in response assert 'bad validations' in response assert 'action/01BTTMFVDKZFRJM80FGD7J1AKN' not in response
def test_describe_validation(*args): responses.add(responses.GET, 'http://shiptest/actions/01BTTMFVDKZFRJM80FGD7J1AKN/' 'validations/02AURNEWAAAESKN99EBF8J2BHD', body=GET_VALIDATION_API_RESP, status=200) response = DescribeValidation( stubs.StubCliContext(), action_id='01BTTMFVDKZFRJM80FGD7J1AKN', validation_id='02AURNEWAAAESKN99EBF8J2BHD').invoke_and_return_resp() v_str = "validation/01BTTMFVDKZFRJM80FGD7J1AKN/02AURNEWAAAESKN99EBF8J2BHD" assert v_str in response assert "Validations failed for field 'abc'" in response
def test_create_action(*args): responses.add(responses.POST, 'http://shiptest/actions', body=resp_body, status=201) response = CreateAction( stubs.StubCliContext(), action_name='deploy_site', param=None, allow_intermediate_commits=False).invoke_and_return_resp() assert 'Name' in response assert 'Action' in response assert 'Lifecycle' in response assert 'action/01BTTMFVDKZFRJM80FGD7J1AKN' in response assert 'Error:' not in response
def test_describe_workflow(*args): responses.add( responses.GET, 'http://shiptest/workflows/deploy_site__2017-10-09T21:19:03.000000', body=WF_API_RESP, status=200) response = DescribeWorkflow( stubs.StubCliContext(), 'deploy_site__2017-10-09T21:19:03.000000').invoke_and_return_resp() assert 'deploy_site__2017-10-09T21:19:03.000000' in response assert 'deploy_site.preflight__2017-10-09T21:19:03.000000' in response assert 'deploy_site.postflight__2017-10-09T21:19:03.000000' in response assert 'dag_concurrency_check' in response assert 'Subworkflows:' in response
def test_get_renderedconfigdocs_not_found(*args): api_resp = stubs.gen_err_resp(message='Not Found', sub_error_count=0, sub_info_count=0, reason='It does not exist', code=404) responses.add(responses.GET, 'http://shiptest/renderedconfigdocs?version=buffer', body=api_resp, status=404) response = GetRenderedConfigdocs( stubs.StubCliContext(), version='buffer').invoke_and_return_resp() assert 'Error: Not Found' in response assert 'Reason: It does not exist' in response
def test_describe_action_not_found(*args): api_resp = stubs.gen_err_resp(message='Not Found', sub_error_count=0, sub_info_count=0, reason='It does not exist', code=404) responses.add(responses.GET, 'http://shiptest/actions/01BTTMFVDKZFRJM80FGD7J1AKN', body=api_resp, status=404) response = DescribeAction( stubs.StubCliContext(), '01BTTMFVDKZFRJM80FGD7J1AKN').invoke_and_return_resp() assert 'Error: Not Found' in response assert 'Reason: It does not exist' in response
def test_commit_configdocs_forced(*args): api_resp = stubs.gen_err_resp(message="Conflicts message forced", sub_message='Another bucket message', sub_error_count=1, sub_info_count=0, reason='Conflicts reason', code=200) responses.add(responses.POST, 'http://shiptest/commitconfigdocs?force=true', body=api_resp, status=200) response = CommitConfigdocs(stubs.StubCliContext(), True, False).invoke_and_return_resp() assert 'Status: Conflicts message forced' in response assert 'Configuration documents committed' in response assert 'Reason: Conflicts reason' in response
def test_describe_workflow_not_found(*args): api_resp = stubs.gen_err_resp(message='Not Found', sub_error_count=0, sub_info_count=0, reason='It does not exist', code=404) responses.add( responses.GET, 'http://shiptest/workflows/deploy_site__2017-10-09T21:19:03.000000', body=api_resp, status=404) response = DescribeWorkflow( stubs.StubCliContext(), 'deploy_site__2017-10-09T21:19:03.000000').invoke_and_return_resp() assert 'Error: Not Found' in response assert 'Reason: It does not exist' in response
def test_validate_auth_vars_missing_required_and_others(): auth_vars = { 'project_domain_name': 'default', 'user_domain_name': 'default', 'project_name': 'service', 'username': None, 'password': '******', 'auth_url': None } param = stubs.gen_api_param(auth_vars=auth_vars) action = stubs.StubAction(stubs.StubCliContext(api_parameters=param)) with pytest.raises(AuthValuesError): try: action.validate_auth_vars() except AuthValuesError as ex: assert 'os-auth-url' in ex.diagnostic assert 'os-username' in ex.diagnostic assert 'os-password' not in ex.diagnostic raise
def test_create_configdocs_empty(*args): def validating_callback(request): # a request that has empty_collection should have no body. assert request.body is None resp_body = stubs.gen_err_resp( message='Validations succeeded', sub_error_count=0, sub_info_count=0, reason='Validation', code=200) return (201, {}, resp_body) responses.add_callback( responses.POST, 'http://shiptest/configdocs/design', callback=validating_callback, content_type='application/json') filename = 'tests/unit/cli/create/sample_yaml/sample.yaml' document_data = yaml.dump_all(filename) file_list = (filename, ) # pass data and empty_collection = True - should init with data, but # not send the data on invoke action = CreateConfigdocs( stubs.StubCliContext(), collection='design', buffer_mode='append', empty_collection=True, data=document_data, filenames=file_list) assert action.data == document_data assert action.empty_collection == True response = action.invoke_and_return_resp() assert response.startswith("Configuration documents added.")