[SQL-CVS] r2007 - in SQLObject/trunk/sqlobject: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-10-11 14:43:14
|
Author: phd Date: 2006-10-11 08:43:12 -0600 (Wed, 11 Oct 2006) New Revision: 2007 Modified: SQLObject/trunk/sqlobject/col.py SQLObject/trunk/sqlobject/tests/test_enum.py Log: Applied patches for the bug 1496014: None in enumValues fails. Additional tests by Nathan Edwards <ned...@um...>. Modified: SQLObject/trunk/sqlobject/col.py =================================================================== --- SQLObject/trunk/sqlobject/col.py 2006-10-11 14:42:35 UTC (rev 2006) +++ SQLObject/trunk/sqlobject/col.py 2006-10-11 14:43:12 UTC (rev 2007) @@ -882,7 +882,12 @@ super(SOEnumCol, self).createValidators() def _mysqlType(self): - return "ENUM(%s)" % ', '.join([sqlbuilder.sqlrepr(v, 'mysql') for v in self.enumValues]) + # We need to map None in the enum expression to an appropriate + # condition on NULL + if None in self.enumValues: + return "ENUM(%s)" % ', '.join([sqlbuilder.sqlrepr(v, 'mysql') for v in self.enumValues if v is not None]) + else: + return "ENUM(%s) NOT NULL" % ', '.join([sqlbuilder.sqlrepr(v, 'mysql') for v in self.enumValues]) def _postgresType(self): length = max(map(self._getlength, self.enumValues)) Modified: SQLObject/trunk/sqlobject/tests/test_enum.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_enum.py 2006-10-11 14:42:35 UTC (rev 2006) +++ SQLObject/trunk/sqlobject/tests/test_enum.py 2006-10-11 14:43:12 UTC (rev 2007) @@ -27,5 +27,25 @@ def testNone(): setupClass(EnumWithNone) for l in [None, 'a', 'bcd', 'a', 'e', None]: - EnumWithNone(l=l) - + e = EnumWithNone(l=l) + assert e.l == l + +class EnumWithDefaultNone(SQLObject): + + l = EnumCol(enumValues=['a', 'bcd', 'e', None], default=None) + +def testDefaultNone(): + setupClass(EnumWithDefaultNone) + + e = EnumWithDefaultNone() + assert e.l == None + +class EnumWithDefaultOther(SQLObject): + + l = EnumCol(enumValues=['a', 'bcd', 'e', None], default='a') + +def testDefaultOther(): + setupClass(EnumWithDefaultOther) + + e = EnumWithDefaultOther() + assert e.l == 'a' |