summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIrina Truong <i.chernyavska@gmail.com>2021-02-12 21:09:38 -0800
committerGitHub <noreply@github.com>2021-02-12 21:09:38 -0800
commita3287c4ab2cea5ba5bef495e1174b12c3b2ae084 (patch)
tree2f9ebfe6f6312ad6c7b37ee8b17233ff72d1ed2f /tests
parent762fb4b8da98fdf6792e6c5586060ed37224f894 (diff)
Finer control over destructive warning. (#1242)
* Finer control over destructive warning. * Review feedback. * Changelog. * Run integration tests with --warn=moderate. * Fix typo. * Black.
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/features/environment.py3
-rw-r--r--tests/parseutils/test_parseutils.py19
-rw-r--r--tests/test_prompt_utils.py2
4 files changed, 23 insertions, 3 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 2a715b11..33cddf24 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -12,7 +12,7 @@ from utils import (
import pgcli.pgexecute
-@pytest.yield_fixture(scope="function")
+@pytest.fixture(scope="function")
def connection():
create_db("_test_db")
connection = db_connection("_test_db")
diff --git a/tests/features/environment.py b/tests/features/environment.py
index a8b3e26a..215c85cd 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -63,7 +63,7 @@ def before_all(context):
"import coverage",
"coverage.process_startup()",
"import pgcli.main",
- "pgcli.main.cli()",
+ "pgcli.main.cli(auto_envvar_prefix='BEHAVE')",
]
),
)
@@ -102,6 +102,7 @@ def before_all(context):
else:
if "PGPASSWORD" in os.environ:
del os.environ["PGPASSWORD"]
+ os.environ["BEHAVE_WARN"] = "moderate"
context.cn = dbutils.create_db(
context.conf["host"],
diff --git a/tests/parseutils/test_parseutils.py b/tests/parseutils/test_parseutils.py
index aaeb3f91..5a375d70 100644
--- a/tests/parseutils/test_parseutils.py
+++ b/tests/parseutils/test_parseutils.py
@@ -1,4 +1,5 @@
import pytest
+from pgcli.packages.parseutils import is_destructive
from pgcli.packages.parseutils.tables import extract_tables
from pgcli.packages.parseutils.utils import find_prev_keyword, is_open_quote
@@ -259,3 +260,21 @@ def test_is_open_quote__closed(sql):
)
def test_is_open_quote__open(sql):
assert is_open_quote(sql)
+
+
+@pytest.mark.parametrize(
+ ("sql", "warning_level", "expected"),
+ [
+ ("update abc set x = 1", "all", True),
+ ("update abc set x = 1 where y = 2", "all", True),
+ ("update abc set x = 1", "moderate", True),
+ ("update abc set x = 1 where y = 2", "moderate", False),
+ ("select x, y, z from abc", "all", False),
+ ("drop abc", "all", True),
+ ("alter abc", "all", True),
+ ("delete abc", "all", True),
+ ("truncate abc", "all", True),
+ ],
+)
+def test_is_destructive(sql, warning_level, expected):
+ assert is_destructive(sql, warning_level=warning_level) == expected
diff --git a/tests/test_prompt_utils.py b/tests/test_prompt_utils.py
index c1f8a169..a8a3a1e0 100644
--- a/tests/test_prompt_utils.py
+++ b/tests/test_prompt_utils.py
@@ -7,4 +7,4 @@ def test_confirm_destructive_query_notty():
stdin = click.get_text_stream("stdin")
if not stdin.isatty():
sql = "drop database foo;"
- assert confirm_destructive_query(sql) is None
+ assert confirm_destructive_query(sql, "all") is None