def test_ensure_command_called(self, mock_create_sf_connection):
     ''' a more interesting test '''
     set_module_args({
         'state': 'present',
         'name': 'element_groupname',
         'account_id': 'element_account_id',
         'hostname': 'hostname',
         'username': '******',
         'password': '******',
     })
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         # It may not be a good idea to start with apply
         # More atomic methods can be easier to mock
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
 def test_check_error_reporting_on_add_exception(self,
                                                 mock_create_sf_connection):
     ''' a more interesting test '''
     set_module_args({
         'state': 'present',
         'name': 'element_groupname',
         'account_id': 'element_account_id',
         'hostname': 'hostname',
         'username': '******',
         'password': '******',
     })
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(
         force_error=True, where=['add'])
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         # It may not be a good idea to start with apply
         # More atomic methods can be easier to mock
         # apply() is calling list_accounts() and add_account()
         my_obj.apply()
     print(exc.value.args[0])
     message = 'Error creating volume access group element_groupname: %s' % ADD_ERROR
     assert exc.value.args[0]['msg'] == message
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         my_module()
     print('Info: %s' % exc.value.args[0]['msg'])