1
0
Fork 0

Merging upstream version 4.2.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-09 08:29:34 +01:00
parent 7e05478097
commit 853c1070f9
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 197 additions and 99 deletions

View file

@ -51,6 +51,10 @@ Feature: run the cli,
When we list databases
then we see list of databases
Scenario: ping databases
When we ping the database
then we get a pong response
Scenario: run the cli with --username
When we launch dbcli using --username
and we send "\?" command

View file

@ -26,6 +26,19 @@ def step_see_list_databases(context):
context.cmd_output = None
@when("we ping the database")
def step_ping_database(context):
cmd = ["pgcli", "--ping"]
context.cmd_output = subprocess.check_output(cmd, cwd=context.package_root)
@then("we get a pong response")
def step_get_pong_response(context):
# exit code 0 is implied by the presence of cmd_output here, which
# is only set on a successful run.
assert context.cmd_output.strip() == b"PONG", f"Output was {context.cmd_output}"
@when("we run dbcli")
def step_run_cli(context):
wrappers.run_cli(context)

View file

@ -1,5 +1,7 @@
import json
import pytest
from pgcli import pgcompleter
import tempfile
def test_load_alias_map_file_missing_file():
@ -47,12 +49,34 @@ def test_generate_alias_uses_first_char_and_every_preceded_by_underscore(
"table_name, alias_map, alias",
[
("some_table", {"some_table": "my_alias"}, "my_alias"),
pytest.param(
"some_other_table", {"some_table": "my_alias"}, "sot", id="no_match_in_map"
),
],
)
def test_generate_alias_can_use_alias_map(table_name, alias_map, alias):
assert pgcompleter.generate_alias(table_name, alias_map) == alias
@pytest.mark.parametrize(
"table_name, alias_map, alias",
[
("some_table", {"some_table": "my_alias"}, "my_alias"),
],
)
def test_pgcompleter_alias_uses_configured_alias_map(table_name, alias_map, alias):
with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as alias_map_file:
alias_map_file.write(json.dumps(alias_map))
alias_map_file.seek(0)
completer = pgcompleter.PGCompleter(
settings={
"generate_aliases": True,
"alias_map_file": alias_map_file.name,
}
)
assert completer.alias(table_name, []) == alias
@pytest.mark.parametrize(
"table_name, alias_map, alias",
[