def test_sqlite_basic(self): res = expand_db_url('sqlite:///tmp/test.sqlite') self.assertEqual(res, { 'client': SqliteClient, 'params': { 'filename': '/tmp/test.sqlite', # nosec } })
def test_sqlite_params(self): res = expand_db_url('sqlite:///tmp/test.sqlite?AHA=5&moo=yes') self.assertEqual(res, { 'client': SqliteClient, 'params': { 'filename': '/tmp/test.sqlite', # nosec 'AHA': '5', 'moo': 'yes', } })
def test_postgres_basic(self): res = expand_db_url('postgres://postgres:@127.0.0.1:5432/test') self.assertEqual(res, { 'client': AsyncpgDBClient, 'params': { 'database': 'test', 'host': '127.0.0.1', 'password': '', 'port': '5432', 'user': '******', } })
def test_sqlite_testing(self): res = expand_db_url('sqlite:///tmp/test-{}.sqlite', testing=True) self.assertIn('/tmp/test-', res['params']['filename']) # nosec self.assertIn('.sqlite', res['params']['filename']) self.assertNotEqual('sqlite:///tmp/test-{}.sqlite', res['params']['filename']) self.assertEqual(res, { 'client': SqliteClient, 'params': { 'filename': res['params']['filename'], 'single_connection': True, } })
def test_mysql_basic(self): res = expand_db_url('mysql://root:@127.0.0.1:3306/test') self.assertEqual( res, { 'client': MySQLClient, 'params': { 'database': 'test', 'host': '127.0.0.1', 'password': '', 'port': '3306', 'user': '******', } })
def test_mysql_params(self): res = expand_db_url('mysql://root:@127.0.0.1:3306/test?AHA=5&moo=yes') self.assertEqual( res, { 'client': MySQLClient, 'params': { 'database': 'test', 'host': '127.0.0.1', 'password': '', 'port': '3306', 'user': '******', 'AHA': '5', 'moo': 'yes', } })
def test_postgres_testing(self): res = expand_db_url('postgres://postgres:@127.0.0.1:5432/test_\{\}', testing=True) self.assertIn('test_', res['params']['database']) self.assertNotEqual('test_{}', res['params']['database']) self.assertEqual(res, { 'client': AsyncpgDBClient, 'params': { 'database': res['params']['database'], 'host': '127.0.0.1', 'password': '', 'port': '5432', 'user': '******', 'single_connection': True, } })
def test_mysql_testing(self): res = expand_db_url('mysql://root:@127.0.0.1:3306/test_\{\}', testing=True) self.assertIn('test_', res['params']['database']) self.assertNotEqual('test_{}', res['params']['database']) self.assertEqual( res, { 'client': MySQLClient, 'params': { 'database': res['params']['database'], 'host': '127.0.0.1', 'password': '', 'port': '3306', 'user': '******', 'single_connection': True, } })
def test_unknown_scheme(self): with self.assertRaises(ConfigurationError): expand_db_url('moo://baa')
def test_postgres_nonint_port(self): with self.assertRaises(ConfigurationError): expand_db_url('postgres://postgres:@127.0.0.1:moo/test')
def test_sqlite_invalid(self): with self.assertRaises(ConfigurationError): expand_db_url('sqlite://')
def test_mysql_nonint_port(self): with self.assertRaises(ConfigurationError): expand_db_url('mysql://root:@127.0.0.1:moo/test')