~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/orm/test_unitofwork.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# coding: utf-8
2
2
"""Tests unitofwork operations."""
3
3
 
4
 
from test.lib.testing import eq_, assert_raises, assert_raises_message
 
4
from sqlalchemy.testing import eq_, assert_raises, assert_raises_message
5
5
import datetime
6
 
import operator
7
6
from sqlalchemy.orm import mapper as orm_mapper
8
7
 
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
22
 
import gc
 
18
from sqlalchemy.testing.assertsql import AllOf, CompiledSQL
23
19
 
24
20
class UnitOfWorkTest(object):
25
21
    pass
620
616
 
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
623
620
 
 
621
        mapper(MyClass, mytable, properties={
 
622
            'foo': relationship(MyOtherClass,
 
623
                                    passive_deletes='all',
 
624
                                    cascade="all")
 
625
            })
624
626
        mapper(MyOtherClass, myothertable)
 
627
 
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',
631
 
                                    cascade="all"
 
632
            sa.orm.configure_mappers
632
633
        )
633
634
 
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)
1625
1627
            session.add(a)
1626
1628
 
1627
1629
        session.flush()
1628
 
 
1629
1630
        objects[2].email_address = 'imnew@foo.bar'
1630
1631
        objects[3].user = User()
1631
1632
        objects[3].user.name = 'imnewlyadded'
2466
2467
        t1 = s.query(T1).first()
2467
2468
        t1.col2 = 5
2468
2469
        assert_raises_message(
2469
 
            sa.exc.FlushError,
 
2470
            orm_exc.FlushError,
2470
2471
            "Can't update table using NULL for primary key value",
2471
2472
            s.commit
2472
2473
        )
2479
2480
        t1 = s.query(T1).first()
2480
2481
        t1.col3 = 'hi'
2481
2482
        assert_raises_message(
2482
 
            sa.exc.FlushError,
 
2483
            orm_exc.FlushError,
2483
2484
            "Can't update table using NULL for primary key value",
2484
2485
            s.commit
2485
2486
        )
2492
2493
        t1 = s.query(T1).first()
2493
2494
        s.delete(t1)
2494
2495
        assert_raises_message(
2495
 
            sa.exc.FlushError,
 
2496
            orm_exc.FlushError,
2496
2497
            "Can't delete from table using NULL for primary key value",
2497
2498
            s.commit
2498
2499
        )
2502
2503
        s = Session()
2503
2504
        s.add(T1(col1=None, col2=None))
2504
2505
        assert_raises_message(
2505
 
            sa.exc.FlushError,
 
2506
            orm_exc.FlushError,
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 ",