From 1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 18 Jul 2012 16:00:49 -0400 Subject: Update iteritems test case to actually test iteritems. This patch updates the jsonutils.to_primitive() test case for when an object has an iteritems() method. The previous implementation was mostly a copy of another test and didn't actually test calling iteritems() at all. Now it does. This is used by NovaBase in nova.db.sqlalchemy.models. Related to nova blueprint no-db-messaging. Change-Id: Ie1d71b859219392ab35b82dd3c7932b30e759c89 --- tests/unit/test_jsonutils.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/unit/test_jsonutils.py b/tests/unit/test_jsonutils.py index 4a18b77..fe25697 100644 --- a/tests/unit/test_jsonutils.py +++ b/tests/unit/test_jsonutils.py @@ -88,19 +88,12 @@ class ToPrimitiveTestCase(unittest.TestCase): self.data = dict(a=1, b=2, c=3).items() self.index = 0 - def __iter__(self): - return self - - def next(self): - if self.index == len(self.data): - raise StopIteration - self.index = self.index + 1 - return self.data[self.index - 1] + def iteritems(self): + return self.data x = IterItemsClass() - ordered = jsonutils.to_primitive(x) - ordered.sort() - self.assertEquals(ordered, [['a', 1], ['b', 2], ['c', 3]]) + p = jsonutils.to_primitive(x) + self.assertEquals(p, {'a': 1, 'b': 2, 'c': 3}) def test_instance(self): class MysteryClass(object): -- cgit