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
This commit is contained in:
Russell Bryant 2012-07-18 16:00:49 -04:00
parent d5f2152dcf
commit 1c1b36985b

View File

@ -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):