Author: phd
Date: 2006-05-02 08:50:05 -0600 (Tue, 02 May 2006)
New Revision: 1748
Modified:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py
Log:
Merged patches from the revisions 1745:1747 from the trunk: a patch by Konrad Zielinski <kzi...@gm...> - test all required keywords before creating parent object(s).
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2006-05-02 14:49:00 UTC (rev 1747)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2006-05-02 14:50:05 UTC (rev 1748)
@@ -293,6 +293,14 @@
else:
new_kw[name] = value
kw = new_kw
+
+ # Need to check that we have enough data to sucesfully
+ # create the current subclass otherwise we will leave
+ # the database in an inconsistent state.
+ for col in self.sqlmeta.columnList:
+ if col._default == sqlbuilder.NoDefault and col.name not in kw:
+ raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, col.name)
+
parent_kw['childName'] = self.sqlmeta.childName
self._parent = parentClass(kw=parent_kw,
connection=self._connection)
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py 2006-05-02 14:49:00 UTC (rev 1747)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py 2006-05-02 14:50:05 UTC (rev 1748)
@@ -1,3 +1,4 @@
+from py.test import raises
from sqlobject import *
from sqlobject.tests.dbtest import *
from sqlobject.inheritance import InheritableSQLObject
@@ -6,7 +7,6 @@
## Deep Inheritance
########################################
-
class DIPerson(InheritableSQLObject):
firstName = StringCol()
lastName = StringCol(alternateID=True, length=255)
@@ -18,6 +18,24 @@
class DIManager(DIEmployee):
subdudes = MultipleJoin("DIPerson", joinColumn="manager_id")
+def test_creation_fail():
+ """
+ Try to creae an Manager without specifying a position.
+ this should fail without leaving any partial records in
+ the database.
+ """
+
+ setupClass(DIManager)
+ setupClass(DIEmployee)
+ setupClass(DIPerson)
+
+ kwargs ={'firstName':'John', 'lastname':'Doe'}
+ raises(TypeError, DIManager, **kwargs)
+ #what we really need to check for is partial records in the database.
+ #the following is not really adaquate.
+ persons = DIEmployee.select(DIPerson.q.firstName == 'John')
+ assert persons.count() == 0
+
def test_deep_inheritance():
cache = getConnection().cache
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py 2006-05-02 14:49:00 UTC (rev 1747)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py 2006-05-02 14:50:05 UTC (rev 1748)
@@ -1,3 +1,4 @@
+from py.test import raises
from sqlobject import *
from sqlobject.tests.dbtest import *
from sqlobject.inheritance import InheritableSQLObject
@@ -6,7 +7,6 @@
## Inheritance
########################################
-
class InheritablePerson(InheritableSQLObject):
firstName = StringCol()
lastName = StringCol(alternateID=True, length=255)
@@ -22,6 +22,12 @@
Employee(firstName='Project', lastName='Leader', position='Project leader')
InheritablePerson(firstName='Oneof', lastName='Authors')
+def test_creation_fail():
+ setup()
+ kwargs ={'firstName':'John', 'lastname':'Doe'}
+ raises(TypeError, Employee, **kwargs)
+ persons = InheritablePerson.select(InheritablePerson.q.firstName == 'John')
+ assert persons.count() == 0
def test_inheritance():
setup()
@@ -35,7 +41,6 @@
assert hasattr(person, "childName")
assert not person.childName
-
def test_inheritance_select():
setup()
|