Thread: [SQL-CVS] r1746 - in SQLObject/trunk/sqlobject/inheritance: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-05-02 14:46:30
|
Author: phd Date: 2006-05-02 08:46:23 -0600 (Tue, 02 May 2006) New Revision: 1746 Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py Log: A patch by Konrad Zielinski <kzi...@gm...> - test all required keywords before creating parent object(s). Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py =================================================================== --- SQLObject/trunk/sqlobject/inheritance/__init__.py 2006-05-01 21:35:45 UTC (rev 1745) +++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2006-05-02 14:46:23 UTC (rev 1746) @@ -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: SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py =================================================================== --- SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py 2006-05-01 21:35:45 UTC (rev 1745) +++ SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py 2006-05-02 14:46:23 UTC (rev 1746) @@ -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: SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py =================================================================== --- SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py 2006-05-01 21:35:45 UTC (rev 1745) +++ SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py 2006-05-02 14:46:23 UTC (rev 1746) @@ -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() |