本文整理汇总了Python中mediagoblin.db.base.Session.flush方法的典型用法代码示例。如果您正苦于以下问题:Python Session.flush方法的具体用法?Python Session.flush怎么用?Python Session.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediagoblin.db.base.Session
的用法示例。
在下文中一共展示了Session.flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_deletes_other_comments
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import flush [as 别名]
def test_user_deletes_other_comments(test_app):
user_a = fixture_add_user(u"chris_a")
user_b = fixture_add_user(u"chris_b")
media_a = fixture_media_entry(uploader=user_a.id, save=False,
expunge=False, fake_upload=False)
media_b = fixture_media_entry(uploader=user_b.id, save=False,
expunge=False, fake_upload=False)
Session.add(media_a)
Session.add(media_b)
Session.flush()
# Create all 4 possible comments:
for u_id in (user_a.id, user_b.id):
for m_id in (media_a.id, media_b.id):
cmt = MediaComment()
cmt.media_entry = m_id
cmt.author = u_id
cmt.content = u"Some Comment"
Session.add(cmt)
Session.flush()
usr_cnt1 = User.query.count()
med_cnt1 = MediaEntry.query.count()
cmt_cnt1 = MediaComment.query.count()
User.query.get(user_a.id).delete(commit=False)
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
cmt_cnt2 = MediaComment.query.count()
# One user deleted
assert usr_cnt2 == usr_cnt1 - 1
# One media gone
assert med_cnt2 == med_cnt1 - 1
# Three of four comments gone.
assert cmt_cnt2 == cmt_cnt1 - 3
User.query.get(user_b.id).delete()
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
cmt_cnt2 = MediaComment.query.count()
# All users gone
assert usr_cnt2 == usr_cnt1 - 2
# All media gone
assert med_cnt2 == med_cnt1 - 2
# All comments gone
assert cmt_cnt2 == cmt_cnt1 - 4
示例2: test_media_deletes_broken_attachment
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import flush [as 别名]
def test_media_deletes_broken_attachment(test_app):
user_a = fixture_add_user(u"chris_a")
media = fixture_media_entry(uploader=user_a.id, save=False)
media.attachment_files.append(dict(
name=u"some name",
filepath=[u"does", u"not", u"exist"],
))
Session.add(media)
Session.flush()
MediaEntry.query.get(media.id).delete()
User.query.get(user_a.id).delete()
示例3: test_user_deletes_other_comments
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import flush [as 别名]
def test_user_deletes_other_comments(test_app):
user_a = fixture_add_user(u"chris_a")
user_b = fixture_add_user(u"chris_b")
media_a = fixture_media_entry(uploader=user_a.id, save=False,
expunge=False, fake_upload=False)
media_b = fixture_media_entry(uploader=user_b.id, save=False,
expunge=False, fake_upload=False)
Session.add(media_a)
Session.add(media_b)
Session.flush()
# Create all 4 possible comments:
for u in (user_a, user_b):
for m in (media_a, media_b):
cmt = TextComment()
cmt.actor = u.id
cmt.content = u"Some Comment"
Session.add(cmt)
# think i need this to get the command ID
Session.flush()
link = Comment()
link.target = m
link.comment = cmt
Session.add(link)
Session.flush()
usr_cnt1 = User.query.count()
med_cnt1 = MediaEntry.query.count()
cmt_cnt1 = Comment.query.count()
User.query.get(user_a.id).delete(commit=False)
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
cmt_cnt2 = Comment.query.count()
# One user deleted
assert usr_cnt2 == usr_cnt1 - 1
# One media gone
assert med_cnt2 == med_cnt1 - 1
# Three of four comments gone.
assert cmt_cnt2 == cmt_cnt1 - 3
User.query.get(user_b.id).delete()
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
cmt_cnt2 = Comment.query.count()
# All users gone
assert usr_cnt2 == usr_cnt1 - 2
# All media gone
assert med_cnt2 == med_cnt1 - 2
# All comments gone
assert cmt_cnt2 == cmt_cnt1 - 4
示例4: save
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import flush [as 别名]
def save(self, obj):
Session.add(obj)
Session.flush()