summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-18 16:00:49 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-18 16:00:49 -0400
commita9ed13380c948f3c8372e8aba244e1b030b9fe06 (patch)
tree68033ff86a8fb582e6e7f148306377a57a9a6dc2
parent12575344308fee5f04af9586c683e0814f171991 (diff)
downloadoslo-serialization-a9ed13380c948f3c8372e8aba244e1b030b9fe06.tar.gz
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
-rw-r--r--tests/unit/test_jsonutils.py15
1 files changed, 4 insertions, 11 deletions
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):