Skip to content

Commit

Permalink
Merge pull request #60 from nutanix/imprv/issue#59
Browse files Browse the repository at this point in the history
Code cleanup: fix github issue#59
  • Loading branch information
alaa-bish authored Feb 6, 2022
2 parents d4c596e + 8b7c471 commit c969651
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
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

0 comments on commit c969651

Please sign in to comment.