From 5034c5ab5969a21055d6ed9f4500d2970f02f696 Mon Sep 17 00:00:00 2001 From: Yann DEGAT Date: Tue, 27 May 2014 16:47:51 +0200 Subject: [PATCH] Fixes the dict comparison in the tests Get rid of the dict_equals func + various refactoring in accordance with the languagepack create test Change-Id: I7a8a4dbe123e84c7d32deeed3eedae1fd617458c --- solumclient/tests/test_solum.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/solumclient/tests/test_solum.py b/solumclient/tests/test_solum.py index f579d5d..07bf11f 100644 --- a/solumclient/tests/test_solum.py +++ b/solumclient/tests/test_solum.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import collections import json import re import sys @@ -179,27 +180,20 @@ class TestSolum(base.TestCase): @mock.patch.object(cliutils, "print_dict") @mock.patch.object(plan.PlanManager, "create") def test_app_create(self, mock_app_create, mock_print_dict): - def dict_equals(dicta, dictb): - unmatched_items = set(dicta) ^ set(dictb) - return len(unmatched_items) == 0 + FakeResource = collections.namedtuple("FakeResource", + "uuid name description uri") - mock_app_create.return_value = dict(uuid='foo', - name='foo', - description='foo', - uri='foo') + mock_app_create.return_value = FakeResource('foo', 'foo', 'foo', 'foo') + expected_printed_dict_args = mock_app_create.return_value._asdict() plan_data = yaml.load(plan_file_data) mopen = mock.mock_open(read_data=plan_file_data) with mock.patch('%s.open' % solum.__name__, mopen, create=True): self.make_env() self.shell("app create /dev/null") - mock_app_create.assert_called_once() - mock_print_dict.assert_called_once() - self.assertTrue( - dict_equals(mock_app_create.call_args[1], plan_data)) - self.assertTrue( - dict_equals( - mock_print_dict.call_args[0][0], - mock_app_create.return_value)) + mock_app_create.assert_called_once_with(**plan_data) + mock_print_dict.assert_called_once_with( + expected_printed_dict_args, + wrap=72) @mock.patch.object(plan.PlanManager, "list") def test_app_list(self, mock_app_list):