Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Aug 19, 2024
1 parent fb8a3d6 commit 7a23587
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
26 changes: 15 additions & 11 deletions plugins/module_utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
from __future__ import absolute_import, annotations, division, print_function

from typing import List, Optional, Union
from typing import Any, List, NoReturn, Optional, Union

from ansible.module_utils.basic import AnsibleModule

Expand Down Expand Up @@ -75,7 +75,7 @@ def get_item_name(self, item):
msg = "Cant determine identity field for Undefined object."
raise EDAError(msg)

def fail_wanted_one(self, response, endpoint, query_params):
def fail_wanted_one(self, response, endpoint, query_params) -> NoReturn:
sample = response.json.copy()
if len(sample["results"]) > 1:
sample["results"] = sample["results"][:2] + ["...more results snipped..."]
Expand All @@ -90,22 +90,26 @@ def fail_wanted_one(self, response, endpoint, query_params):
def get_exactly_one(
self, endpoint, name=None, **kwargs
) -> Optional[dict[str, bool]]:
result = self.get_one_or_many(endpoint, name=name, allow_none=False, **kwargs)
if isinstance(result, list):
raise RuntimeError("This should never happen.")
result = self.get_one_or_many(

Check warning on line 93 in plugins/module_utils/controller.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/controller.py#L93

Added line #L93 was not covered by tests
endpoint, name=name, allow_none=False, want_one=True, **kwargs
)
# typing: needed as get_one_or_many can also return lists, not expected
# to reach this ever.
if isinstance(result, list): # pragma: no cover
self.fail_wanted_one(result, endpoint, {})
return result

Check warning on line 100 in plugins/module_utils/controller.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/controller.py#L100

Added line #L100 was not covered by tests

def resolve_name_to_id(self, endpoint, name):
return self.get_exactly_one(endpoint, name)["id"]

def get_one_or_many(
self,
endpoint,
name=None,
allow_none=True,
check_exists=False,
want_one=True,
**kwargs,
endpoint: str,
name: Optional[str] = None,
allow_none: bool = True,
check_exists: bool = False,
want_one: bool = True,
**kwargs: Any,
) -> Union[None, dict[str, bool], List]:
new_kwargs = kwargs.copy()
response = None
Expand Down
1 change: 0 additions & 1 deletion tests/sanity/ignore-2.15.txt

This file was deleted.

15 changes: 15 additions & 0 deletions tests/sanity/ignore-2.15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins/module_utils/arguments.py future-import-boilerplate!skip
plugins/module_utils/common.py import-3.7!skip
plugins/module_utils/common.py import-3.8!skip
plugins/module_utils/controller.py future-import-boilerplate!skip
plugins/modules/activation.py import-3.7!skip
plugins/modules/activation.py import-3.8!skip
plugins/modules/activation_info.py import-3.7!skip
plugins/modules/activation_info.py import-3.8!skip
plugins/modules/credential_info.py import-3.7!skip
plugins/modules/credential_info.py import-3.8!skip
plugins/modules/credential_type_info.py future-import-boilerplate!skip
plugins/modules/credential_type_info.py import-3.7!skip
plugins/modules/credential_type_info.py import-3.8!skip
plugins/modules/decision_environment_info.py import-3.7!skip
plugins/modules/decision_environment_info.py import-3.8!skip
1 change: 0 additions & 1 deletion tests/sanity/ignore-2.16.txt

This file was deleted.

15 changes: 15 additions & 0 deletions tests/sanity/ignore-2.16.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins/module_utils/arguments.py future-import-boilerplate!skip
plugins/module_utils/common.py import-3.7!skip
plugins/module_utils/common.py import-3.8!skip
plugins/module_utils/controller.py future-import-boilerplate!skip
plugins/modules/activation.py import-3.7!skip
plugins/modules/activation.py import-3.8!skip
plugins/modules/activation_info.py import-3.7!skip
plugins/modules/activation_info.py import-3.8!skip
plugins/modules/credential_info.py import-3.7!skip
plugins/modules/credential_info.py import-3.8!skip
plugins/modules/credential_type_info.py future-import-boilerplate!skip
plugins/modules/credential_type_info.py import-3.7!skip
plugins/modules/credential_type_info.py import-3.8!skip
plugins/modules/decision_environment_info.py import-3.7!skip
plugins/modules/decision_environment_info.py import-3.8!skip

0 comments on commit 7a23587

Please sign in to comment.