mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 04:24:00 -07:00
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
# Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from .hpe_test_utils import FactsParamsTest
|
|
from .oneview_conftest import mock_ov_client, mock_ansible_module # noqa: F401, pylint: disable=unused-import
|
|
|
|
from ansible_collections.community.general.plugins.modules.oneview_datacenter_info import DatacenterInfoModule
|
|
|
|
PARAMS_GET_CONNECTED = dict(
|
|
config='config.json',
|
|
name="MyDatacenter",
|
|
options=['visualContent']
|
|
)
|
|
|
|
|
|
class TestDatacenterInfoModule(FactsParamsTest):
|
|
@pytest.fixture(autouse=True)
|
|
def setUp(self, mock_ansible_module, mock_ov_client):
|
|
self.resource = mock_ov_client.datacenters
|
|
self.mock_ansible_module = mock_ansible_module
|
|
self.mock_ov_client = mock_ov_client
|
|
|
|
def test_should_get_all_datacenters(self):
|
|
self.resource.get_all.return_value = {"name": "Data Center Name"}
|
|
|
|
self.mock_ansible_module.params = dict(config='config.json')
|
|
|
|
DatacenterInfoModule().run()
|
|
|
|
self.mock_ansible_module.exit_json.assert_called_once_with(
|
|
changed=False,
|
|
datacenters=({"name": "Data Center Name"})
|
|
)
|
|
|
|
def test_should_get_datacenter_by_name(self):
|
|
self.resource.get_by.return_value = [{"name": "Data Center Name"}]
|
|
|
|
self.mock_ansible_module.params = dict(config='config.json', name="MyDatacenter")
|
|
|
|
DatacenterInfoModule().run()
|
|
|
|
self.mock_ansible_module.exit_json.assert_called_once_with(
|
|
changed=False,
|
|
datacenters=([{"name": "Data Center Name"}])
|
|
)
|
|
|
|
def test_should_get_datacenter_visual_content(self):
|
|
self.resource.get_by.return_value = [{"name": "Data Center Name", "uri": "/rest/datacenter/id"}]
|
|
|
|
self.resource.get_visual_content.return_value = {
|
|
"name": "Visual Content"}
|
|
|
|
self.mock_ansible_module.params = PARAMS_GET_CONNECTED
|
|
|
|
DatacenterInfoModule().run()
|
|
|
|
self.mock_ansible_module.exit_json.assert_called_once_with(
|
|
changed=False,
|
|
datacenter_visual_content={'name': 'Visual Content'},
|
|
datacenters=[{'name': 'Data Center Name', 'uri': '/rest/datacenter/id'}]
|
|
)
|
|
|
|
def test_should_get_none_datacenter_visual_content(self):
|
|
self.resource.get_by.return_value = []
|
|
|
|
self.mock_ansible_module.params = PARAMS_GET_CONNECTED
|
|
|
|
DatacenterInfoModule().run()
|
|
|
|
self.mock_ansible_module.exit_json.assert_called_once_with(
|
|
changed=False,
|
|
datacenter_visual_content=None,
|
|
datacenters=[]
|
|
)
|