Esempio n. 1
0
    def test_with_default_arguments(self, monkeypatch):
        monkeypatch.setattr(dump_env, 'environ', self.simple_environ())
        result = dump()

        assert list(result.keys()) == ['a', 'key']
        assert result['key'] == 'value'
        assert result['a'] == 'b'
Esempio n. 2
0
def main():
    """
    Runs dump-env script.

    Examples:
        This example will dump all environ variables::

            $ dump-env

        This example will dump all environ variables starting with `PIP_`::

            $ dump-env -p 'PIP_'

        This example will dump everything from `.env.template` file
        and all env variables with `SECRET_` prefix into a `.env` file::

            $ dump-env -p 'SECRET_' -t .env.template > .env

    """
    parser = _create_parser()
    args = parser.parse_args()
    variables = dump(args.template, args.prefix)

    for key, value in variables.items():
        print('{0}={1}'.format(key, value))
Esempio n. 3
0
    def test_with_template(self, monkeypatch, env_file):
        monkeypatch.setattr(dump_env, 'environ', self.simple_environ())
        result = dump(template=env_file)

        assert list(result.keys()) == ['NORMAL_KEY', 'a', 'key']
        assert result['key'] == 'value'
        assert result['a'] == 'b'
        assert result['NORMAL_KEY'] == 'SOMEVALUE'
Esempio n. 4
0
    def test_same_environ(self, monkeypatch, env_file):
        monkeypatch.setattr(
            dump_env,
            'environ',
            self.same_environ(),
        )
        result = dump(template=env_file)

        # Should contain the value from env, not from template:
        assert result['NORMAL_KEY'] == 'test'
Esempio n. 5
0
    def test_with_prefix(self, monkeypatch):
        prefix = 'P_'
        monkeypatch.setattr(
            dump_env,
            'environ',
            self.simple_environ(prefix=prefix),
        )
        result = dump(prefix=prefix)

        assert len(result.keys()) == 1
        assert result['key'] == 'value'
Esempio n. 6
0
    def test_multiple_prefix(self, monkeypatch, env_file):
        monkeypatch.setattr(
            dump_env,
            'environ',
            self.multiple_prefix(),
        )
        result = dump(template=env_file, prefix='SECRET_')

        # Only prefix should be changed, other parts should not:
        assert result['DJANGO_SECRET_KEY'] == 'test'
        assert result['SECRET_VALUE'] == 'value'
Esempio n. 7
0
    def test_with_two_options(self, monkeypatch, env_file):
        prefix = 'P_'
        monkeypatch.setattr(
            dump_env,
            'environ',
            self.simple_environ(prefix=prefix),
        )
        result = dump(template=env_file, prefix=prefix)

        assert list(result.keys()) == ['NORMAL_KEY', 'key']
        assert result['key'] == 'value'
        assert result['NORMAL_KEY'] == 'SOMEVALUE'