[entities] fix dc_title output for bool(value) == False
authorAurelien Campeas <aurelien.campeas@pythonian.fr>
Wed, 15 Apr 2015 22:48:20 +0200
changeset 10396 33e44293b0eb
parent 10395 7e311ee8b5b0
child 10397 1ce4594f9cf4
[entities] fix dc_title output for bool(value) == False Closes #5194853.
entities/__init__.py
entities/test/data/schema.py
entities/test/unittest_base.py
--- a/entities/__init__.py	Fri May 15 18:06:03 2015 +0200
+++ b/entities/__init__.py	Wed Apr 15 22:48:20 2015 +0200
@@ -68,7 +68,7 @@
             if rschema.meta:
                 continue
             value = self.cw_attr_value(rschema.type)
-            if value:
+            if value is not None:
                 # make the value printable (dates, floats, bytes, etc.)
                 return self.printable_value(rschema.type, value, attrschema.type,
                                             format='text/plain')
--- a/entities/test/data/schema.py	Fri May 15 18:06:03 2015 +0200
+++ b/entities/test/data/schema.py	Wed Apr 15 22:48:20 2015 +0200
@@ -17,10 +17,11 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """entities tests schema"""
 
-from yams.buildobjs import EntityType, String, RichString
+from yams.buildobjs import EntityType, String, RichString, Int
 from cubicweb.schema import make_workflowable
 
 class Company(EntityType):
+    order = Int()
     name = String()
     description = RichString()
 
--- a/entities/test/unittest_base.py	Fri May 15 18:06:03 2015 +0200
+++ b/entities/test/unittest_base.py	Wed Apr 15 22:48:20 2015 +0200
@@ -137,6 +137,12 @@
             self.assertEqual(e.dc_title(), 'member')
             self.assertEqual(e.name(), u'bouah lôt')
 
+    def test_falsey_dc_title(self):
+        with self.admin_access.repo_cnx() as cnx:
+            e = cnx.create_entity('Company', order=0, name=u'pythonian')
+            cnx.commit()
+            self.assertEqual(u'0', e.dc_title())
+
     def test_allowed_massmail_keys(self):
         with self.admin_access.repo_cnx() as cnx:
             e = cnx.execute('CWUser U WHERE U login "member"').get_entity(0, 0)