def test_query_error(self): connect_mock = MagicMock() with patch.object(mysql, '_connect', connect_mock): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): side_effect = MySQLdb.OperationalError(9999, 'Something Went Wrong') with patch.object(mysql, '_execute', MagicMock(side_effect=side_effect)): mysql.query('testdb', 'SELECT * FROM testdb') self.assertIn('mysql.error', mysql.__context__) expected = 'MySQL Error 9999: Something Went Wrong' self.assertEqual(mysql.__context__['mysql.error'], expected)
def test_query_error(self): connect_mock = MagicMock() with patch.object(mysql, '_connect', connect_mock): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): # Use the OperationalError from the salt mysql module because that # exception can come from either MySQLdb or pymysql side_effect = mysql.OperationalError(9999, 'Something Went Wrong') with patch.object(mysql, '_execute', MagicMock(side_effect=side_effect)): mysql.query('testdb', 'SELECT * FROM testdb') self.assertIn('mysql.error', mysql.__context__) expected = 'MySQL Error 9999: Something Went Wrong' self.assertEqual(mysql.__context__['mysql.error'], expected)
def test_query_error(): connect_mock = MagicMock() with patch.object(mysql, "_connect", connect_mock): with patch.dict(mysql.__salt__, {"config.option": MagicMock()}): # Use the OperationalError from the salt mysql module because that # exception can come from either MySQLdb or pymysql side_effect = mysql.OperationalError(9999, "Something Went Wrong") with patch.object(mysql, "_execute", MagicMock(side_effect=side_effect)): mysql.query("testdb", "SELECT * FROM testdb") assert "mysql.error" in mysql.__context__ expected = "MySQL Error 9999: Something Went Wrong" assert mysql.__context__["mysql.error"] == expected