def test_execute_unprepared_stmt(self): """ Given a statement has not been prepared in the database When execute() is called for that statement Then a StatementNotPreparedException error will be raised """ psc = PreparedStatementController() self.assertFalse("gen_sql" in psc.prepared_statements) with self.assertRaises(StatementNotPreparedException): psc.execute("gen_qs", force=False)
def test_execute_prepared_stmt(self): """ Given a statement has been prepared in the database When execute() is called for that statement Then then the execute method of the PreparedStatement object will be called """ psc = PreparedStatementController() psc.register_sql("gen_sql", lambda: None) with patch.object(PreparedStatement, "prepare", return_value=None): psc.prepare_sql_stmt("gen_sql", force=False) self.assertTrue("gen_sql" in psc.prepared_statements) with patch.object(PreparedStatement, "execute", return_value=None) as mock_execute: psc.execute("gen_sql") mock_execute.assert_called_once()