Add some more unittests for fail_json
Test that order of msg as a keyword arg doesn't matter
This commit is contained in:
parent
6531ba38f8
commit
184f540056
1 changed files with 22 additions and 1 deletions
|
@ -7,6 +7,7 @@ from __future__ import (absolute_import, division)
|
|||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -67,11 +68,31 @@ class TestAnsibleModuleExitJson:
|
|||
assert return_val == {'msg': 'This is the msg', 'failed': True,
|
||||
'invocation': EMPTY_INVOCATION}
|
||||
|
||||
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
||||
def test_fail_json_msg_as_kwarg_after(self, am, capfd):
|
||||
"""Test that msg as a kwarg after other kwargs works"""
|
||||
with pytest.raises(SystemExit) as ctx:
|
||||
am.fail_json(arbitrary=42, msg='This is the msg')
|
||||
assert ctx.value.code == 1
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
return_val = json.loads(out)
|
||||
# Fail_json should add failed=True
|
||||
assert return_val == {'msg': 'This is the msg', 'failed': True,
|
||||
'arbitrary': 42,
|
||||
'invocation': EMPTY_INVOCATION}
|
||||
|
||||
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
||||
def test_fail_json_no_msg(self, am):
|
||||
with pytest.raises(TypeError) as ctx:
|
||||
am.fail_json()
|
||||
assert ctx.value.args[0] == "fail_json() missing 1 required positional argument: 'msg'"
|
||||
|
||||
if sys.version_info < (3,):
|
||||
error_msg = "fail_json() takes exactly 2 arguments (1 given)"
|
||||
else:
|
||||
error_msg = "fail_json() missing 1 required positional argument: 'msg'"
|
||||
|
||||
assert ctx.value.args[0] == error_msg
|
||||
|
||||
|
||||
class TestAnsibleModuleExitValuesRemoved:
|
||||
|
|
Loading…
Reference in a new issue