Пример #1
0
    def test_list_assignment(self):
        sess = create_session()
        u = User(name='jack', orders=[Order(description='someorder'), Order(description='someotherorder')])
        sess.save(u)
        sess.flush()
        sess.clear()
        
        u = sess.query(User).get(u.id)
        self.assertEquals(u, User(name='jack', orders=[Order(description='someorder'), Order(description='someotherorder')]))
        
        u.orders=[Order(description="order 3"), Order(description="order 4")]
        sess.flush()
        sess.clear()
        
        u = sess.query(User).get(u.id)
        self.assertEquals(u, User(name='jack', orders=[Order(description="order 3"), Order(description="order 4")]))

        self.assertEquals(sess.query(Order).all(), [Order(description="order 3"), Order(description="order 4")])
        o5 = Order(description="order 5")
        sess.save(o5)
        try:
            sess.flush()
            assert False
        except exceptions.FlushError, e:
            assert "is an orphan" in str(e)
Пример #2
0
 def test_pending_expunge(self):
     sess = create_session()
     someuser = User(name='someuser')
     sess.save(someuser)
     sess.flush()
     someuser.pref = p1 = Pref(data='somepref')
     assert p1 in sess
     someuser.pref = Pref(data='someotherpref')
     assert p1 not in sess
     sess.flush()
     self.assertEquals(sess.query(Pref).with_parent(someuser).all(), [Pref(data="someotherpref")])
Пример #3
0
    def test_collection_orphans(self):
        sess = create_session()
        u = User(name='jack', orders=[Order(description='someorder'), Order(description='someotherorder')])
        sess.save(u)
        sess.flush()

        assert users.count().scalar() == 1
        assert orders.count().scalar() == 2

        u.orders[:] = []

        sess.flush()

        assert users.count().scalar() == 1
        assert orders.count().scalar() == 0