summaryrefslogtreecommitdiffstats
path: root/tests/test_main.py
diff options
context:
space:
mode:
authorAlexander Schmolck <alexander.schmolck@smarkets.com>2017-05-25 11:39:01 +0100
committerAlexander Schmolck <alexander.schmolck@smarkets.com>2017-05-25 14:49:30 +0100
commit0c729909cd85b72f1879671c57daf3fbb424ebe9 (patch)
tree6af1c7a217add38aa3629d779306bc16e81b3b35 /tests/test_main.py
parent666aeee79f849d4a8d02d2860b2f33a9bd105e93 (diff)
Make it possible to use SSL with pgcli
This adds support for additional url query params which make stuff like ``` pgcli "postgres://user:pass@host.invalid/db?\ sslmode=verify-full&sslcert=my.pem&sslkey=my-key.pem&sslrootcert=ca.pem" ``` work. More generally it allows one to pass through various extra connection options.
Diffstat (limited to 'tests/test_main.py')
-rw-r--r--tests/test_main.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/test_main.py b/tests/test_main.py
index b705b730..b380d4db 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -91,11 +91,36 @@ def test_quoted_db_uri(tmpdir):
with mock.patch.object(PGCli, 'connect') as mock_connect:
cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile")))
cli.connect_uri('postgres://bar%5E:%5Dfoo@baz.com/testdb%5B')
- mock_connect.assert_called_with('testdb[', 'baz.com', 'bar^', None, ']foo')
+ mock_connect.assert_called_with(database='testdb[',
+ port=None,
+ host='baz.com',
+ user='bar^',
+ passwd=']foo')
+
+
+def test_ssl_db_uri(tmpdir):
+ with mock.patch.object(PGCli, 'connect') as mock_connect:
+ cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile")))
+ cli.connect_uri(
+ 'postgres://bar%5E:%5Dfoo@baz.com/testdb%5B?'
+ 'sslmode=verify-full&sslcert=m%79.pem&sslkey=my-key.pem&sslrootcert=c%61.pem')
+ mock_connect.assert_called_with(database='testdb[',
+ host='baz.com',
+ port=None,
+ user='bar^',
+ passwd=']foo',
+ sslmode='verify-full',
+ sslcert='my.pem',
+ sslkey='my-key.pem',
+ sslrootcert='ca.pem')
def test_port_db_uri(tmpdir):
with mock.patch.object(PGCli, 'connect') as mock_connect:
cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile")))
cli.connect_uri('postgres://bar:foo@baz.com:2543/testdb')
- mock_connect.assert_called_with('testdb', 'baz.com', 'bar', '2543', 'foo')
+ mock_connect.assert_called_with(database='testdb',
+ host='baz.com',
+ user='bar',
+ passwd='foo',
+ port='2543')