def test_unix_domain_socket(self, connect): with _patch_db("postgresql+psycopg2://usrn:pwd@/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with(host=None, port=None, user="******", password="******", database="dbname")
def test_missing_password(self, connect): with _patch_db("postgresql+psycopg2://u@h:1/db"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with(host="h", port=1, user="******", password=None, database="db")
def test_network(self, connect): # Simple TCP connection. with _patch_db("postgresql+psycopg2://usrn:pwd@hooost:5433/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with(host="hooost", port=5433, user="******", password="******", database="dbname")
def test_network_missing_port(self, connect): # If port is missing, the default 5432 is used. with _patch_db("postgresql+psycopg2://usrn:pwd@hooost/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with(host="hooost", port=5432, user="******", password="******", database="dbname")
def test_missing_password(self, connect): with _patch_db("postgresql+psycopg2://u@h:1/db"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with( host="h", port=1, user="******", password=None, database="db")
def test_unix_domain_socket(self, connect): with _patch_db("postgresql+psycopg2://usrn:pwd@/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with( host=None, port=None, user="******", password="******", database="dbname")
def test_network_missing_port(self, connect): # If port is missing, the default 5432 is used. with _patch_db("postgresql+psycopg2://usrn:pwd@hooost/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with( host="hooost", port=5432, user="******", password="******", database="dbname")
def test_network(self, connect): # Simple TCP connection. with _patch_db("postgresql+psycopg2://usrn:pwd@hooost:5433/dbname"): r = custom_psycopg2_connection() self.assertIs(r, connect.return_value) connect.assert_called_once_with( host="hooost", port=5433, user="******", password="******", database="dbname")
def test_not_psycopg2(self, connect): with _patch_db("sqlite://file"): with self.assertRaises(AssertionError): custom_psycopg2_connection()
def test_not_psycopg2(self, connect): with _patch_db("sqlite://file"): with self.assertRaises(AssertionError): custom_psycopg2_connection()