コード例 #1
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_environment_variable_multiple_global_items():
    """Test the encrypt module's CLI function with the --env flag and a nonempty YAML file.

    The YAML file's global key is a list of items. The global key needs to be
    traversed and the secure key if found needs to be overwritten."""
    runner = CliRunner()
    with runner.isolated_filesystem():

        initial_data = OrderedDict([('language', 'python'), ('dist', 'trusty'),
                                    ('env', {'global': ['SOMETHING', 'OR_ANOTHER',
                                    {'secure': 'API_KEY="SUPER_INSECURE_KEY"'}]})])

        with open('file.yml', 'w') as file:
            ordered_dump(initial_data, file)

        result = runner.invoke(cli, ['--env', 'mandeep', 'Travis-Encrypt', 'file.yml'],
                               'SUPER_SECURE_API_KEY')

        assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)

        assert config['language'] == 'python'
        assert config['dist'] == 'trusty'
        assert ['language', 'dist', 'env'] == [key for key in config.keys()]

        for item in config['env']['global']:
            if 'secure' in item:
                assert base64.b64decode(item['secure'])
コード例 #2
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_deploy_nonempty_file():
    """Test the encrypt module's CLI function with the --deploy flag and a nonempty YAML file.

    The YAML file includes information that needs to be overwritten."""
    runner = CliRunner()
    with runner.isolated_filesystem():

        initial_data = OrderedDict([('language', 'python'), ('dist', 'trusty'),
                                    ('deploy', {'password': {'secure': 'SUPER_INSECURE_PASSWORD'}})])

        with open('file.yml', 'w') as file:
            ordered_dump(initial_data, file)

        result = runner.invoke(cli, ['--deploy', 'mandeep', 'Travis-Encrypt', 'file.yml'],
                               'SUPER_SECURE_PASSWORD')

        assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)

        assert config['language'] == 'python'
        assert config['dist'] == 'trusty'
        assert base64.b64decode(config['deploy']['password']['secure'])
        assert ['language', 'dist', 'deploy'] == [key for key in config.keys()]
コード例 #3
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_password_empty_file():
    """Test the encrypt module's CLI function with an empty YAML file."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('file.yml', 'w') as file:

            result = runner.invoke(cli, ['mandeep', 'Travis-Encrypt', 'file.yml'],
                                   'SUPER_SECURE_PASSWORD')
            assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)

            assert 'secure' in config['password']
            assert base64.b64decode(config['password']['secure'])
コード例 #4
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_deploy_empty_file():
    """Test the encrypt module's CLI function with the --deploy flag and an empty YAML file."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        initial_data = {'language': 'python'}
        with open('file.yml', 'w') as file:
            ordered_dump(initial_data, file)

        result = runner.invoke(cli, ['--deploy', 'mandeep', 'Travis-Encrypt', 'file.yml'],
                               'SUPER_SECURE_PASSWORD')
        assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)

        assert config['language'] == 'python'
        assert base64.b64decode(config['deploy']['password']['secure'])
コード例 #5
0
def load_travis_configuration(path):
    """Load the travis configuration settings from the travis.yml file.

    The configuration settings from the travis.yml file will be loaded
    with ordering preserved.

    Parameters
    ----------
    path: str
        The file path to the .travis.yml file

    Returns
    -------
    config: collections.OrderedDict
        The configuration settings in an OrderedDict object
    """
    with open(path) as config_file:
        config = ordered_load(config_file)

    return config
コード例 #6
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_environment_variable_empty_file():
    """Test the encrypt module's CLI function with the --env flag and an empty YAML file."""
    runner = CliRunner()
    with runner.isolated_filesystem():

        initial_data = {'language': 'python'}

        with open('file.yml', 'w') as file:
            ordered_dump(initial_data, file)

        result = runner.invoke(cli, ['--env', 'mandeep', 'Travis-Encrypt', 'file.yml'],
                               'API_KEY=SUPER_SECURE_KEY')

        assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)

        assert config['language'] == 'python'
        assert base64.b64decode(config['env']['global']['secure'])
        assert ['language', 'env'] == [key for key in config.keys()]
コード例 #7
0
ファイル: test_cli.py プロジェクト: ddboline/Travis-Encrypt
def test_dotenv_empty_file():
    """Test the --env-file CLI option with a dotenv file and a YAML file.

    The API key from the dotenv file will be added to the YAML configuration file.
    """
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('test.env', 'w') as env_file:
            env_file.write("API_KEY=MY_PASSWORD")

        initial_data = {'language': 'python'}
        with open('file.yml', 'w') as file:
            ordered_dump(initial_data, file)

        result = runner.invoke(cli, ['mandeep', 'Travis-Encrypt',
                                     'file.yml', '--env-file=test.env'])
        assert not result.exception

        with open('file.yml') as file:
            config = ordered_load(file)
            assert 'env' in config
            assert 'global' in config['env']
            assert config['language'] == 'python'
            assert base64.b64decode(config['env']['global']['API_KEY']['secure'])