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
This commit is contained in:
Yann DEGAT
2014-05-27 16:47:51 +02:00
parent 987e234ac2
commit 5034c5ab59

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import collections
import json import json
import re import re
import sys import sys
@@ -179,27 +180,20 @@ class TestSolum(base.TestCase):
@mock.patch.object(cliutils, "print_dict") @mock.patch.object(cliutils, "print_dict")
@mock.patch.object(plan.PlanManager, "create") @mock.patch.object(plan.PlanManager, "create")
def test_app_create(self, mock_app_create, mock_print_dict): def test_app_create(self, mock_app_create, mock_print_dict):
def dict_equals(dicta, dictb): FakeResource = collections.namedtuple("FakeResource",
unmatched_items = set(dicta) ^ set(dictb) "uuid name description uri")
return len(unmatched_items) == 0
mock_app_create.return_value = dict(uuid='foo', mock_app_create.return_value = FakeResource('foo', 'foo', 'foo', 'foo')
name='foo', expected_printed_dict_args = mock_app_create.return_value._asdict()
description='foo',
uri='foo')
plan_data = yaml.load(plan_file_data) plan_data = yaml.load(plan_file_data)
mopen = mock.mock_open(read_data=plan_file_data) mopen = mock.mock_open(read_data=plan_file_data)
with mock.patch('%s.open' % solum.__name__, mopen, create=True): with mock.patch('%s.open' % solum.__name__, mopen, create=True):
self.make_env() self.make_env()
self.shell("app create /dev/null") self.shell("app create /dev/null")
mock_app_create.assert_called_once() mock_app_create.assert_called_once_with(**plan_data)
mock_print_dict.assert_called_once() mock_print_dict.assert_called_once_with(
self.assertTrue( expected_printed_dict_args,
dict_equals(mock_app_create.call_args[1], plan_data)) wrap=72)
self.assertTrue(
dict_equals(
mock_print_dict.call_args[0][0],
mock_app_create.return_value))
@mock.patch.object(plan.PlanManager, "list") @mock.patch.object(plan.PlanManager, "list")
def test_app_list(self, mock_app_list): def test_app_list(self, mock_app_list):