瀏覽代碼

Fix db_url set to empty string in default pcconfig.py (#1022)

Masen Furer 2 年之前
父節點
當前提交
d0e383d23c
共有 3 個文件被更改,包括 43 次插入1 次删除
  1. 1 1
      pynecone/.templates/jinja/app/pcconfig.py.jinja2
  2. 1 0
      pynecone/compiler/templates.py
  3. 41 0
      tests/test_utils.py

+ 1 - 1
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,
 )

+ 1 - 0
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,
         }
 
 

+ 41 - 0
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",
     [