def test_copy_data(self): pg_ctl_exe = pgtest.which('pg_ctl') temp_dir = tempfile.mkdtemp() data_dir = os.path.join(temp_dir, 'data') cmd = ('"{pg_ctl}" initdb -D "{cluster}" -o "-U postgres -A trust"' ).format(pg_ctl=pg_ctl_exe, cluster=data_dir) subprocess.check_output(cmd, shell=True) with pgtest.PGTest(copy_cluster=data_dir) as pg: self.assertTrue(pgtest.is_server_running(pg.cluster)) shutil.rmtree(temp_dir, ignore_errors=True)
def test_invalid_port_type_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest(port='5432')
def test_no_exist_copy_cluster_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest('/not/a/path')
def test_invalid_copy_cluster_exit(self): temp_dir = tempfile.mkdtemp() with self.assertRaises(AssertionError): pgtest.PGTest(copy_cluster=temp_dir) shutil.rmtree(temp_dir, ignore_errors=True)
def test_invalid_pg_ctl_exe_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest(pg_ctl='/not/a/path/pg_ctl')
def test_invalid_username_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest(username='******')
def test_base_dir_valid(self): temp_dir = tempfile.mkdtemp() with pgtest.PGTest(base_dir=temp_dir) as pg: self.assertTrue(pgtest.is_server_running(pg.cluster)) shutil.rmtree(temp_dir, ignore_errors=True)
def test_pg_ctl_exe_valid(self): pg_ctl_exe = pgtest.which('pg_ctl') with pgtest.PGTest(pg_ctl=pg_ctl_exe) as pg: self.assertTrue(pgtest.is_server_running(pg.cluster))
def test_username_valid(self): with pgtest.PGTest(username='******') as pg: self.assertTrue(pgtest.is_server_running(pg.cluster))
def test_no_cleanup(self): with pgtest.PGTest(no_cleanup=True) as pg: base_dir = pg._base_dir self.assertDirExists(base_dir) self.assertDirExists(base_dir) shutil.rmtree(base_dir, ignore_errors=True)
def test_cleanup(self): with pgtest.PGTest() as pg: base_dir = pg._base_dir self.assertDirExists(base_dir) self.assertDirNotExists(base_dir)
def setUpClass(cls): cls.pg = pgtest.PGTest() cls.base_dir = cls.pg._base_dir
def setUpClass(cls): cls.pg_ctl_exe = pgtest.which('pg_ctl') cls.pg = pgtest.PGTest()
def test_invalid_max_connections_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest(max_connections=3.5)
def test_max_connections_valid(self): with pgtest.PGTest(max_connections=12) as pg: with psycopg2.connect(**pg.dsn) as connection: with connection.cursor() as cursor: cursor.execute('SHOW max_connections;') self.assertEqual(int(list(cursor)[0][0]), 12)
def test_invalid_base_dir_exit(self): with self.assertRaises(AssertionError): pgtest.PGTest(base_dir='/not/a/path')