mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 06:49:10 -07:00
Add module hana_query to make SAP HANA administration easier. (#2623)
* new * move link * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * add more interesting return value in test * remove unused objects * removed unneeded function * extend test output * Update tests/unit/plugins/modules/database/saphana/test_hana_query.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Rainer Leber <rainer.leber@sva.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
909e9fe950
commit
b79969da68
4 changed files with 254 additions and 0 deletions
0
tests/unit/plugins/modules/database/saphana/__init__.py
Normal file
0
tests/unit/plugins/modules/database/saphana/__init__.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2021, Rainer Leber (@rainerleber) <rainerleber@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import hana_query
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import (
|
||||
AnsibleExitJson,
|
||||
AnsibleFailJson,
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
|
||||
|
||||
def get_bin_path(*args, **kwargs):
|
||||
"""Function to return path of hdbsql"""
|
||||
return "/usr/sap/HDB/HDB01/exe/hdbsql"
|
||||
|
||||
|
||||
class Testhana_query(ModuleTestCase):
|
||||
"""Main class for testing hana_query module."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup."""
|
||||
super(Testhana_query, self).setUp()
|
||||
self.module = hana_query
|
||||
self.mock_get_bin_path = patch.object(basic.AnsibleModule, 'get_bin_path', get_bin_path)
|
||||
self.mock_get_bin_path.start()
|
||||
self.addCleanup(self.mock_get_bin_path.stop) # ensure that the patching is 'undone'
|
||||
|
||||
def tearDown(self):
|
||||
"""Teardown."""
|
||||
super(Testhana_query, self).tearDown()
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing."""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
|
||||
def test_hana_query(self):
|
||||
"""Check that result is processed."""
|
||||
set_module_args({
|
||||
'sid': "HDB",
|
||||
'instance': "01",
|
||||
'encrypted': False,
|
||||
'host': "localhost",
|
||||
'user': "SYSTEM",
|
||||
'password': "1234Qwer",
|
||||
'database': "HDB",
|
||||
'query': "SELECT * FROM users;"
|
||||
})
|
||||
with patch.object(basic.AnsibleModule, 'run_command') as run_command:
|
||||
run_command.return_value = 0, 'username,name\n testuser,test user \n myuser, my user \n', ''
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
hana_query.main()
|
||||
self.assertEqual(result.exception.args[0]['query_result'], [[
|
||||
{'username': 'testuser', 'name': 'test user'},
|
||||
{'username': 'myuser', 'name': 'my user'},
|
||||
]])
|
||||
self.assertEqual(run_command.call_count, 1)
|
Loading…
Add table
Add a link
Reference in a new issue