Skip to content

Instantly share code, notes, and snippets.

@danslimmon
Created May 30, 2016 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danslimmon/f3002f225c7766e93e8d5138315e3021 to your computer and use it in GitHub Desktop.
Save danslimmon/f3002f225c7766e93e8d5138315e3021 to your computer and use it in GitHub Desktop.
# Test:
def test_get_slave_status_bad_server(self):
'''
Test get_slave_status in the mysql execution module, simulating a broken server
'''
connect_mock = MagicMock(return_value=None)
mysql._connect = connect_mock
with patch.dict(mysql.__salt__, {'config.option': MagicMock()}):
rslt = mysql.get_slave_status()
connect_mock.assert_has_calls(call())
self.assertEqual(rslt, [])
# Output:
"""
*** unit.modules.mysql_test.MySQLTestCase.test_get_slave_status_bad_server Tests ************************************************
-------- Failed Tests ---------------------------------------------------------------------------------------------------------
-> unit.modules.mysql_test.MySQLTestCase.test_get_slave_status_bad_server ....................................................
Traceback (most recent call last):
File "/home/ubuntu/salt/tests/unit/modules/mysql_test.py", line 280, in test_get_slave_status_bad_server
connect_mock.assert_has_calls(call())
File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 969, in assert_has_calls
), cause)
File "/usr/local/lib/python2.7/dist-packages/six.py", line 718, in raise_from
raise value
AssertionError: Calls not found.
Expected: ['', (), {}]
Actual: [call()]
...............................................................................................................................
---------------------------------------------------------------------------------------------------------------------------------
==================================================================================================================================
FAILED (total=1, skipped=0, passed=0, failures=1, errors=0)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment