diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-18 16:00:49 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-18 16:13:34 -0400 |
| commit | 1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc (patch) | |
| tree | d8ebd70b0632b5ac78ef3f93130b8a92c7b16206 | |
| parent | d5f2152dcfc4039de8324bdf75f6a2cd844dbdd0 (diff) | |
| download | oslo-1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc.tar.gz oslo-1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc.tar.xz oslo-1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc.zip | |
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.py | 15 |
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): |
