diff --git a/changelogs/fragments/11145-ruff-cases-4.yml b/changelogs/fragments/11145-ruff-cases-4.yml new file mode 100644 index 0000000000..799d866d1d --- /dev/null +++ b/changelogs/fragments/11145-ruff-cases-4.yml @@ -0,0 +1,2 @@ +bugfixes: + - ipinfoio_facts - fix handling of HTTP errors consulting the service (https://github.com/ansible-collections/community.general/pull/11145). diff --git a/plugins/modules/ipinfoio_facts.py b/plugins/modules/ipinfoio_facts.py index a233611438..705eba61ba 100644 --- a/plugins/modules/ipinfoio_facts.py +++ b/plugins/modules/ipinfoio_facts.py @@ -95,25 +95,23 @@ class IpinfoioFacts: response, info = fetch_url( self.module, self.url, - force=True, # NOQA + force=True, timeout=self.timeout, ) - try: - info["status"] == 200 - except AssertionError: + if info["status"] != 200: self.module.fail_json(msg=f"Could not get {self.url} page, check for connectivity!") + + try: + content = response.read() + result = self.module.from_json(content) + except ValueError: + self.module.fail_json(msg=f"Failed to parse the ipinfo.io response: {self.url} {content}") else: - try: - content = response.read() - result = self.module.from_json(content.decode("utf8")) - except ValueError: - self.module.fail_json(msg=f"Failed to parse the ipinfo.io response: {self.url} {content}") - else: - return result + return result def main(): - module = AnsibleModule( # NOQA + module = AnsibleModule( argument_spec=dict( http_agent=dict(default=USER_AGENT), timeout=dict(type="int", default=10), diff --git a/ruff.toml b/ruff.toml index cc83b38257..30426aa23f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -27,7 +27,6 @@ ignore = [ "UP030", # Use implicit references for positional format fields "UP031", # Use format specifiers instead of percent format "UP041", # Replace aliased errors with `TimeoutError` - "B015", # useless-comparison "B026", # star-arg-unpacking-after-keyword-arg "SIM102", # collapsible-if "SIM110", # reimplemented-builtin diff --git a/tests/unit/plugins/module_utils/net_tools/pritunl/test_api.py b/tests/unit/plugins/module_utils/net_tools/pritunl/test_api.py index 165e9eaf8a..027f3e5a8a 100644 --- a/tests/unit/plugins/module_utils/net_tools/pritunl/test_api.py +++ b/tests/unit/plugins/module_utils/net_tools/pritunl/test_api.py @@ -441,7 +441,7 @@ class TestPritunlApi: for org in response: if org["id"] == org_id: - org["user_count"] == org_user_count + assert org["user_count"] == org_user_count @pytest.mark.parametrize( "org_filters,org_expected", diff --git a/tests/unit/plugins/modules/test_pacman.py b/tests/unit/plugins/modules/test_pacman.py index 934a5717a6..bf16cdfb8f 100644 --- a/tests/unit/plugins/modules/test_pacman.py +++ b/tests/unit/plugins/modules/test_pacman.py @@ -354,7 +354,7 @@ class TestPacman: with pytest.raises(AnsibleExitJson) as e: P.run() - self.mock_run_command.call_count == 0 + assert self.mock_run_command.call_count == 0 out = e.value.args[0] assert "packages" not in out assert out["changed"] @@ -494,7 +494,7 @@ class TestPacman: out = e.value.args[0] if check_mode_value: - self.mock_run_command.call_count == 0 + assert self.mock_run_command.call_count == 0 if run_command_data and "args" in run_command_data: self.mock_run_command.assert_called_with(mock.ANY, run_command_data["args"], check_rc=False) @@ -672,7 +672,7 @@ class TestPacman: assert not out["changed"] assert "packages" in out assert "diff" not in out - self.mock_run_command.call_count == 0 + assert self.mock_run_command.call_count == 0 @pytest.mark.parametrize( "module_args, expected_packages, package_list_out, run_command_data, raises",