summaryrefslogtreecommitdiffstats
path: root/tests/parseutils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-11-01 04:38:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-11-01 04:38:10 +0000
commit6ad5e5b3d0d0029af2401594ecc398fcb6bc9ff5 (patch)
tree4a648e2fca058a515ad4dfe12302bb9d41ca1c7d /tests/parseutils
parentReleasing debian version 3.5.0-5. (diff)
downloadpgcli-6ad5e5b3d0d0029af2401594ecc398fcb6bc9ff5.tar.xz
pgcli-6ad5e5b3d0d0029af2401594ecc398fcb6bc9ff5.zip
Merging upstream version 4.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/parseutils')
-rw-r--r--tests/parseutils/test_parseutils.py56
1 files changed, 43 insertions, 13 deletions
diff --git a/tests/parseutils/test_parseutils.py b/tests/parseutils/test_parseutils.py
index 5a375d7..349cbd0 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