def get_volume_efficiency_mock_object(cx_type='zapi', kind=None):
     volume_efficiency_obj = volume_efficiency_module()
     if cx_type == 'zapi':
         if kind is None:
             volume_efficiency_obj.server = MockONTAPConnection()
         else:
             volume_efficiency_obj.server = MockONTAPConnection(kind=kind)
     return volume_efficiency_obj
 def test_successful_enable(self, enable_volume_efficiency):
     ''' enable volume_efficiency and testing idempotency '''
     set_module_args(self.set_default_args(use_rest='Never'))
     my_obj = volume_efficiency_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('volume_efficiency_disabled')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     enable_volume_efficiency.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 = volume_efficiency_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('volume_efficiency_enabled')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_successful_modify(self, modify_volume_efficiency):
     ''' modifying volume_efficiency config and testing idempotency '''
     data = self.set_default_args(use_rest='Never')
     data['policy'] = 'default'
     set_module_args(data)
     my_obj = volume_efficiency_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('volume_efficiency_enabled')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     # modify_volume_efficiency.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     data['policy'] = 'auto'
     set_module_args(data)
     my_obj = volume_efficiency_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('volume_efficiency_enabled')
     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 = volume_efficiency_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('volume_efficiency_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.enable_volume_efficiency()
     assert 'Error enabling storage efficiency' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.disable_volume_efficiency()
     assert 'Error disabling storage efficiency' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.modify_volume_efficiency()
     assert 'Error modifying storage efficiency' in exc.value.args[0]['msg']
 def test_ensure_get_called_existing(self):
     ''' test get_volume_efficiency for existing config '''
     set_module_args(self.set_default_args(use_rest='Never'))
     my_obj = volume_efficiency_module()
     my_obj.server = MockONTAPConnection(kind='volume_efficiency_enabled')
     assert my_obj.get_volume_efficiency()
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         volume_efficiency_module()
     print('Info: %s' % exc.value.args[0]['msg'])