[SQL-CVS] r104 - in trunk/SQLObject: sqlobject tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2004-04-23 22:02:09
|
Author: ianb Date: 2004-04-23 14:04:25 -0400 (Fri, 23 Apr 2004) New Revision: 104 Modified: trunk/SQLObject/sqlobject/main.py trunk/SQLObject/tests/test.py Log: Fixed bug related to orderBy=3D'-column_name' Modified: trunk/SQLObject/sqlobject/main.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/sqlobject/main.py 2004-04-14 16:38:33 UTC (rev 103) +++ trunk/SQLObject/sqlobject/main.py 2004-04-23 18:04:25 UTC (rev 104) @@ -1095,6 +1095,7 @@ orderBy =3D map(self._mungeOrderBy, orderBy) else: orderBy =3D self._mungeOrderBy(orderBy) + print "OUT: %r; in: %r" % (sourceClass.sqlrepr(orderBy), sourceC= lass.sqlrepr(self.ops['orderBy'])) self.ops['dbOrderBy'] =3D orderBy if ops.has_key('connection') and ops['connection'] is None: del ops['connection'] @@ -1105,17 +1106,20 @@ desc =3D True else: desc =3D False - if self.sourceClass._SO_columnDict.has_key(orderBy): - val =3D self.sourceClass._SO_columnDict[orderBy].dbName - if desc: - return '-' + val + if isinstance(orderBy, (str, unicode)): + if self.sourceClass._SO_columnDict.has_key(orderBy): + val =3D self.sourceClass._SO_columnDict[orderBy].dbName + if desc: + return '-' + val + else: + return val else: - return val + if desc: + return '-' + orderBy + else: + return orderBy else: - if desc: - return sqlbuilder.DESC(orderBy) - else: - return orderBy + return orderBy =20 def clone(self, **newOps): ops =3D self.ops.copy() Modified: trunk/SQLObject/tests/test.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/tests/test.py 2004-04-14 16:38:33 UTC (rev 103) +++ trunk/SQLObject/tests/test.py 2004-04-23 18:04:25 UTC (rev 104) @@ -259,33 +259,56 @@ =20 _table =3D 'names_table' =20 - fname =3D StringCol(length=3D30) - lname =3D StringCol(length=3D30) + firstName =3D StringCol(length=3D30) + lastName =3D StringCol(length=3D30) =20 - _defaultOrder =3D ['lname', 'fname'] + _defaultOrder =3D ['lastName', 'firstName'] =20 class NamesTest(SQLObjectTest): =20 classes =3D [Names] =20 def inserts(self): - for fname, lname in [('aj', 'baker'), ('joe', 'robbins'), - ('tim', 'jackson'), ('joe', 'baker'), - ('zoe', 'robbins')]: - Names(fname=3Dfname, lname=3Dlname) + for firstName, lastName in [('aj', 'baker'), ('joe', 'robbins'), + ('tim', 'jackson'), ('joe', 'baker')= , + ('zoe', 'robbins')]: + Names(firstName=3DfirstName, lastName=3DlastName) =20 def testDefaultOrder(self): - self.assertEqual([(n.fname, n.lname) for n in Names.select()], + self.assertEqual([(n.firstName, n.lastName) for n in Names.selec= t()], [('aj', 'baker'), ('joe', 'baker'), ('tim', 'jackson'), ('joe', 'robbins'), ('zoe', 'robbins')]) =20 def testOtherOrder(self): - self.assertEqual([(n.fname, n.lname) for n in Names.select().ord= erBy(['fname', 'lname'])], + self.assertEqual([(n.firstName, n.lastName) for n in Names.selec= t().orderBy(['firstName', 'lastName'])], [('aj', 'baker'), ('joe', 'baker'), ('joe', 'robbins'), ('tim', 'jackson'), ('zoe', 'robbins')]) =20 + def testUntranslatedColumnOrder(self): + self.assertEqual([(n.firstName, n.lastName) for n in Names.selec= t().orderBy(['first_name', 'last_name'])], + [('aj', 'baker'), ('joe', 'baker'), + ('joe', 'robbins'), ('tim', 'jackson'), + ('zoe', 'robbins')]) + + def testSingleUntranslatedColumnOrder(self): + self.assertEqual([n.firstName for n in + Names.select().orderBy('firstName')], + ['aj', 'joe', 'joe', 'tim', 'zoe']) + self.assertEqual([n.firstName for n in + Names.select().orderBy('first_name')], + ['aj', 'joe', 'joe', 'tim', 'zoe']) + self.assertEqual([n.firstName for n in + Names.select().orderBy('-firstName')], + ['zoe', 'tim', 'joe', 'joe', 'aj']) + self.assertEqual([n.firstName for n in + Names.select().orderBy('-first_name')], + ['zoe', 'tim', 'joe', 'joe', 'aj']) + self.assertEqual([n.firstName for n in + Names.select().orderBy(Names.q.firstName)], + ['aj', 'joe', 'joe', 'tim', 'zoe']) + ######################################## ## Select results ######################################## |