Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup: fix github issue#59 #60

Merged
merged 2 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def list(self, data=None, endpoint=None, use_base_url=False, timeout=30):
url = url + "/{0}".format(endpoint)
return self._fetch_url(url, method="POST", data=data, timeout=timeout)

def get_spec(self):
spec = self._get_default_spec()
for ansible_param, ansible_value in self.module.params.items():
build_spec_method = self.build_spec_methods.get(ansible_param)
if build_spec_method and ansible_value:
spec, error = build_spec_method(spec, ansible_value)
if error:
return None, error
return spec, None

def get_uuid(self, name):
data = {"filter": "name=={0}".format(name), "length": 1}
resp, status = self.list(data)
Expand Down
10 changes: 0 additions & 10 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ def __init__(self, module):
"categories": self._build_spec_categories,
}

def get_spec(self):
spec = self._get_default_spec()
for ansible_param, ansible_value in self.module.params.items():
build_spec_method = self.build_spec_methods.get(ansible_param)
if build_spec_method and ansible_value:
spec, error = build_spec_method(spec, ansible_value)
if error:
return None, error
return spec, None

def _get_default_spec(self):
return deepcopy(
{
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/plugins/module_utils/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def test_list_action(self):
result = self.entity.list(data)
self.assertEqual(result["request"], req)

def test_negative_list_action(self):
data = {}
self.module.params = {}
entity = Entity(self.module, resource_type="")

req = {"method": "POST", "url": "https://None//list", "data": data}
result = entity.list(data)
self.assertEqual(result["request"], req)
self.assertEqual(entity.headers.get("Authorization"), None)

def test_delete_action(self):
uuid = "test_uuid"
req = {
Expand All @@ -115,6 +125,16 @@ def test_delete_action(self):
result = self.entity.delete(uuid=uuid)
self.assertEqual(result["request"], req)

def test_negative_delete_action(self):
data = None
self.module.params = {}
entity = Entity(self.module, resource_type="")

req = {"method": "DELETE", "url": "https://None/", "data": data}
result = entity.delete(data)
self.assertEqual(result["request"], req)
self.assertEqual(entity.headers.get("Authorization"), None)

def test_build_url(self):
module_name = "test"
actual = self.entity._build_url(self.module, "https", "/test")
Expand Down