本文整理汇总了Python中ming.orm.ThreadLocalORMSession.flush_all方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadLocalORMSession.flush_all方法的具体用法?Python ThreadLocalORMSession.flush_all怎么用?Python ThreadLocalORMSession.flush_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ming.orm.ThreadLocalORMSession
的用法示例。
在下文中一共展示了ThreadLocalORMSession.flush_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def main():
dbs = dict((p.database_uri, p) for p in M.Project.query.find())
for db, p in sorted(dbs.items()):
log.info('=== Making attachments in %s polymorphic ===', db)
c.project = p
log.info('Fixing %d discussions', M.Discussion.query.find().count())
for d in M.Discussion.query.find():
for a in M.DiscussionAttachment.query.find(dict(
discussion_id=d._id)):
log.info('%s: %s', d.url(), a.filename)
log.info('Fixing %d forums', DM.Forum.query.find().count())
for d in DM.Forum.query.find():
for a in DM.ForumAttachment.query.find(dict(
discussion_id=d._id)):
log.info('%s: %s', d.url(), a.filename)
log.info('Fixing %d tickets', TM.Ticket.query.find().count())
for t in TM.Ticket.query.find():
for a in TM.TicketAttachment.query.find(dict(
artifact_id=t._id)):
log.info('%s: %s', t.url(), a.filename)
log.info('Fixing %d wikis', WM.Page.query.find().count())
for p in WM.Page.query.find():
for a in WM.WikiAttachment.query.find(dict(
artifact_id=p._id)):
log.info('%s: %s', p.url(), a.filename)
ThreadLocalORMSession.flush_all()
示例2: test_direct_sub
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_direct_sub(self):
self._subscribe()
self._post_notification(text='A')
self._post_notification(text='B')
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
M.Mailbox.fire_ready()
示例3: test_make_app_admin_only
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_make_app_admin_only():
h.set_context('test', 'wiki', neighborhood='Projects')
anon = M.User.anonymous()
dev = M.User.query.get(username='test-user')
admin = M.User.query.get(username='test-admin')
c.project.add_user(dev, ['Developer'])
ThreadLocalORMSession.flush_all()
Credentials.get().clear()
assert has_access(c.app, 'read', user=anon)()
assert has_access(c.app, 'read', user=dev)()
assert has_access(c.app, 'read', user=admin)()
assert not has_access(c.app, 'create', user=anon)()
assert has_access(c.app, 'create', user=dev)()
assert has_access(c.app, 'create', user=admin)()
assert c.app.is_visible_to(anon)
assert c.app.is_visible_to(dev)
assert c.app.is_visible_to(admin)
h.make_app_admin_only(c.app)
ThreadLocalORMSession.flush_all()
Credentials.get().clear()
assert not has_access(c.app, 'read', user=anon)()
assert not has_access(c.app, 'read', user=dev)()
assert has_access(c.app, 'read', user=admin)()
assert not has_access(c.app, 'create', user=anon)()
assert not has_access(c.app, 'create', user=dev)()
assert has_access(c.app, 'create', user=admin)()
assert not c.app.is_visible_to(anon)
assert not c.app.is_visible_to(dev)
assert c.app.is_visible_to(admin)
示例4: test_members
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_members(self):
nbhd = M.Neighborhood.query.get(name='Projects')
self.app.post('/admin/groups/create', params={'name': 'B_role'})
test_project = M.Project.query.get(
shortname='test', neighborhood_id=nbhd._id)
test_project.add_user(M.User.by_username('test-user-1'), ['B_role'])
test_project.add_user(M.User.by_username('test-user'), ['Developer'])
test_project.add_user(M.User.by_username('test-user-0'), ['Member'])
test_project.add_user(M.User.by_username('test-user-2'), ['Member'])
test_project.add_user(M.User.by_username('test-user-3'), ['Member'])
test_project.add_user(M.User.by_username('test-user-3'), ['Developer'])
test_project.add_user(M.User.by_username('test-user-4'), ['Admin'])
ThreadLocalORMSession.flush_all()
r = self.app.get('/p/test/_members/')
assert '<td>Test Admin</td>' in r
assert '<td><a href="/u/test-admin/">test-admin</a></td>' in r
assert '<td>Admin</td>' in r
tr = r.html.findAll('tr')
assert "<td>Test Admin</td>" in str(tr[1])
assert "<td>Test User 4</td>" in str(tr[2])
assert "<td>Test User</td>" in str(tr[3])
assert "<td>Test User 3</td>" in str(tr[4])
assert "<td>Test User 0</td>" in str(tr[5])
assert "<td>Test User 1</td>" in str(tr[6])
assert "<td>Test User 2</td>" in str(tr[7])
示例5: test_email
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_email(self):
self._subscribe() # as current user: test-admin
user2 = M.User.query.get(username='test-user-2')
self._subscribe(user=user2)
self._post_notification()
ThreadLocalORMSession.flush_all()
assert_equal(M.Notification.query.get()['from_address'], '"Test Admin" <[email protected]>')
assert_equal(M.Mailbox.query.find().count(), 2)
M.MonQTask.run_ready() # sends the notification out into "mailboxes", and from mailboxes into email tasks
mboxes = M.Mailbox.query.find().all()
assert_equal(len(mboxes), 2)
assert_equal(len(mboxes[0].queue), 1)
assert not mboxes[0].queue_empty
assert_equal(len(mboxes[1].queue), 1)
assert not mboxes[1].queue_empty
email_tasks = M.MonQTask.query.find({'state': 'ready'}).all()
assert_equal(len(email_tasks), 2) # make sure both subscribers will get an email
first_destinations = [e.kwargs['destinations'][0] for e in email_tasks]
assert_in(str(c.user._id), first_destinations)
assert_in(str(user2._id), first_destinations)
assert_equal(email_tasks[0].kwargs['fromaddr'], '"Test Admin" <[email protected]>')
assert_equal(email_tasks[1].kwargs['fromaddr'], '"Test Admin" <[email protected]>')
assert_equal(email_tasks[0].kwargs['sender'], '[email protected]')
assert_equal(email_tasks[1].kwargs['sender'], '[email protected]')
assert email_tasks[0].kwargs['text'].startswith('Home modified by Test Admin')
assert 'you indicated interest in ' in email_tasks[0].kwargs['text']
示例6: test_macro_include_permissions
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_macro_include_permissions():
p_nbhd = M.Neighborhood.query.get(name='Projects')
p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
wiki = p_test.app_instance('wiki')
wiki2 = p_test.app_instance('wiki2')
with h.push_context(p_test._id, app_config_id=wiki.config._id):
p = WM.Page.upsert(title='CanRead')
p.text = 'Can see this!'
p.commit()
ThreadLocalORMSession.flush_all()
with h.push_context(p_test._id, app_config_id=wiki2.config._id):
role = M.ProjectRole.by_name('*anonymous')._id
read_perm = M.ACE.allow(role, 'read')
acl = c.app.config.acl
if read_perm in acl:
acl.remove(read_perm)
p = WM.Page.upsert(title='CanNotRead')
p.text = 'Can not see this!'
p.commit()
ThreadLocalORMSession.flush_all()
with h.push_context(p_test._id, app_config_id=wiki.config._id):
c.user = M.User.anonymous()
md = '[[include ref=CanRead]]\n[[include ref=wiki2:CanNotRead]]'
html = g.markdown_wiki.convert(md)
assert_in('Can see this!', html)
assert_not_in('Can not see this!', html)
assert_in("[[include: you don't have a read permission for wiki2:CanNotRead]]", html)
示例7: test_sendsimplemail_with_disabled_user
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_sendsimplemail_with_disabled_user(self):
c.user = M.User.by_username('test-admin')
with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
mail_tasks.sendsimplemail(
fromaddr=str(c.user._id),
toaddr='[email protected]',
text=u'This is a test',
reply_to=g.noreply,
subject=u'Test subject',
message_id=h.gen_message_id())
assert_equal(_client.sendmail.call_count, 1)
return_path, rcpts, body = _client.sendmail.call_args[0]
body = body.split('\n')
assert_in('From: "Test Admin" <[email protected]>', body)
c.user.disabled = True
ThreadLocalORMSession.flush_all()
mail_tasks.sendsimplemail(
fromaddr=str(c.user._id),
toaddr='[email protected]',
text=u'This is a test',
reply_to=g.noreply,
subject=u'Test subject',
message_id=h.gen_message_id())
assert_equal(_client.sendmail.call_count, 2)
return_path, rcpts, body = _client.sendmail.call_args[0]
body = body.split('\n')
assert_in('From: %s' % g.noreply, body)
示例8: test_export_with_attachments
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_export_with_attachments(self):
project = M.Project.query.get(shortname='test')
discussion = project.app_instance('discussion')
post = Forum.query.get(shortname='general').sorted_threads[0].first_post
test_file1 = FieldStorage()
test_file1.name = 'file_info'
test_file1.filename = 'test_file'
test_file1.file = StringIO('test file1\n')
post.add_attachment(test_file1)
ThreadLocalORMSession.flush_all()
f = tempfile.TemporaryFile()
temp_dir = tempfile.mkdtemp()
discussion.bulk_export(f, temp_dir, True)
f.seek(0)
discussion = json.loads(f.read())
forums = sorted(discussion['forums'], key=lambda x: x['name'])
threads = sorted(forums[0]['threads'], key=lambda x: x['subject'])
file_path = os.path.join(
'discussion',
str(post.discussion_id),
str(post.thread_id),
post.slug,
'test_file'
)
assert_equal(threads[0]['posts'][0]['attachments'][0]['path'], file_path)
os.path.exists(file_path)
示例9: main
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def main():
for chunk in utils.chunked_find(M.Project):
for p in chunk:
p.install_app('activity')
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
示例10: test_attachment_methods
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_attachment_methods():
d = M.Discussion(shortname="test", name="test")
t = M.Thread.new(discussion_id=d._id, subject="Test Thread")
p = t.post("This is a post")
p_att = p.attach("foo.text", StringIO("Hello, world!"), discussion_id=d._id, thread_id=t._id, post_id=p._id)
t_att = p.attach("foo2.text", StringIO("Hello, thread!"), discussion_id=d._id, thread_id=t._id)
d_att = p.attach("foo3.text", StringIO("Hello, discussion!"), discussion_id=d._id)
ThreadLocalORMSession.flush_all()
assert p_att.post == p
assert p_att.thread == t
assert p_att.discussion == d
for att in (p_att, t_att, d_att):
assert "wiki/_discuss" in att.url()
assert "attachment/" in att.url()
# Test notification in mail
t = M.Thread.new(discussion_id=d._id, subject="Test comment notification")
fs = FieldStorage()
fs.name = "file_info"
fs.filename = "fake.txt"
fs.type = "text/plain"
fs.file = StringIO("this is the content of the fake file\n")
p = t.post(text=u"test message", forum=None, subject="", file_info=fs)
ThreadLocalORMSession.flush_all()
n = M.Notification.query.get(subject=u"[test:wiki] Test comment notification")
assert "\nAttachment: fake.txt (37 Bytes; text/plain)" in n.text
示例11: test_post_delete
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_post_delete():
d = M.Discussion(shortname="test", name="test")
t = M.Thread.new(discussion_id=d._id, subject="Test Thread")
p = t.post("This is a post")
p.attach("foo.text", StringIO(""), discussion_id=d._id, thread_id=t._id, post_id=p._id)
ThreadLocalORMSession.flush_all()
p.delete()
示例12: test_refresh
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_refresh(self):
ci = mock.Mock()
ci.count_revisions=mock.Mock(return_value=100)
ci.authored.name = 'Test Committer'
ci.author_url = '/u/test-committer/'
self.repo._impl.commit = mock.Mock(return_value=ci)
self.repo._impl.new_commits = mock.Mock(return_value=['foo%d' % i for i in range(100) ])
self.repo._impl.all_commit_ids = mock.Mock(return_value=['foo%d' % i for i in range(100) ])
self.repo.symbolics_for_commit = mock.Mock(return_value=[['master', 'branch'], []])
def refresh_commit_info(oid, seen, lazy=False):
M.repo.CommitDoc(dict(
authored=dict(
name='Test Committer',
email='[email protected]'),
_id=oid)).m.insert()
def set_heads():
self.repo.heads = [ ming.base.Object(name='head', object_id='foo0', count=100) ]
self.repo._impl.refresh_commit_info = refresh_commit_info
self.repo._impl.refresh_heads = mock.Mock(side_effect=set_heads)
self.repo.shorthand_for_commit = lambda oid: '[' + str(oid) + ']'
self.repo.url_for_commit = lambda oid: '/ci/' + str(oid) + '/'
self.repo.refresh()
ThreadLocalORMSession.flush_all()
notifications = M.Notification.query.find().all()
for n in notifications:
if '100 new commits' in n.subject:
assert "master,branch: by Test Committer http://localhost/#" in n.text
break
else:
assert False, 'Did not find notification'
assert M.Feed.query.find(dict(
title='New commit',
author_name='Test Committer')).count()
示例13: fork
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def fork(self, project_id=None, mount_point=None, mount_label=None):
# this shows the form and handles the submission
security.require_authenticated()
if not c.app.forkable: raise exc.HTTPNotFound
from_repo = c.app.repo
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
from_project = c.project
to_project = M.Project.query.get(_id=ObjectId(project_id))
mount_label = mount_label or '%s - %s' % (c.project.name, c.app.config.options.mount_label)
mount_point = (mount_point or from_project.shortname)
if request.method != 'POST' or not mount_point:
return dict(from_repo=from_repo,
user_project=c.user.private_project(),
mount_point=mount_point,
mount_label=mount_label)
else:
with h.push_config(c, project=to_project):
if not to_project.database_configured:
to_project.configure_project(is_user_project=True)
security.require(security.has_access(to_project, 'admin'))
try:
to_project.install_app(
ep_name=from_repo.tool_name,
mount_point=mount_point,
mount_label=mount_label,
cloned_from_project_id=from_project._id,
cloned_from_repo_id=from_repo._id)
redirect(to_project.url()+mount_point+'/')
except exc.HTTPRedirection:
raise
except Exception, ex:
flash(str(ex), 'error')
redirect(request.referer)
示例14: test_attachment_methods
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_attachment_methods():
d = M.Discussion(shortname='test', name='test')
t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
p = t.post('This is a post')
p_att = p.attach('foo.text', StringIO('Hello, world!'),
discussion_id=d._id,
thread_id=t._id,
post_id=p._id)
t_att = p.attach('foo2.text', StringIO('Hello, thread!'),
discussion_id=d._id,
thread_id=t._id)
d_att = p.attach('foo3.text', StringIO('Hello, discussion!'),
discussion_id=d._id)
ThreadLocalORMSession.flush_all()
assert p_att.post == p
assert p_att.thread == t
assert p_att.discussion == d
for att in (p_att, t_att, d_att):
assert 'wiki/_discuss' in att.url()
assert 'attachment/' in att.url()
# Test notification in mail
t = M.Thread.new(discussion_id=d._id, subject='Test comment notification')
fs = FieldStorage()
fs.name = 'file_info'
fs.filename = 'fake.txt'
fs.type = 'text/plain'
fs.file = StringIO('this is the content of the fake file\n')
p = t.post(text=u'test message', forum=None, subject='', file_info=fs)
ThreadLocalORMSession.flush_all()
n = M.Notification.query.get(
subject=u'[test:wiki] Test comment notification')
assert '\nAttachment: fake.txt (37 Bytes; text/plain)' in n.text
示例15: test_macro_neighborhood_feeds
# 需要导入模块: from ming.orm import ThreadLocalORMSession [as 别名]
# 或者: from ming.orm.ThreadLocalORMSession import flush_all [as 别名]
def test_macro_neighborhood_feeds():
p_nbhd = M.Neighborhood.query.get(name='Projects')
p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
with h.push_context('--init--', 'wiki', neighborhood='Projects'):
r = g.markdown_wiki.convert('[[neighborhood_feeds tool_name=wiki]]')
assert 'Home modified by' in r, r
orig_len = len(r)
# Make project private & verify we don't see its new feed items
anon = M.User.anonymous()
p_test.acl.insert(0, M.ACE.deny(
M.ProjectRole.anonymous(p_test)._id, 'read'))
ThreadLocalORMSession.flush_all()
pg = WM.Page.query.get(title='Home', app_config_id=c.app.config._id)
pg.text = 'Change'
with h.push_config(c, user=M.User.by_username('test-admin')):
pg.commit()
r = g.markdown_wiki.convert('[[neighborhood_feeds tool_name=wiki]]')
new_len = len(r)
assert new_len == orig_len
p = BM.BlogPost(title='test me',
neighborhood_id=p_test.neighborhood_id)
p.text = 'test content'
p.state = 'published'
p.make_slug()
with h.push_config(c, user=M.User.by_username('test-admin')):
p.commit()
ThreadLocalORMSession.flush_all()
with h.push_config(c, user=anon):
r = g.markdown_wiki.convert('[[neighborhood_blog_posts]]')
assert 'test content' in r