-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Echo notifications * Blackify * Clean up a bit * Add test * Blackify * Update changelog * Fix tests
- Loading branch information
Showing
7 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import os | ||
import platform | ||
import re | ||
from unittest import mock | ||
|
||
import pytest | ||
|
@@ -13,6 +14,7 @@ | |
obfuscate_process_password, | ||
duration_in_words, | ||
format_output, | ||
notify_callback, | ||
PGCli, | ||
OutputSettings, | ||
COLOR_CODE_REGEX, | ||
|
@@ -432,6 +434,7 @@ def test_pg_service_file(tmpdir): | |
"b_host", | ||
"5435", | ||
"", | ||
notify_callback, | ||
application_name="pgcli", | ||
) | ||
del os.environ["PGPASSWORD"] | ||
|
@@ -487,7 +490,7 @@ def test_application_name_db_uri(tmpdir): | |
cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) | ||
cli.connect_uri("postgres://[email protected]/?application_name=cow") | ||
mock_pgexecute.assert_called_with( | ||
"bar", "bar", "", "baz.com", "", "", application_name="cow" | ||
"bar", "bar", "", "baz.com", "", "", notify_callback, application_name="cow" | ||
) | ||
|
||
|
||
|
@@ -514,3 +517,23 @@ def test_application_name_db_uri(tmpdir): | |
) | ||
def test_duration_in_words(duration_in_seconds, words): | ||
assert duration_in_words(duration_in_seconds) == words | ||
|
||
|
||
@dbtest | ||
def test_notifications(executor): | ||
run(executor, "listen chan1") | ||
|
||
with mock.patch("pgcli.main.click.secho") as mock_secho: | ||
run(executor, "notify chan1, 'testing1'") | ||
mock_secho.assert_called() | ||
arg = mock_secho.call_args_list[0].args[0] | ||
assert re.match( | ||
r'Notification received on channel "chan1" \(PID \d+\):\ntesting1', | ||
arg, | ||
) | ||
|
||
run(executor, "unlisten chan1") | ||
|
||
with mock.patch("pgcli.main.click.secho") as mock_secho: | ||
run(executor, "notify chan1, 'testing2'") | ||
mock_secho.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters