From f77392695c09f9fef9386c112aef0e2b2f6fcd1a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 07:31:44 +0200 Subject: Adding upstream version 2.1.2. Signed-off-by: Daniel Baumann --- tests/test_named_queries.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/test_named_queries.py (limited to 'tests/test_named_queries.py') diff --git a/tests/test_named_queries.py b/tests/test_named_queries.py new file mode 100644 index 0000000..720974b --- /dev/null +++ b/tests/test_named_queries.py @@ -0,0 +1,46 @@ +"""Tests for named queries.""" + +import pytest +import configparser +import tempfile + +from pgspecial.namedqueries import NamedQueries +from pgspecial.main import PGSpecial +from configobj import ConfigObj + + +@pytest.fixture(scope="module") +def named_query(): + with tempfile.NamedTemporaryFile() as f: + NamedQueries.instance = NamedQueries.from_config(ConfigObj(f)) + yield + NamedQueries.instance = None + + +def test_save_named_queries(named_query): + PGSpecial().execute(None, "\\ns test select * from foo") + expected = {"test": "select * from foo"} + assert NamedQueries.instance.list() == expected + + +def test_delete_named_queries(named_query): + PGSpecial().execute(None, "\\ns test_foo select * from foo") + assert "test_foo" in NamedQueries.instance.list() + + PGSpecial().execute(None, "\\nd test_foo") + assert "test_foo" not in NamedQueries.instance.list() + + +def test_print_named_queries(named_query): + PGSpecial().execute(None, "\\ns test_name select * from bar") + assert "test_name" in NamedQueries.instance.list() + + result = PGSpecial().execute(None, "\\np test_n.*") + assert result == [("", [("test_name", "select * from bar")], ["Name", "Query"], "")] + + result = PGSpecial().execute(None, "\\np") + assert result[0][:3] == ( + None, + None, + None, + ) -- cgit v1.2.3