Пример #1
0
def test__get_artifactory_files_name_no_artifact_found(monkeypatch):
    _b = MagicMock(BuildConfig)
    _b.build_env_info = mock_build_config_dict['environments']['unittest']
    _b.json_config = mock_build_config_dict
    _b.project_name = mock_build_config_dict['projectInfo']['name']
    _b.version_number = 'v1.0.0'
    _b.artifact_extension = 'bob'
    _b.artifact_extensions = None

    art = ArtiFactory(config_override=_b)

    def _get_files_of_type_from_directory(type, directory):
        print(type)
        print(directory)

    with patch('flow.utils.commons.get_files_of_type_from_directory',
               new=_get_files_of_type_from_directory):
        with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
            monkeypatch.setenv('ARTIFACT_BUILD_DIRECTORY', 'mydir')

            with pytest.raises(SystemExit) as cm:
                art._get_artifactory_files_name_from_build_dir()

            print(str(mock_printmsg_fn.mock_calls))
            mock_printmsg_fn.assert_called_with(
                'ArtiFactory', '_get_artifactory_files_name_from_build_dir',
                'Failed to find artifact of type bob in mydir', 'ERROR')
Пример #2
0
def test__get_artifactory_file_name_directory_not_defined(monkeypatch):
    _b = MagicMock(BuildConfig)
    _b.build_env_info = mock_build_config_dict['environments']['unittest']
    _b.json_config = mock_build_config_dict
    _b.project_name = mock_build_config_dict['projectInfo']['name']
    _b.version_number = 'v1.0.0'

    art = ArtiFactory(config_override=_b)

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        if os.getenv('ARTIFACT_BUILD_DIRECTORY'):
            monkeypatch.delenv('ARTIFACT_BUILD_DIRECTORY')

        with pytest.raises(SystemExit) as cm:
            art._get_artifactory_files_name_from_build_dir()

        print(str(mock_printmsg_fn.mock_calls))
        mock_printmsg_fn.assert_called_with(
            'ArtiFactory', '_get_artifactory_files_name_from_build_dir',
            ('Missing artifact build path. Did you forget to define the environment variable \'ARTIFACT_BUILD_DIRECTORY\'? '
             ), 'ERROR')