| 888 | |
| 889 | @pytest.mark.skipif(not HAS_PYMYSQL, reason="Could not import pymysql") |
| 890 | def test_query_error(): |
| 891 | connect_mock = MagicMock() |
| 892 | with patch.object(mysql, "_connect", connect_mock): |
| 893 | with patch.dict(mysql.__salt__, {"config.option": MagicMock()}): |
| 894 | # Use the OperationalError from the salt mysql module because that |
| 895 | # exception can come from either MySQLdb or pymysql |
| 896 | side_effect = mysql.OperationalError(9999, "Something Went Wrong") |
| 897 | with patch.object(mysql, "_execute", MagicMock(side_effect=side_effect)): |
| 898 | mysql.query("testdb", "SELECT * FROM testdb") |
| 899 | assert "mysql.error" in mysql.__context__ |
| 900 | expected = "MySQL Error 9999: Something Went Wrong" |
| 901 | assert mysql.__context__["mysql.error"] == expected |
| 902 | |
| 903 | |
| 904 | def test_plugin_add(): |