2
2
"""Tests unitofwork operations."""
4
from test.lib.testing import eq_, assert_raises, assert_raises_message
4
from sqlalchemy.testing import eq_, assert_raises, assert_raises_message
7
6
from sqlalchemy.orm import mapper as orm_mapper
9
8
import sqlalchemy as sa
10
9
from sqlalchemy import Integer, String, ForeignKey, literal_column, event
11
from test.lib import engines, testing, pickleable
12
from test.lib.schema import Table
13
from test.lib.schema import Column
10
from sqlalchemy.testing import engines
11
from sqlalchemy import testing
12
from sqlalchemy.testing.schema import Table
13
from sqlalchemy.testing.schema import Column
14
14
from sqlalchemy.orm import mapper, relationship, create_session, \
15
column_property, attributes, Session, reconstructor, object_session
16
from test.lib.testing import eq_, ne_
17
from test.lib.util import gc_collect
18
from test.lib import fixtures
15
column_property, Session, exc as orm_exc
16
from sqlalchemy.testing import fixtures
19
17
from test.orm import _fixtures
20
from test.lib import fixtures
21
from test.lib.assertsql import AllOf, CompiledSQL
18
from sqlalchemy.testing.assertsql import AllOf, CompiledSQL
24
20
class UnitOfWorkTest(object):
621
617
def test_assertions(self):
622
618
myothertable, MyOtherClass = self.tables.myothertable, self.classes.MyOtherClass
619
mytable, MyClass = self.tables.mytable, self.classes.MyClass
621
mapper(MyClass, mytable, properties={
622
'foo': relationship(MyOtherClass,
623
passive_deletes='all',
624
626
mapper(MyOtherClass, myothertable)
625
628
assert_raises_message(
626
629
sa.exc.ArgumentError,
627
"Can't set passive_deletes='all' in conjunction with 'delete' "
630
"On MyClass.foo, can't set passive_deletes='all' in conjunction with 'delete' "
628
631
"or 'delete-orphan' cascade",
629
relationship, MyOtherClass,
630
passive_deletes='all',
632
sa.orm.configure_mappers
634
635
def test_extra_passive(self):
635
myothertable, MyClass, MyOtherClass, mytable = (self.tables.myothertable,
636
myothertable, MyClass, MyOtherClass, mytable = (
637
self.tables.myothertable,
636
638
self.classes.MyClass,
637
639
self.classes.MyOtherClass,
638
640
self.tables.mytable)
2503
2504
s.add(T1(col1=None, col2=None))
2504
2505
assert_raises_message(
2506
2507
r"Instance \<T1 at .+?\> has a NULL "
2507
2508
"identity key. If this is an auto-generated value, "
2508
2509
"check that the database table allows generation ",