本文整理汇总了Python中camelot.core.orm.Session.expunge_all方法的典型用法代码示例。如果您正苦于以下问题:Python Session.expunge_all方法的具体用法?Python Session.expunge_all怎么用?Python Session.expunge_all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类camelot.core.orm.Session
的用法示例。
在下文中一共展示了Session.expunge_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_refresh
# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import expunge_all [as 别名]
def test_refresh( self ):
from camelot.core.orm import Session
from camelot.model.party import Person
refresh_action = application_action.Refresh()
session = Session()
session.expunge_all()
# create objects in various states
#
p1 = Person(first_name = u'p1', last_name = u'persistent' )
p2 = Person(first_name = u'p2', last_name = u'dirty' )
p3 = Person(first_name = u'p3', last_name = u'deleted' )
p4 = Person(first_name = u'p4', last_name = u'to be deleted' )
p5 = Person(first_name = u'p5', last_name = u'detached' )
p6 = Person(first_name = u'p6', last_name = u'deleted outside session' )
session.flush()
p3.delete()
session.flush()
p4.delete()
p2.last_name = u'clean'
#
# delete p6 without the session being aware
#
person_table = Person.table
session.execute( person_table.delete().where( person_table.c.party_id == p6.id ) )
#
# refresh the session through the action
#
list( refresh_action.model_run( self.context ) )
self.assertEqual( p2.last_name, u'dirty' )
示例2: PartyCase
# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import expunge_all [as 别名]
class PartyCase( ModelThreadTestCase ):
"""Test the build in party - address - contact mechanism model"""
def setUp(self):
super( PartyCase, self ).setUp()
from camelot.admin.application_admin import ApplicationAdmin
self.session = Session()
self.app_admin = ApplicationAdmin()
self.person_admin = self.app_admin.get_related_admin( party.Person )
self.organization_admin = self.app_admin.get_related_admin( party.Organization )
def tearDown(self):
self.session.expunge_all()
def test_party( self ):
p = party.Party()
self.assertFalse( p.name )
def test_geographic_boundary( self ):
belgium = party.Country.get_or_create( code = u'BE',
name = u'Belgium' )
self.assertTrue( unicode( belgium ) )
city = party.City.get_or_create( country = belgium,
code = '1000',
name = 'Brussels' )
return city
def test_address( self ):
city = self.test_geographic_boundary()
address = party.Address.get_or_create( street1 = 'Avenue Louise',
street2 = None,
city = city )
self.assertTrue( unicode( address ) )
return address
def test_party_address( self ):
city = self.test_geographic_boundary()
org = party.Organization( name = 'PSF' )
party_address = party.PartyAddress( party = org )
party_address.street1 = 'Avenue Louise 5'
party_address.street2 = 'Boite 4'
party_address.city = city
party_address_admin = party.AddressAdmin( self.app_admin, party.PartyAddress )
self.assertTrue( party_address.address in party_address_admin.get_compounding_objects( party_address ) )
self.assertTrue( party_address.address in self.session.new )
# everything should be flushed through the party admin
org_admin = self.app_admin.get_related_admin( party.Organization )
org_validator = org_admin.get_validator()
self.assertTrue( party_address in org_admin.get_compounding_objects( org ) )
org_admin.flush( org )
self.assertFalse( party_address.address in self.session.new )
party_address_admin.refresh( party_address )
# test hybrid property getters on Party and PartyAddress
self.assertEqual( party_address.street1, 'Avenue Louise 5' )
self.assertEqual( party_address.street2, 'Boite 4' )
self.assertEqual( party_address.city, city )
self.assertEqual( org.street1, 'Avenue Louise 5' )
self.assertEqual( org.street2, 'Boite 4' )
self.assertEqual( org.city, city )
self.assertTrue( unicode( party_address ) )
query = self.session.query( party.PartyAddress )
self.assertTrue( query.filter( party.PartyAddress.street1 == 'Avenue Louise 5' ).first() )
self.assertTrue( query.filter( party.PartyAddress.street2 == 'Boite 4' ).first() )
# if party address changes, party should be updated
depending_objects = list( party_address_admin.get_depending_objects( party_address ) )
self.assertTrue( org in depending_objects )
# if address changes, party address and party should be updated
address = party_address.address
address_admin = self.app_admin.get_related_admin( party.Address )
depending_objects = list( address_admin.get_depending_objects( address ) )
self.assertTrue( party_address in depending_objects )
self.assertTrue( org in depending_objects )
# test hybrid property setters on Party
org.street1 = 'Rue Belliard 1'
org.street2 = 'Second floor'
org.city = None
# expunge should expunge the related address objects as well, so
# after an expunge, the session as a whole can be flushed
org_admin.expunge( org )
self.session.flush()
# test hybrid property setters on a new party
org = party.Organization( name = 'PSF' )
org.street1 = 'Rue Belliard 1'
org.street2 = 'Second floor'
org.city = city
org_admin.flush( org )
self.assertEqual( len( org.addresses ), 1 )
self.assertEqual( org.street1, 'Rue Belliard 1' )
self.assertEqual( org.street2, 'Second floor' )
self.assertEqual( org.city, city )
# test invalidation of org object and refresh it
self.assertFalse( org_validator.validate_object( org ) )
org.city = None
self.assertTrue( org_validator.validate_object( org ) )
org_admin.refresh( org )
self.assertFalse( org_validator.validate_object( org ) )
# removing all the address properties should make the
# object valid again
org.street1 = None
org.street2 = None
#.........这里部分代码省略.........