Author: phd
Date: 2007-03-14 10:41:05 -0600 (Wed, 14 Mar 2007)
New Revision: 2411
Added:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_indexes.py
Removed:
home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py
Modified:
home/phd/SQLObject/paramstyles/sqlobject/index.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_indexes.py
Log:
Merged patches from the revisions 2406:2410 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/index.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/index.py 2007-03-14 16:19:05 UTC (rev 2410)
+++ home/phd/SQLObject/paramstyles/sqlobject/index.py 2007-03-14 16:41:05 UTC (rev 2411)
@@ -23,19 +23,18 @@
raise TypeError, "You cannot mix named and unnamed arguments"
columns = [d['column'] for d in self.descriptions
if d.has_key('column')]
- if kw:
- args = []
- for i in xrange(len(columns)):
- args.append(kw[columns[i].name])
- del kw[columns[i].name]
- if kw or len(args) != len(columns):
+ if kw and len(kw) != len(columns) or args and len(args) != len(columns):
raise TypeError, ("get() takes exactly %d argument and an optional "
"named argument 'connection' (%d given)" % (
len(columns), len(args)+len(kw)))
- cols = [c.name for c in columns]
- dbcols = [c.dbName for c in columns]
- return self.soClass._SO_fetchAlternateID(cols, dbcols, args,
- connection=connection, idxName=self.name)
+ if args:
+ kw = {}
+ for i in range(len(args)):
+ if columns[i].foreignName is not None:
+ kw[columns[i].foreignName] = args[i]
+ else:
+ kw[columns[i].name] = args[i]
+ return self.soClass.selectBy(connection=connection, **kw).getOne()
def convertColumns(self, columns):
"""
Copied: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_indexes.py (from rev 2410, SQLObject/trunk/sqlobject/inheritance/tests/test_indexes.py)
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_indexes.py (rev 0)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_indexes.py 2007-03-14 16:41:05 UTC (rev 2411)
@@ -0,0 +1,40 @@
+from sqlobject import *
+from sqlobject.tests.dbtest import *
+from sqlobject.inheritance import InheritableSQLObject
+
+
+class InheritedPersonIndexGet(InheritableSQLObject):
+ first_name = StringCol(notNone=True)
+ last_name = StringCol(notNone=True)
+ age = IntCol()
+ pk = DatabaseIndex(first_name, last_name, unique=True)
+
+class InheritedEmployeeIndexGet(InheritedPersonIndexGet):
+ security_number = IntCol()
+ experience = IntCol()
+ sec_index = DatabaseIndex(security_number, unique=True)
+
+class InheritedSalesManIndexGet(InheritedEmployeeIndexGet):
+ _inheritable = False
+ skill = IntCol()
+
+
+def test_index_get_1():
+ setupClass([InheritedPersonIndexGet, InheritedEmployeeIndexGet, InheritedSalesManIndexGet])
+
+ InheritedSalesManIndexGet(first_name='Michael', last_name='Pallin', age=65, security_number=2304,
+ experience=2, skill=10)
+ InheritedEmployeeIndexGet(first_name='Eric', last_name='Idle', age=63, security_number=3402,
+ experience=9)
+ InheritedPersonIndexGet(first_name='Terry', last_name='Guilliam', age=64)
+
+ InheritedPersonIndexGet.pk.get('Michael', 'Pallin')
+ InheritedEmployeeIndexGet.pk.get('Michael', 'Pallin')
+ InheritedSalesManIndexGet.pk.get('Michael', 'Pallin')
+ InheritedPersonIndexGet.pk.get('Eric', 'Idle')
+ InheritedEmployeeIndexGet.pk.get('Eric', 'Idle')
+ InheritedPersonIndexGet.pk.get(first_name='Terry', last_name='Guilliam')
+ InheritedEmployeeIndexGet.sec_index.get(2304)
+ InheritedEmployeeIndexGet.sec_index.get(3402)
+ InheritedSalesManIndexGet.sec_index.get(2304)
+ InheritedSalesManIndexGet.sec_index.get(3402)
Deleted: home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py 2007-03-14 16:19:05 UTC (rev 2410)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py 2007-03-14 16:41:05 UTC (rev 2411)
@@ -1,47 +0,0 @@
-from sqlobject import *
-from sqlobject.tests.dbtest import *
-
-class PersonIndexGet(SQLObject):
- firstName = StringCol()
- lastName = StringCol()
- age = IntCol(alternateID=True)
- nameIndex = DatabaseIndex(firstName, lastName, unique=True)
-
-def test_1():
- setupClass(PersonIndexGet, force=True)
-
- PersonIndexGet(firstName='Eric', lastName='Idle', age=62)
- PersonIndexGet(firstName='Terry', lastName='Gilliam', age=65)
- PersonIndexGet(firstName='John', lastName='Cleese', age=66)
-
- PersonIndexGet.get(1)
- PersonIndexGet.nameIndex.get('Terry', 'Gilliam')
- PersonIndexGet.nameIndex.get(firstName='John', lastName='Cleese')
-
- try:
- print PersonIndexGet.nameIndex.get(firstName='Graham', lastName='Chapman')
- except Exception, e:
- pass
- else:
- raise AssertError
-
- try:
- print PersonIndexGet.nameIndex.get('Terry', lastName='Gilliam')
- except Exception, e:
- pass
- else:
- raise AssertError
-
- try:
- print PersonIndexGet.nameIndex.get('Terry', 'Gilliam', 65)
- except Exception, e:
- pass
- else:
- raise AssertError
-
- try:
- print PersonIndexGet.nameIndex.get('Terry')
- except Exception, e:
- pass
- else:
- raise AssertError
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_indexes.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_indexes.py 2007-03-14 16:19:05 UTC (rev 2410)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_indexes.py 2007-03-14 16:41:05 UTC (rev 2411)
@@ -14,14 +14,11 @@
nameIndex2 = DatabaseIndex(name, number)
nameIndex3 = DatabaseIndex({'column': name,
'length': 3})
-
class SOIndex2(SQLObject):
-
name = StringCol()
-
nameIndex = DatabaseIndex({'expression': 'lower(name)'})
-def test_1():
+def test_indexes_1():
setupClass(SOIndex1)
n = 0
for name in 'blah blech boring yep yort snort'.split():
@@ -39,8 +36,76 @@
else:
assert 0, "Exception expected."
-def test_2():
+def test_indexes_2():
if not supports('expressionIndex'):
return
setupClass(SOIndex2)
SOIndex2(name='')
+
+
+class PersonIndexGet(SQLObject):
+ firstName = StringCol()
+ lastName = StringCol()
+ age = IntCol(alternateID=True)
+ nameIndex = DatabaseIndex(firstName, lastName, unique=True)
+
+def test_index_get_1():
+ setupClass(PersonIndexGet, force=True)
+
+ PersonIndexGet(firstName='Eric', lastName='Idle', age=62)
+ PersonIndexGet(firstName='Terry', lastName='Gilliam', age=65)
+ PersonIndexGet(firstName='John', lastName='Cleese', age=66)
+
+ PersonIndexGet.get(1)
+ PersonIndexGet.nameIndex.get('Terry', 'Gilliam')
+ PersonIndexGet.nameIndex.get(firstName='John', lastName='Cleese')
+
+ try:
+ print PersonIndexGet.nameIndex.get(firstName='Graham', lastName='Chapman')
+ except Exception, e:
+ pass
+ else:
+ raise AssertError
+
+ try:
+ print PersonIndexGet.nameIndex.get('Terry', lastName='Gilliam')
+ except Exception, e:
+ pass
+ else:
+ raise AssertError
+
+ try:
+ print PersonIndexGet.nameIndex.get('Terry', 'Gilliam', 65)
+ except Exception, e:
+ pass
+ else:
+ raise AssertError
+
+ try:
+ print PersonIndexGet.nameIndex.get('Terry')
+ except Exception, e:
+ pass
+ else:
+ raise AssertError
+
+
+class PersonIndexGet2(SQLObject):
+ name = StringCol(alternateID=True)
+ age = IntCol()
+ addresses = MultipleJoin('AddressIndexGet2')
+
+class AddressIndexGet2(SQLObject):
+ person = ForeignKey('PersonIndexGet2', notNone=True)
+ type = StringCol(notNone=True)
+ street = StringCol(notNone=True)
+ pk = DatabaseIndex(person, type, unique=True)
+
+def test_index_get_2():
+ setupClass([PersonIndexGet2, AddressIndexGet2])
+
+ p = PersonIndexGet2(name='Terry Guilliam', age=64)
+ AddressIndexGet2(person=p, type='home', street='Terry Street 234')
+ AddressIndexGet2(person=p, type='work', street='Guilliam Street 234')
+
+ AddressIndexGet2.pk.get(p, 'work')
+ AddressIndexGet2.pk.get(person=p, type='work')
|