def test_ensure_get_called(self):
     ''' test get_fpolicy_policy for non-existent config'''
     set_module_args(self.set_default_args(use_rest='Never'))
     print('starting')
     my_obj = fpolicy_policy_module()
     print('use_rest:', my_obj.use_rest)
     my_obj.server = self.server
     assert my_obj.get_fpolicy_policy is not None
 def get_fpolicy_policy_mock_object(cx_type='zapi', kind=None):
     fpolicy_policy_obj = fpolicy_policy_module()
     if cx_type == 'zapi':
         if kind is None:
             fpolicy_policy_obj.server = MockONTAPConnection()
         else:
             fpolicy_policy_obj.server = MockONTAPConnection(kind=kind)
     return fpolicy_policy_obj
 def test_successful_delete(self, delete_fpolicy_policy):
     ''' delete fpolicy_policy and test idempotency '''
     data = self.set_default_args(use_rest='Never')
     data['state'] = 'absent'
     set_module_args(data)
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('fpolicy_policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     # to reset na_helper from remembering the previous 'changed' value
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_successful_create(self, create_fpolicy_policy):
     ''' creating fpolicy_policy and test idempotency '''
     set_module_args(self.set_default_args(use_rest='Never'))
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     create_fpolicy_policy.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     set_module_args(self.set_default_args(use_rest='Never'))
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('fpolicy_policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_successful_modify(self, modify_fpolicy_policy):
     ''' modifying fpolicy_policy config and testing idempotency '''
     data = self.set_default_args(use_rest='Never')
     data['is_mandatory'] = True
     set_module_args(data)
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('fpolicy_policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     # to reset na_helper from remembering the previous 'changed' value
     data['is_mandatory'] = False
     set_module_args(data)
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('fpolicy_policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_if_all_methods_catch_exception(self):
     data = self.set_default_args(use_rest='Never')
     set_module_args(data)
     my_obj = fpolicy_policy_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('fpolicy_policy_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_fpolicy_policy()
     assert 'Error creating fPolicy policy ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_fpolicy_policy()
     assert 'Error deleting fPolicy policy ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.modify_fpolicy_policy(modify={})
     assert 'Error modifying fPolicy policy ' in exc.value.args[0]['msg']
 def test_ensure_get_called_existing(self):
     ''' test get_fpolicy_policy_config for existing config'''
     set_module_args(self.set_default_args(use_rest='Never'))
     my_obj = fpolicy_policy_module()
     my_obj.server = MockONTAPConnection(kind='fpolicy_policy')
     assert my_obj.get_fpolicy_policy()
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         fpolicy_policy_module()
     print('Info: %s' % exc.value.args[0]['msg'])