def test_container_variables_json_serialized(minimal_project): with minimal_project: conf_file = Project().root / CONF_FILENAME config = { "project_name": "minimal", "variables": { "ALL_JWT_AUTH": { "default": { "JWT_AUDIENCE": "jwt-audience", "JWT_SECRET_KEY": "jwt-secret", }, "production": { "JWT_AUDIENCE": "prod-audience", "JWT_SECRET_KEY": "prod-secret", }, }, }, } conf_file.write_text(yaml.dump(config)) create_settings_file(Project().root, "production") project = Project() env = project.get_container_env() assert "DEREX_JSON_ALL_JWT_AUTH" in env expected = config["variables"]["ALL_JWT_AUTH"]["default"] assert expected == json.loads(env["DEREX_JSON_ALL_JWT_AUTH"]) project.settings = project._available_settings.production env = project.get_container_env() assert "DEREX_JSON_ALL_JWT_AUTH" in env expected = config["variables"]["ALL_JWT_AUTH"]["production"] assert expected == json.loads(env["DEREX_JSON_ALL_JWT_AUTH"])
def test_container_variables(testproj): with testproj as projdir: conf_file = Path(projdir) / "derex.config.yaml" config = { "project_name": "minimal", "variables": { "lms_site_name": { "base": "dev.onlinecourses.example", "production": "onlinecourses.example", } }, } conf_file.write_text(yaml.dump(config)) create_settings_file(Path(projdir), "production") project = Project() env = project.get_container_env() assert "DEREX_LMS_SITE_NAME" in env assert env["DEREX_LMS_SITE_NAME"] == "dev.onlinecourses.example" project.settings = project.get_available_settings().production env = project.get_container_env() assert env["DEREX_LMS_SITE_NAME"] == "onlinecourses.example"
def test_container_variables(minimal_project): with minimal_project: conf_file = Project().root / CONF_FILENAME config = { "project_name": "minimal", "variables": { "lms_site_name": { "default": "dev.onlinecourses.example", "production": "onlinecourses.example", } }, } conf_file.write_text(yaml.dump(config)) create_settings_file(Project().root, "production") project = Project() env = project.get_container_env() assert "DEREX_LMS_SITE_NAME" in env assert env["DEREX_LMS_SITE_NAME"] == "dev.onlinecourses.example" project.settings = project.get_available_settings().production env = project.get_container_env() assert env["DEREX_LMS_SITE_NAME"] == "onlinecourses.example"
def test_secret_variables(complete_project): with complete_project: conf_file = Project().root / SECRETS_CONF_FILENAME config = { "variables": { "ALL_MYSQL_ROOT_PASSWORD": { "default": "base-secret-password", "production": "production-secret-password", }, }, } conf_file.write_text(yaml.dump(config)) create_settings_file(Project().root, "production") project = Project() env = project.get_container_env() assert "DEREX_ALL_MYSQL_ROOT_PASSWORD" in env expected = config["variables"]["ALL_MYSQL_ROOT_PASSWORD"]["default"] assert expected == env["DEREX_ALL_MYSQL_ROOT_PASSWORD"] project.settings = project._available_settings.production env = project.get_container_env() assert "DEREX_ALL_MYSQL_ROOT_PASSWORD" in env expected = config["variables"]["ALL_MYSQL_ROOT_PASSWORD"]["production"] assert expected == env["DEREX_ALL_MYSQL_ROOT_PASSWORD"]
def settings(project: Project, settings: Optional[Any]): """Get/set project settings module to use (base.py/production.py)""" if settings is None: click.echo(project.settings.name) else: project.settings = settings