def test_delete_batch_2(self): pg_batch.connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) pg_batch.confirmed_write = True # Return should be none if there are no `ids` self.assertIsNone(pg_batch.delete_batch([], 'batch_test'))
def test_update_batch(self): pg_batch.connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) pg_batch.confirmed_write = True self.assertTrue( pg_batch.update_batch([4, 5, 6], 'batch_test', 'date=NOW()'))
def test_delete_batch_3(self): with unittest.mock.patch('builtins.input', return_value='no'): pg_batch.connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) pg_batch.confirmed_write = False # Should exit if the client refuses the update self.assertRaises(SystemExit, pg_batch.delete_batch, [1, 2, 3], 'batch_test')
def setUp(self): # Connect to the database connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) # Read sample schema with open(self.schema_path, 'r') as f: schema = f.read() # Apply schema for test with connection.cursor() as cursor: cursor.execute(schema) connection.commit()
def test_run_query(self): pg_batch.connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) self.assertTrue(pg_batch.run_query('SELECT 1')) self.assertTrue(pg_batch.run_query('SELECT 1', 0.001))
def test_delete_batch(self): pg_batch.connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) pg_batch.confirmed_write = True self.assertTrue(pg_batch.delete_batch([1, 2, 3], 'batch_test'))
def test_connect(self): connection = pg_batch.connect(self.host, self.user, self.port, self.password, self.database) self.assertIsInstance(connection, psycopg2.extensions.connection)