def test_if_all_methods_catch_exception(self): module_args = {} module_args.update(self.set_default_args()) module_args.update({'service_state': 'online'}) module_args.update({'unmount_volumes': 'True'}) module_args.update({'from_name': 'test_name2'}) set_module_args(module_args) my_obj = my_module() if not self.onbox: my_obj.server = MockONTAPConnection('aggregate_fail') with pytest.raises(AnsibleFailJson) as exc: my_obj.aggr_get_iter(module_args.get('name')) assert '' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.aggregate_online() assert 'Error changing the state of aggregate' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.aggregate_offline() assert 'Error changing the state of aggregate' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.create_aggr() assert 'Error provisioning aggregate' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.delete_aggr() assert 'Error removing aggregate' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.rename_aggregate() assert 'Error renaming aggregate' in exc.value.args[0]['msg'] with pytest.raises(AnsibleFailJson) as exc: my_obj.asup_log_for_cserver = Mock(return_value=None) my_obj.apply() assert 'TEST:This exception is from the unit test' in exc.value.args[0]['msg']
def call_command(self, module_args): ''' utility function to call apply ''' module_args.update(self.set_default_args()) set_module_args(module_args) my_obj = my_module() my_obj.asup_log_for_cserver = Mock(return_value=None) if not self.onbox: # mock the connection my_obj.server = MockONTAPConnection('aggregate', '12', 'test_name') with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() return exc.value.args[0]['changed']
def call_command(self, module_args, what=None): ''' utility function to call apply ''' args = dict(self.set_default_args()) args.update(module_args) set_module_args(args) my_obj = my_module() my_obj.asup_log_for_cserver = Mock(return_value=None) aggregate = 'aggregate' if what == 'disks': aggregate = 'aggr_disks' elif what == 'mirrors': aggregate = 'aggr_mirrors' elif what is not None: aggregate = what if not self.onbox: # mock the connection my_obj.server = MockONTAPConnection(aggregate, '12', AGGR_NAME) self.zapis = my_obj.server.zapis with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() return exc.value.args[0]['changed']
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'])