本文整理汇总了Python中ming.orm.ThreadLocalORMSession类的典型用法代码示例。如果您正苦于以下问题:Python ThreadLocalORMSession类的具体用法?Python ThreadLocalORMSession怎么用?Python ThreadLocalORMSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadLocalORMSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attachment_methods
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
示例2: test_direct_sub
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
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_refresh
def test_refresh(self):
committer_name = 'Test Committer'
committer_email = '[email protected]'
ci = mock.Mock()
ci.authored.name = committer_name
ci.committed.name = committer_name
ci.committed.email = committer_email
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=committer_name,
email=committer_email),
_id=oid)).m.insert()
self.repo._impl.refresh_commit_info = refresh_commit_info
_id = lambda oid: getattr(oid, '_id', str(oid))
self.repo.shorthand_for_commit = lambda oid: '[' + _id(oid) + ']'
self.repo.url_for_commit = lambda oid: '/ci/' + _id(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 %s http://localhost/ci/foo99" % committer_name in n.text
break
else:
assert False, 'Did not find notification'
assert M.Feed.query.find(dict(
author_name=committer_name)).count() == 100
示例5: test_email
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_hideawards_macro
def test_hideawards_macro():
p_nbhd = M.Neighborhood.query.get(name='Projects')
app_config_id = ObjectId()
award = M.Award(app_config_id=app_config_id)
award.short = u'Award short'
award.full = u'Award full'
award.created_by_neighborhood_id = p_nbhd._id
project = M.Project.query.get(
neighborhood_id=p_nbhd._id, shortname=u'test')
M.AwardGrant(
award=award,
award_url='http://award.org',
comment='Winner!',
granted_by_neighborhood=p_nbhd,
granted_to_project=project)
ThreadLocalORMSession.flush_all()
with h.push_context(p_nbhd.neighborhood_project._id):
r = g.markdown_wiki.convert('[[projects]]')
assert_in('<div class="feature"> <a href="http://award.org" rel="nofollow" title="Winner!">'
'Award short</a> </div>',
squish_spaces(r))
r = g.markdown_wiki.convert('[[projects show_awards_banner=False]]')
assert_not_in('Award short', r)
示例7: test_user_search_for_disabled_user
def test_user_search_for_disabled_user(self):
user = M.User.by_username('test-admin')
user.disabled = True
ThreadLocalORMSession.flush_all()
r = self.app.get('/p/test/user_search?term=test', status=200)
j = json.loads(r.body)
assert j == {'users': []}
示例8: main
def main():
for chunk in utils.chunked_find(M.Project):
for p in chunk:
p.install_app('activity')
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
示例9: fix_for_project
def fix_for_project(self, project):
c.project = project
base.log.info(
'Checking discussion instances for each tracker in project %s' %
project.shortname)
trackers = [ac for ac in project.app_configs
if ac.tool_name.lower() == 'tickets']
for tracker in trackers:
base.log.info('Found tracker %s' % tracker)
for ticket in Ticket.query.find({'app_config_id': tracker._id}):
base.log.info('Processing ticket %s [#%s] %s'
% (ticket._id, ticket.ticket_num, ticket.summary))
if ticket.discussion_thread.discussion.app_config_id != tracker._id:
# Some tickets were moved from this tracker,
# and Discussion instance for entire tracker was moved too.
# Should move it back.
base.log.info("Some tickets were moved from this tracker. "
"Moving tracker's discussion instance back.")
ticket.discussion_thread.discussion.app_config_id = tracker._id
if ticket.discussion_thread.discussion_id != tracker.discussion_id:
# Ticket was moved from another tracker.
# Should bind his comment thread to tracker's Discussion
base.log.info("Ticket was moved from another tracker. "
"Bind ticket's comment thread to tracker's Discussion instance.")
ticket.discussion_thread.discussion_id = tracker.discussion_id
for post in ticket.discussion_thread.posts:
post.discussion_id = tracker.discussion_id
ThreadLocalORMSession.flush_all()
示例10: test_post_delete
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()
示例11: test_export_with_attachments
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)
示例12: test_attachment_methods
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
示例13: test_refresh
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()
示例14: fork
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)
示例15: test_macro_include_no_extra_br
def test_macro_include_no_extra_br():
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')
with h.push_context(p_test._id, app_config_id=wiki.config._id):
p = WM.Page.upsert(title='Include_1')
p.text = 'included page 1'
p.commit()
p = WM.Page.upsert(title='Include_2')
p.text = 'included page 2'
p.commit()
p = WM.Page.upsert(title='Include_3')
p.text = 'included page 3'
p.commit()
ThreadLocalORMSession.flush_all()
md = '[[include ref=Include_1]]\n[[include ref=Include_2]]\n[[include ref=Include_3]]'
html = g.markdown_wiki.convert(md)
expected_html = '''<div class="markdown_content"><p></p><div>
<div class="markdown_content"><p>included page 1</p></div>
</div>
<div>
<div class="markdown_content"><p>included page 2</p></div>
</div>
<div>
<div class="markdown_content"><p>included page 3</p></div>
</div>
<p></p></div>'''
assert_equal(squish_spaces(html), squish_spaces(expected_html))