mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-10 03:01:29 -07:00
Ensure uri module always returns status even on failure (#56240)
- Also return url and update docs for other values to indicate they are only returned on success. - Add integration tests - Use info variable for common return values - Use -1 as default status rather than None. This is lines up with with existing code in urls.py - Add unit tests to ensure status and url are returned on failure
This commit is contained in:
parent
22b9525aa9
commit
8f4f3750fe
5 changed files with 19 additions and 8 deletions
|
@ -157,6 +157,8 @@ def test_fetch_url_nossl(open_url_mock, fake_ansible_module, mocker):
|
|||
fetch_url(fake_ansible_module, 'http://ansible.com/')
|
||||
|
||||
assert 'python-ssl' in excinfo.value.kwargs['msg']
|
||||
assert'http://ansible.com/' == excinfo.value.kwargs['url']
|
||||
assert excinfo.value.kwargs['status'] == -1
|
||||
|
||||
|
||||
def test_fetch_url_connectionerror(open_url_mock, fake_ansible_module):
|
||||
|
@ -165,12 +167,16 @@ def test_fetch_url_connectionerror(open_url_mock, fake_ansible_module):
|
|||
fetch_url(fake_ansible_module, 'http://ansible.com/')
|
||||
|
||||
assert excinfo.value.kwargs['msg'] == 'TESTS'
|
||||
assert'http://ansible.com/' == excinfo.value.kwargs['url']
|
||||
assert excinfo.value.kwargs['status'] == -1
|
||||
|
||||
open_url_mock.side_effect = ValueError('TESTS')
|
||||
with pytest.raises(FailJson) as excinfo:
|
||||
fetch_url(fake_ansible_module, 'http://ansible.com/')
|
||||
|
||||
assert excinfo.value.kwargs['msg'] == 'TESTS'
|
||||
assert'http://ansible.com/' == excinfo.value.kwargs['url']
|
||||
assert excinfo.value.kwargs['status'] == -1
|
||||
|
||||
|
||||
def test_fetch_url_httperror(open_url_mock, fake_ansible_module):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue