def test_as_expected(self, mock_write): """ Everything is as expected, content is written to the location in the config file. """ mock_cmd = mock.MagicMock() key_response = mock_cmd.context.server.static.get_server_key.return_value key_loc = mock_cmd.context.config['getter']['getter'] cli.update_server_key(mock_cmd) mock_write.assert_called_once_with(key_loc, key_response.response_body)
def test_binding_exception(self, mock_write): """ If there is a problem getting the key, do not attempt to write the file. """ class MockException(Exception): def __str__(self): return "Mock Exception str" mock_cmd = mock.MagicMock() mock_cmd.context.server.static.get_server_key.side_effect = MockException() cli.update_server_key(mock_cmd) msg = 'Download server RSA key failed [Mock Exception str]' mock_cmd.prompt.render_failure_message.assert_called_once_with(msg) self.assertEqual(mock_write.call_count, 0)