pyramid/bodhi/bodhi/models/models.py | 3 ++-
pyramid/bodhi/bodhi/tests/models/__init__.py | 11 ++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
New commits:
commit e1fd8ee21eff5532e5ae63dc2beaa2f4896edd82
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 10:33:46 2011 -0400
Add a test_json method to each model test, and fix a bug that it found
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index ea52a10..df1036f 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -47,7 +47,8 @@ class BodhiBase(object):
continue
prop = getattr(self, col.name)
if isinstance(prop, list):
- prop = [child.__json__() for child in prop]
+ prop = [child.__json__() for child in prop
+ if hasattr(child, '__json__')]
elif hasattr(prop, '__json__'):
prop = prop.__json__()
elif isinstance(prop, datetime):
diff --git a/pyramid/bodhi/bodhi/tests/models/__init__.py
b/pyramid/bodhi/bodhi/tests/models/__init__.py
index e99caaa..2a40c9a 100644
--- a/pyramid/bodhi/bodhi/tests/models/__init__.py
+++ b/pyramid/bodhi/bodhi/tests/models/__init__.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""Unit test suite for the models of the application."""
-from nose.tools import assert_equals
+import json
+
+from nose.tools import assert_equals, eq_
from bodhi.models import DBSession
from bodhi.tests import setup_db, teardown_db
@@ -44,6 +46,9 @@ class ModelTest(object):
pass
def test_query_obj(self):
- obj = DBSession.query(self.klass).one()
for key, value in self.attrs.iteritems():
- assert_equals(getattr(obj, key), value)
+ assert_equals(getattr(self.obj, key), value)
+
+ def test_json(self):
+ """ Ensure our models can return valid JSON """
+ assert json.dumps(self.obj.__json__())
Show replies by date