1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

[PR #11066/5ea1dee3 backport][stable-12] oneview: remove superfluous parts from unit test (#11067)

oneview: remove superfluous parts from unit test (#11066)

Remove superfluous parts from unit test.

(cherry picked from commit 5ea1dee3ea)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-11-09 10:10:11 +01:00 committed by GitHub
parent 8cd80d94a0
commit bb926e462f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,6 @@ from __future__ import annotations
import pytest
import re
import yaml
from unittest.mock import Mock, patch
from .oneview_module_loader import ONEVIEW_MODULE_UTILS_PATH
@ -33,15 +32,8 @@ class OneViewBaseTest:
oneview_module = ansible_collections.community.general.plugins.modules
resource_module = getattr(oneview_module, resource_module_path_name)
self.testing_class = getattr(resource_module, resource_name)
testing_module = self.testing_class.__module__.split(".")[-1]
testing_module = getattr(oneview_module, testing_module)
try:
# Load scenarios from module examples (Also checks if it is a valid yaml)
yaml.safe_load(testing_module.EXAMPLES)
except yaml.scanner.ScannerError:
message = f"Something went wrong while parsing yaml from {self.testing_class.__module__}.EXAMPLES"
raise Exception(message)
testing_module_name = self.testing_class.__module__.split(".")[-1]
testing_module = getattr(oneview_module, testing_module_name)
return testing_module
def test_main_function_should_call_run_method(self, testing_module, mock_ansible_module):
@ -94,7 +86,6 @@ class OneViewBaseTestCase:
mock_ansible_module = None
mock_ov_client = None
testing_module = None
EXAMPLES = None
def configure_mocks(self, test_case, testing_class):
"""
@ -120,7 +111,9 @@ class OneViewBaseTestCase:
self.mock_ansible_module = Mock()
mock_ansible_module.return_value = self.mock_ansible_module
self.__set_module_examples()
ansible_collections = __import__("ansible_collections")
testing_module_name = self.testing_class.__module__.split(".")[-1]
self.testing_module = getattr(ansible_collections.community.general.plugins.modules, testing_module_name)
def test_main_function_should_call_run_method(self):
self.mock_ansible_module.params = {"config": "config.json"}
@ -131,20 +124,6 @@ class OneViewBaseTestCase:
main_func()
mock_run.assert_called_once()
def __set_module_examples(self):
# Load scenarios from module examples (Also checks if it is a valid yaml)
ansible_collections = __import__("ansible_collections")
testing_module = self.testing_class.__module__.split(".")[-1]
self.testing_module = getattr(ansible_collections.community.general.plugins.modules, testing_module)
try:
# Load scenarios from module examples (Also checks if it is a valid yaml)
self.EXAMPLES = yaml.safe_load(self.testing_module.EXAMPLES)
except yaml.scanner.ScannerError:
message = f"Something went wrong while parsing yaml from {self.testing_class.__module__}.EXAMPLES"
raise Exception(message)
class FactsParamsTestCase(OneViewBaseTestCase):
"""