def test_with_default_arguments(self, monkeypatch): """Dumper without options return unmodified environment variables.""" monkeypatch.setattr(dumper, 'environ', simple_environ()) dump_result = dumper.dump() assert list(dump_result.keys()) == ['a', 'key'] assert dump_result['key'] == 'value' assert dump_result['a'] == 'b'
def test_with_template(self, monkeypatch, env_file): """Dumper with template option return variables for given template.""" monkeypatch.setattr(dumper, 'environ', simple_environ()) dump_result = dumper.dump(template=env_file) assert list(dump_result.keys()) == ['NORMAL_KEY', 'a', 'key'] assert dump_result['key'] == 'value' assert dump_result['a'] == 'b' assert dump_result['NORMAL_KEY'] == 'SOMEVALUE'
def test_same_environ(self, monkeypatch, env_file): """Dumper should return unmodified environment variables by default.""" monkeypatch.setattr( dumper, 'environ', same_environ(), ) dump_result = dumper.dump(template=env_file) # Should contain the value from env, not from template: assert dump_result['NORMAL_KEY'] == 'test'
def test_with_prefix(self, monkeypatch): """Dumper with prefix option should return requested variables.""" prefix = 'P_' monkeypatch.setattr( dumper, 'environ', simple_environ(prefix=prefix), ) dump_result = dumper.dump(prefixes=[prefix]) assert len(dump_result.keys()) == 1 assert dump_result['key'] == 'value'
def test_multiple_vars_with_prefix(self, monkeypatch, env_file): """Dumper with prefix option should return all prefixed variables.""" monkeypatch.setattr( dumper, 'environ', multiple_variables_with_prefix(), ) dump_result = dumper.dump(template=env_file, prefixes=['SECRET_']) # Only prefix should be changed, other parts should not: assert dump_result['DJANGO_SECRET_KEY'] == 'test' assert dump_result['SECRET_VALUE'] == 'value'
def test_with_two_options(self, monkeypatch, env_file): """Check both prefix and template options works together.""" prefix = 'P_' monkeypatch.setattr( dumper, 'environ', simple_environ(prefix=prefix), ) dump_result = dumper.dump(template=env_file, prefixes=[prefix]) assert list(dump_result.keys()) == ['NORMAL_KEY', 'key'] assert dump_result['key'] == 'value' assert dump_result['NORMAL_KEY'] == 'SOMEVALUE'
def main() -> NoReturn: """ Runs dump-env script. Example: This example will dump all environ variables: .. code:: bash $ dump-env This example will dump all environ variables starting with ``PIP_``: .. code:: bash $ dump-env -p 'PIP_' This example will dump all environ variables starting with ``PIP_`` and update them with variables starting with ``SECRET_``: .. code:: bash $ dump-env -p 'PIP_' -p 'SECRET_' This example will dump everything from ``.env.template`` file and all env variables with ``SECRET_`` prefix into a ``.env`` file: .. code:: bash $ dump-env -p 'SECRET_' -t .env.template > .env This example will fail if ``REQUIRED`` does not exist in environ: .. code:: bash $ dump-env --strict=REQUIRED """ args = _create_parser().parse_args() strict_vars = set(args.strict) if args.strict else None try: variables = dumper.dump(args.template, args.prefix, strict_vars) except StrictEnvException as exc: sys.stderr.write('{0}\n'.format(str(exc))) sys.exit(1) else: for env_name, env_value in variables.items(): sys.stdout.write('{0}={1}\n'.format(env_name, env_value)) sys.exit(0)
def test_with_multiple_prefixes(self, monkeypatch): """With multiple prefixes further prefixed variable replace previous.""" first_prefix = 'P1_' monkeypatch.setattr( dumper, 'environ', simple_environ(prefix=first_prefix), ) second_prefix = 'P2_' monkeypatch.setattr( dumper, 'environ', simple_environ( prefix=second_prefix, env_value='another_value', ), ) dump_result = dumper.dump(prefixes=[first_prefix, second_prefix]) assert len(dump_result.keys()) == 1 assert dump_result['key'] == 'another_value'
print("=" * 10 + "Schwab Account" + "=" * 10) SCHWAB_USERNAME = input("Schwab Username: "******"Schwab Password: "******"RSA_SCHWAB_USERNAME"] = SCHWAB_USERNAME or os.getenv("SCHWAB_USERNAME") or "" os.environ["RSA_SCHWAB_PASSWORD"] = SCHWAB_PASSWORD or os.getenv("SCHWAB_PASSWORD") or "" print("=" * 10 + "Vanguard Account" + "=" * 10) VANGUARD_USERNAME = input("Vanguard Email: ") VANGUARD_PASSWORD = input("Vanguard Password: "******"RSA_VANGUARD_USERNAME"] = VANGUARD_USERNAME or os.getenv("VANGUARD_USERNAME") or "" os.environ["RSA_VANGUARD_PASSWORD"] = VANGUARD_PASSWORD or os.getenv("VANGUARD_PASSWORD") or "" print("=" * 5 + "Saving credentials to .env (DO NOT SHARE THIS FILE!)" + "=" * 5) variables = dumper.dump(prefixes=["RSA_"]) with open(".env", 'w') as f: for env_name, env_value in variables.items(): f.write('{0}={1}\n'.format(env_name, env_value)) print("Credentials saved to .env") def setupWebull(account=1): # Get webull information WB1_USERNAME = input(f"Webull Account #{account} Username (email/phone): ") WB1_PASSWORD = input(f"Webull Account #{account} Password: "******"Webull Account #{account} Trade Token (6 digit trading code): ") WB1_QUESTION = "" WB1_QUESTION_ID = ""