Fix unittests for return of invocation from fail_json and exit_json

This commit is contained in:
Toshio Kuratomi 2015-12-19 15:49:06 -08:00
parent bb2935549f
commit e2d9f4e2f2

View file

@ -56,7 +56,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
else:
self.assertEquals(ctx.exception.code, 0)
return_val = json.loads(self.fake_stream.getvalue())
self.assertEquals(return_val, dict(changed=False))
self.assertEquals(return_val, dict(changed=False, invocation={}))
def test_exit_json_args_exits(self):
with self.assertRaises(SystemExit) as ctx:
@ -67,7 +67,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
else:
self.assertEquals(ctx.exception.code, 0)
return_val = json.loads(self.fake_stream.getvalue())
self.assertEquals(return_val, dict(msg="message", changed=False))
self.assertEquals(return_val, dict(msg="message", changed=False, invocation={}))
def test_fail_json_exits(self):
with self.assertRaises(SystemExit) as ctx:
@ -78,13 +78,13 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
else:
self.assertEquals(ctx.exception.code, 1)
return_val = json.loads(self.fake_stream.getvalue())
self.assertEquals(return_val, dict(msg="message", failed=True))
self.assertEquals(return_val, dict(msg="message", failed=True, invocation={}))
def test_exit_json_proper_changed(self):
with self.assertRaises(SystemExit) as ctx:
self.module.exit_json(changed=True, msg='success')
return_val = json.loads(self.fake_stream.getvalue())
self.assertEquals(return_val, dict(changed=True, msg='success'))
self.assertEquals(return_val, dict(changed=True, msg='success', invocation={}))
@unittest.skipIf(sys.version_info[0] >= 3, "Python 3 is not supported on targets (yet)")
class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
@ -94,19 +94,22 @@ class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
dict(one=1, pwd='$ecret k3y', url='https://username:password12345@foo.com/login/',
not_secret='following the leader', msg='here'),
dict(one=1, pwd=OMIT, url='https://username:password12345@foo.com/login/',
not_secret='following the leader', changed=False, msg='here')
not_secret='following the leader', changed=False, msg='here',
invocation=dict(password=OMIT, token=None, username='person')),
),
(dict(username='person', password='password12345'),
dict(one=1, pwd='$ecret k3y', url='https://username:password12345@foo.com/login/',
not_secret='following the leader', msg='here'),
dict(one=1, pwd='$ecret k3y', url='https://username:********@foo.com/login/',
not_secret='following the leader', changed=False, msg='here')
not_secret='following the leader', changed=False, msg='here',
invocation=dict(password=OMIT, token=None, username='person')),
),
(dict(username='person', password='$ecret k3y'),
dict(one=1, pwd='$ecret k3y', url='https://username:$ecret k3y@foo.com/login/',
not_secret='following the leader', msg='here'),
dict(one=1, pwd=OMIT, url='https://username:********@foo.com/login/',
not_secret='following the leader', changed=False, msg='here')
not_secret='following the leader', changed=False, msg='here',
invocation=dict(password=OMIT, token=None, username='person')),
),
)