diff --git a/pynecone/.templates/jinja/app/pcconfig.py.jinja2 b/pynecone/.templates/jinja/app/pcconfig.py.jinja2 index da215ed10..7e51d7ab1 100644 --- a/pynecone/.templates/jinja/app/pcconfig.py.jinja2 +++ b/pynecone/.templates/jinja/app/pcconfig.py.jinja2 @@ -5,6 +5,6 @@ class {{ config_name }}(pc.Config): config = {{ config_name }}( app_name="{{ app_name }}", - db_url="{{ db_url }}", + db_url="{{ const.db_url }}", env=pc.Env.DEV, ) diff --git a/pynecone/compiler/templates.py b/pynecone/compiler/templates.py index e42b6f966..0da3e4390 100644 --- a/pynecone/compiler/templates.py +++ b/pynecone/compiler/templates.py @@ -38,6 +38,7 @@ class PyneconeJinjaEnvironment(Environment): "toggle_color_mode": constants.TOGGLE_COLOR_MODE, "use_color_mode": constants.USE_COLOR_MODE, "hydrate": constants.HYDRATE, + "db_url": constants.DB_URL, } diff --git a/tests/test_utils.py b/tests/test_utils.py index 2b79e79a5..f3e57e983 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,9 +1,13 @@ +import os import typing +from pathlib import Path from typing import Any, List, Union import pytest from packaging import version +from pynecone import Env +from pynecone.constants import CONFIG_FILE, DB_URL from pynecone.utils import build, format, imports, prerequisites, types from pynecone.vars import Var @@ -391,6 +395,43 @@ def test_create_config(app_name, expected_config_name, mocker): ) +@pytest.fixture +def tmp_working_dir(tmp_path): + """Create a temporary directory and chdir to it. + + After the test executes, chdir back to the original working directory. + + Args: + tmp_path: pytest tmp_path fixture creates per-test temp dir + + Yields: + subdirectory of tmp_path which is now the current working directory. + """ + old_pwd = Path(".").resolve() + working_dir = tmp_path / "working_dir" + working_dir.mkdir() + os.chdir(working_dir) + yield working_dir + os.chdir(old_pwd) + + +def test_create_config_e2e(tmp_working_dir): + """Create a new config file, exec it, and make assertions about the config. + + Args: + tmp_working_dir: a new directory that is the current working directory + for the duration of the test. + """ + app_name = "e2e" + prerequisites.create_config(app_name) + eval_globals = {} + exec((tmp_working_dir / CONFIG_FILE).read_text(), eval_globals) + config = eval_globals["config"] + assert config.app_name == app_name + assert config.db_url == DB_URL + assert config.env == Env.DEV + + @pytest.mark.parametrize( "name,expected", [