summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRodrigo Neri (Rigo) <rigoneri@users.noreply.github.com>2022-10-13 16:42:22 -0500
committerGitHub <noreply@github.com>2022-10-13 14:42:22 -0700
commit1726ff5397538d5061be1a5fae1b060e3140e696 (patch)
tree67384d0d4fe06661a5bf97560c10e6b1c47cb416 /tests
parentc280f8e398662e43a1637c6918700f0883baea1c (diff)
Changed destructive_warning to take a list of destructive commands (#1328)
* Changed destructive_warning to take a list of destructive commands and added the dsn_alias as part of the destructive command warning * Updated parse_destructive_warning to handle None * Reverted auto formatted change to AUTHORS * Reverted auto formatted change to AUTHORS
Diffstat (limited to 'tests')
-rw-r--r--tests/parseutils/test_parseutils.py56
-rw-r--r--tests/test_prompt_utils.py9
2 files changed, 51 insertions, 14 deletions
diff --git a/tests/parseutils/test_parseutils.py b/tests/parseutils/test_parseutils.py
index 5a375d70..349cbd02 100644
--- a/tests/parseutils/test_parseutils.py
+++ b/tests/parseutils/test_parseutils.py
@@ -1,5 +1,10 @@
import pytest
-from pgcli.packages.parseutils import is_destructive
+from pgcli.packages.parseutils import (
+ is_destructive,
+ parse_destructive_warning,
+ BASE_KEYWORDS,
+ ALL_KEYWORDS,
+)
from pgcli.packages.parseutils.tables import extract_tables
from pgcli.packages.parseutils.utils import find_prev_keyword, is_open_quote
@@ -263,18 +268,43 @@ def test_is_open_quote__open(sql):
@pytest.mark.parametrize(
- ("sql", "warning_level", "expected"),
+ ("sql", "keywords", "expected"),
+ [
+ ("update abc set x = 1", ALL_KEYWORDS, True),
+ ("update abc set x = 1 where y = 2", ALL_KEYWORDS, True),
+ ("update abc set x = 1", BASE_KEYWORDS, True),
+ ("update abc set x = 1 where y = 2", BASE_KEYWORDS, False),
+ ("select x, y, z from abc", ALL_KEYWORDS, False),
+ ("drop abc", ALL_KEYWORDS, True),
+ ("alter abc", ALL_KEYWORDS, True),
+ ("delete abc", ALL_KEYWORDS, True),
+ ("truncate abc", ALL_KEYWORDS, True),
+ ("insert into abc values (1, 2, 3)", ALL_KEYWORDS, False),
+ ("insert into abc values (1, 2, 3)", BASE_KEYWORDS, False),
+ ("insert into abc values (1, 2, 3)", ["insert"], True),
+ ("insert into abc values (1, 2, 3)", ["insert"], True),
+ ],
+)
+def test_is_destructive(sql, keywords, expected):
+ assert is_destructive(sql, keywords) == expected
+
+
+@pytest.mark.parametrize(
+ ("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),
+ ("true", ALL_KEYWORDS),
+ ("false", []),
+ ("all", ALL_KEYWORDS),
+ ("moderate", BASE_KEYWORDS),
+ ("off", []),
+ ("", []),
+ (None, []),
+ (ALL_KEYWORDS, ALL_KEYWORDS),
+ (BASE_KEYWORDS, BASE_KEYWORDS),
+ ("insert", ["insert"]),
+ ("drop,alter,delete", ["drop", "alter", "delete"]),
+ (["drop", "alter", "delete"], ["drop", "alter", "delete"]),
],
)
-def test_is_destructive(sql, warning_level, expected):
- assert is_destructive(sql, warning_level=warning_level) == expected
+def test_parse_destructive_warning(warning_level, expected):
+ assert parse_destructive_warning(warning_level) == expected
diff --git a/tests/test_prompt_utils.py b/tests/test_prompt_utils.py
index a8a3a1e0..91abe374 100644
--- a/tests/test_prompt_utils.py
+++ b/tests/test_prompt_utils.py
@@ -7,4 +7,11 @@ 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, "all") is None
+ assert confirm_destructive_query(sql, [], None) is None
+
+
+def test_confirm_destructive_query_with_alias():
+ stdin = click.get_text_stream("stdin")
+ if not stdin.isatty():
+ sql = "drop database foo;"
+ assert confirm_destructive_query(sql, ["drop"], "test") is None