From 62c4511eeb3b99775ce87b667233d7c5926dbffa Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Thu, 23 Nov 2017 13:25:57 +0100 Subject: [PATCH] Make chef agent tests more reliable They fail sometimes on py35 because we rely on dict order in asserts. Let's remove that and load json instead. Change-Id: I7bff32028cc130128ce05c151534c85ef99607d5 --- tests/test_hook_chef.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_hook_chef.py b/tests/test_hook_chef.py index 05968dc..2fd9c87 100644 --- a/tests/test_hook_chef.py +++ b/tests/test_hook_chef.py @@ -96,8 +96,6 @@ class HookChefTest(common.RunScriptTest): 'fooval': {u'bar': u'baz'}, 'run_list': [u'recipe[apache]'] } - exp_node = json.dumps(exp_node, indent=4, - separators=(',', ': ')) exp_cfg = ("log_level :debug\n" "log_location STDOUT\n" "local_mode true\n" @@ -111,7 +109,8 @@ class HookChefTest(common.RunScriptTest): "node_path '/var/lib/heat-config/" "heat-config-chef/node'") mfdopen.return_value.write.assert_any_call(exp_cfg) - mfdopen.return_value.write.assert_any_call(exp_node) + args = mfdopen.return_value.write.mock_calls[0][1][0] + self.assertEqual(exp_node, json.loads(args)) calls = [ mock.call(['hostname', '-f'], env=mock.ANY, stderr=mock.ANY, stdout=mock.ANY), @@ -194,8 +193,6 @@ class HookChefTest(common.RunScriptTest): 'fooval': {u'bar': u'baz'}, 'run_list': [u'recipe[apache]'] } - exp_node = json.dumps(exp_node, indent=4, - separators=(',', ': ')) exp_cfg = ("log_level :debug\n" "log_location STDOUT\n" "local_mode true\n" @@ -210,4 +207,5 @@ class HookChefTest(common.RunScriptTest): "node_path '/var/lib/heat-config/" "heat-config-chef/node'") mfdopen.return_value.write.assert_any_call(exp_cfg) - mfdopen.return_value.write.assert_any_call(exp_node) + args = mfdopen.return_value.write.mock_calls[0][1][0] + self.assertEqual(exp_node, json.loads(args))