def test_main_add_auto_run_no_task(self, mock_module, mock_connect,
                                    mock_info, mock_comp, mock_server_conf,
                                    mock_port_conf, mock_conf_action, mock_conf_task,
                                    mock_wait):
     ''' Test main good with add and auto_run. Config not updated, no task.
     '''
     mock_module_object = Mock()
     mock_module_object.params = dict(action='add', switch_name='eos',
                                      switch_port='3', auto_run=True)
     mock_module.return_value = mock_module_object
     mock_client_object = Mock()
     mock_connect.return_value = mock_client_object
     mock_info.return_value = 'Info'
     mock_server_conf.return_value = 'Configlet'
     mock_port_conf.return_value = 'Port'
     mock_conf_action.return_value = dict(taskCreated=True, changed=False)
     mock_conf_task.return_value = None
     cv_server_provision.main()
     self.assertEqual(mock_connect.call_count, 1)
     self.assertEqual(mock_info.call_count, 1)
     self.assertEqual(mock_comp.call_count, 1)
     self.assertEqual(mock_server_conf.call_count, 1)
     self.assertEqual(mock_port_conf.call_count, 1)
     self.assertEqual(mock_conf_action.call_count, 1)
     self.assertEqual(mock_conf_task.call_count, 1)
     mock_wait.assert_not_called()
     mock_module_object.fail_json.assert_not_called()
     return_dict = dict(changed=False, switchInfo='Info',
                        switchConfigurable=True, portConfigurable=True,
                        taskCreated=False, taskExecuted=False,
                        taskCompleted=False)
     mock_module_object.exit_json.assert_called_with(**return_dict)
 def test_main_add_no_auto_run(self, mock_module, mock_connect, mock_info,
                               mock_comp, mock_server_conf, mock_port_conf,
                               mock_conf_action):
     ''' Test main good with add action and no auto_run.
     '''
     mock_module_object = Mock()
     mock_module_object.params = dict(action='add',
                                      switch_name='eos',
                                      switch_port='3',
                                      auto_run=False)
     mock_module.return_value = mock_module_object
     mock_connect.return_value = 'Client'
     mock_info.return_value = 'Info'
     mock_server_conf.return_value = 'Configlet'
     mock_port_conf.return_value = 'Port'
     mock_conf_action.return_value = dict(taskCreated=True)
     cv_server_provision.main()
     self.assertEqual(mock_connect.call_count, 1)
     self.assertEqual(mock_info.call_count, 1)
     self.assertEqual(mock_comp.call_count, 1)
     self.assertEqual(mock_server_conf.call_count, 1)
     self.assertEqual(mock_port_conf.call_count, 1)
     self.assertEqual(mock_conf_action.call_count, 1)
     mock_module_object.fail_json.assert_not_called()
     return_dict = dict(changed=False,
                        switchInfo='Info',
                        switchConfigurable=True,
                        portConfigurable=True,
                        taskCreated=True,
                        taskExecuted=False,
                        taskCompleted=False)
     mock_module_object.exit_json.assert_called_with(**return_dict)
 def test_main_show(self, mock_module, mock_connect, mock_info, mock_comp,
                    mock_server_conf, mock_port_conf, mock_conf_action):
     ''' Test main good with show action.
     '''
     mock_module_object = Mock()
     mock_module_object.params = dict(action='show', switch_name='eos',
                                      switch_port='3', auto_run=False)
     mock_module.return_value = mock_module_object
     mock_connect.return_value = 'Client'
     mock_info.return_value = 'Info'
     mock_server_conf.return_value = 'Configlet'
     mock_port_conf.return_value = 'Port'
     mock_conf_action.return_value = dict()
     cv_server_provision.main()
     self.assertEqual(mock_connect.call_count, 1)
     self.assertEqual(mock_info.call_count, 1)
     mock_comp.assert_not_called()
     self.assertEqual(mock_server_conf.call_count, 1)
     self.assertEqual(mock_port_conf.call_count, 1)
     self.assertEqual(mock_conf_action.call_count, 1)
     mock_module_object.fail_json.assert_not_called()
     return_dict = dict(changed=False, switchInfo='Info',
                        switchConfigurable=True, portConfigurable=True,
                        taskCreated=False, taskExecuted=False,
                        taskCompleted=False)
     mock_module_object.exit_json.assert_called_with(**return_dict)