|
@@ -6,6 +6,7 @@ import pytest
|
|
|
import pynecone as pc
|
|
|
from pynecone import constants
|
|
|
from pynecone.config import DBConfig
|
|
|
+from pynecone.constants import get_value
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
@@ -34,6 +35,21 @@ def config_empty_db_url_values(base_config_values):
|
|
|
"""
|
|
|
base_config_values["db_url"] = None
|
|
|
yield base_config_values
|
|
|
+ os.environ.pop("DB_URL", None)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture
|
|
|
+def config_none_db_url_values(base_config_values):
|
|
|
+ """Create config values with None (string) db_url.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ base_config_values: Base config values fixture.
|
|
|
+
|
|
|
+ Yields:
|
|
|
+ Config values
|
|
|
+ """
|
|
|
+ base_config_values["db_url"] = "None"
|
|
|
+ yield base_config_values
|
|
|
os.environ.pop("DB_URL")
|
|
|
|
|
|
|
|
@@ -68,6 +84,16 @@ def test_empty_db_url(config_empty_db_url_values):
|
|
|
assert config.db_url is None
|
|
|
|
|
|
|
|
|
+def test_none_db_url(config_none_db_url_values):
|
|
|
+ """Test that db_url is set 'None' (string) assigned if an 'None' (string) value is defined.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ config_none_db_url_values: Config values with None (string) db_url.
|
|
|
+ """
|
|
|
+ config = pc.Config(**config_none_db_url_values)
|
|
|
+ assert config.db_url == "None"
|
|
|
+
|
|
|
+
|
|
|
def test_db_url_precedence(base_config_values, sqlite_db_config_values):
|
|
|
"""Test that db_url is not overwritten when db_url is defined.
|
|
|
|
|
@@ -92,3 +118,18 @@ def test_db_url_from_db_config(config_no_db_url_values, sqlite_db_config_values)
|
|
|
config_no_db_url_values["db_config"] = db_config
|
|
|
config = pc.Config(**config_no_db_url_values)
|
|
|
assert config.db_url == db_config.get_url()
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(
|
|
|
+ "key, value, expected_value_type_in_config",
|
|
|
+ (
|
|
|
+ ("TIMEOUT", "1", int),
|
|
|
+ ("CORS_ALLOWED_ORIGINS", "[1, 2, 3]", list),
|
|
|
+ ("DB_NAME", "dbname", str),
|
|
|
+ ),
|
|
|
+)
|
|
|
+def test_get_value(monkeypatch, key, value, expected_value_type_in_config):
|
|
|
+ monkeypatch.setenv(key, value)
|
|
|
+ casted_value = get_value(key, type_=expected_value_type_in_config)
|
|
|
+
|
|
|
+ assert isinstance(casted_value, expected_value_type_in_config)
|