mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Adding a test to ensure exception handling is correct.
This commit is contained in:
parent
858cfac113
commit
b85c5bf6d9
1 changed files with 17 additions and 0 deletions
|
@ -282,6 +282,23 @@ class MySQLTestCase(TestCase, LoaderModuleMockMixin):
|
|||
def test_query(self):
|
||||
self._test_call(mysql.query, 'SELECT * FROM testdb', 'testdb', 'SELECT * FROM testdb')
|
||||
|
||||
def test_query_error(self):
|
||||
def mock_execute(cur, query):
|
||||
'''
|
||||
Mock of info method
|
||||
'''
|
||||
raise MySQLdb.OperationalError(9999, 'Something Went Wrong')
|
||||
|
||||
connect_mock = MagicMock()
|
||||
with patch.object(mysql, '_connect', connect_mock):
|
||||
with patch.dict(mysql.__salt__, {'config.option': MagicMock()}):
|
||||
with patch.object(mysql, '_execute') as execute_mock:
|
||||
execute_mock.side_effect = mock_execute
|
||||
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_call(self, function, expected_sql, *args, **kwargs):
|
||||
connect_mock = MagicMock()
|
||||
with patch.object(mysql, '_connect', connect_mock):
|
||||
|
|
Loading…
Add table
Reference in a new issue