def test_ensure_get_called_valid_account(self, client_f, mock_base): set_module_args(self.set_default_args()) mock_base.return_value = Mock() client_f.return_value = Mock() client_f.side_effect = Mock() my_obj = account_module() # my_obj.netapp_client = self.netapp_client my_obj.netapp_client.accounts = self.netapp_client.accounts assert my_obj.get_azure_netapp_account() is not None
def test_ensure_get_called_non_existing_account(self, client_f, mock_base): data = self.set_default_args() data['name'] = 'invalid' set_module_args(data) mock_base.return_value = Mock() client_f.return_value = Mock() client_f.side_effect = Mock() my_obj = account_module() my_obj.netapp_client.accounts = self.netapp_client.accounts assert my_obj.get_azure_netapp_account() is None
def test_ensure_delete_called(self, client_f, mock_delete, mock_get, mock_base): data = self.set_default_args() data['state'] = 'absent' set_module_args(data) mock_base.return_value = Mock() mock_get.return_value = Mock() client_f.return_value = Mock() client_f.side_effect = Mock() my_obj = account_module() my_obj.netapp_client.accounts = self.netapp_client.accounts with pytest.raises(AnsibleExitJson) as exc: my_obj.exec_module() assert exc.value.args[0]['changed'] mock_delete.assert_called_with()
def test_ensure_create_called(self, client_f, mock_create, mock_get, mock_base): data = self.set_default_args() data['name'] = 'create' data['tags'] = {'ttt': 'tesssttt', 'abc': 'xyz'} set_module_args(data) mock_get.return_value = None mock_base.return_value = Mock() client_f.return_value = Mock() client_f.side_effect = Mock() my_obj = account_module() my_obj.netapp_client.accounts = self.netapp_client.accounts with pytest.raises(AnsibleExitJson) as exc: my_obj.exec_module() assert exc.value.args[0]['changed'] mock_create.assert_called_with()
def test_module_fail_when_required_args_missing(self): ''' required arguments are reported as errors ''' with pytest.raises(AnsibleFailJson) as exc: set_module_args({}) account_module() print('Info: %s' % exc.value.args[0]['msg'])