本文整理汇总了Python中ming.odm.ThreadLocalORMSession类的典型用法代码示例。如果您正苦于以下问题:Python ThreadLocalORMSession类的具体用法?Python ThreadLocalORMSession怎么用?Python ThreadLocalORMSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadLocalORMSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_disable_user
def test_disable_user(self):
# user was not pending
assert_equal(M.User.by_username('test-user-3').disabled, False)
assert_equal(M.User.by_username('test-user-3').pending, False)
r = self.app.get('/nf/admin/user/test-user-3')
form = r.forms[0]
assert_equal(form['username'].value, 'test-user-3')
assert_equal(form['status'].value, 'enable')
form['status'].value = 'disable'
with td.audits('Account disabled', user=True):
r = form.submit()
assert_equal(M.AuditLog.query.find().count(), 1)
assert_in(u'User disabled', self.webflash(r))
assert_equal(M.User.by_username('test-user-3').disabled, True)
assert_equal(M.User.by_username('test-user-3').pending, False)
# user was pending
user = M.User.by_username('test-user-3')
user.disabled = False
user.pending = True
ThreadLocalORMSession.flush_all()
assert_equal(M.User.by_username('test-user-3').disabled, False)
assert_equal(M.User.by_username('test-user-3').pending, True)
r = self.app.get('/nf/admin/user/test-user-3')
form = r.forms[0]
assert_equal(form['username'].value, 'test-user-3')
assert_equal(form['status'].value, 'pending')
form['status'].value = 'disable'
with td.audits('Account disabled', user=True):
r = form.submit()
assert_equal(M.AuditLog.query.find().count(), 1)
assert_in(u'User disabled', self.webflash(r))
assert_equal(M.User.by_username('test-user-3').disabled, True)
assert_equal(M.User.by_username('test-user-3').pending, True)
示例2: execute
def execute(cls, options):
duplicates = cls._find_duplicates()
log.info('Found %s duplicate categories: %s', len(duplicates), duplicates.keys())
for name, dups in duplicates.iteritems():
projects_with_category = {}
for dup in dups:
projects = cls._projects_with_category(dup._id)
projects_with_category[dup._id] = projects
log.info('Following projects are using category %s:', name)
for _id, ps in projects_with_category.iteritems():
log.info(' with id %s: %s', _id, [p.shortname for p in ps])
priority = [(i, len(ps)) for i, ps in projects_with_category.items()]
priority = sorted(priority, key=itemgetter(1), reverse=True)
priority = [p[0] for p in priority]
live, kill = priority[0], priority[1:]
log.info('%s will live %s will die', live, kill)
if sum([len(projects_with_category[_id]) for _id in kill]) > 0:
# Duplicates are used somewhere, need to reasign for all projects that use them
projects = []
ids_to_kill = set(kill)
for p in [projects_with_category[_id] for _id in kill]:
projects.extend(p)
for p in projects:
for tt in cls.trove_types:
_ids = ids_to_kill.intersection(getattr(p, tt))
for _id in _ids:
log.info('Removing %s from %s.%s and adding %s instead', _id, p.shortname, tt, live)
if not options.dry_run:
getattr(p, tt).remove(_id)
getattr(p, tt).append(live)
log.info('Removing categories %s', kill)
if not options.dry_run:
M.TroveCategory.query.remove({'_id': {'$in': kill}})
ThreadLocalORMSession.flush_all()
示例3: main
def main():
for chunk in utils.chunked_find(M.User):
for user in chunk:
print 'Processing {0}'.format(user.username)
user.pending = False
# Ming doesn't mark document for update, since pending is False
# by default, even if field is missing from mongo
state(user).status = state(user).dirty
ThreadLocalORMSession.flush_all()
示例4: main
def main():
for chunk in utils.chunked_find(M.MergeRequest):
for mr in chunk:
try:
print 'Processing {0}'.format(mr.url())
mr.subscribe(user=mr.creator)
ThreadLocalORMSession.flush_all()
except:
log.exception('Error on %s', mr)
示例5: test_is_spam
def test_is_spam(self, spam_checker):
spam_checker.check.return_value = True
c.user = M.User.query.get(username="test-user")
role = M.ProjectRole(project_id=c.project._id, name='TestRole')
M.ProjectRole.by_user(c.user, upsert=True).roles.append(role._id)
ThreadLocalORMSession.flush_all()
t = M.Thread()
p = M.Post()
assert_in('TestRole', [r.name for r in c.project.named_roles])
assert_false(t.is_spam(p))
示例6: test_new_projects_deleted_projects
def test_new_projects_deleted_projects(self):
'''Deleted projects should not be visible here'''
r = self.app.get('/nf/admin/new_projects', extra_environ=dict(
username='root'))
count = len(r.html.find('table').findAll('tr'))
p = M.Project.query.get(shortname='test')
p.deleted = True
ThreadLocalORMSession.flush_all()
r = self.app.get('/nf/admin/new_projects', extra_environ=dict(
username='root'))
assert_equal(len(r.html.find('table').findAll('tr')), count - 1)
示例7: test_create_limit
def test_create_limit(self, import_tool, extractor):
extractor.return_value.get_repo_type.return_value = "git"
project = M.Project.query.get(shortname=test_project_with_repo)
project.set_tool_data("GoogleRepoImporter", pending=1)
ThreadLocalORMSession.flush_all()
params = dict(gc_project_name="poop", mount_label="mylabel", mount_point="mymount")
r = self.app.post(
"/p/{}/admin/ext/import/google-code-repo/create".format(test_project_with_repo), params, status=302
).follow()
self.assertIn("Please wait and try again", r)
self.assertEqual(import_tool.post.call_count, 0)
示例8: test_create_limit
def test_create_limit(self, import_tool):
project = M.Project.query.get(shortname='test')
project.set_tool_data('GoogleCodeTrackerImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(gc_project_name='test',
mount_label='mylabel',
mount_point='mymount',
)
r = self.app.post('/p/test/admin/bugs/_importer/create', params,
status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
示例9: test_create_limit
def test_create_limit(self, import_tool, sui):
project = M.Project.query.get(shortname="test")
project.set_tool_data("ForgeTrackerImporter", pending=1)
ThreadLocalORMSession.flush_all()
params = {
"tickets_json": webtest.Upload("tickets.json", '{"key": "val"}'),
"mount_label": "mylabel",
"mount_point": "mymount",
}
r = self.app.post("/p/test/admin/bugs/_importer/create", params, status=302).follow()
self.assertIn("Please wait and try again", r)
self.assertEqual(import_tool.post.call_count, 0)
示例10: test_record_result
def test_record_result(self):
config = {}
artifact = WM.Page.query.get()
user = M.User.query.get(username='test-user')
SpamFilter(config).record_result(True, artifact, user)
ThreadLocalORMSession.flush_all()
results = SpamCheckResult.query.find().all()
assert_equal(len(results), 1)
assert_equal(results[0].result, True)
assert_equal(results[0].user.username, 'test-user')
示例11: test_create_limit
def test_create_limit(self, import_tool):
p = M.Project.query.get(shortname=test_project_with_wiki)
p.set_tool_data('GitHubWikiImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(
gh_user_name='spooky',
gh_project_name='mulder',
mount_point='gh-wiki',
mount_label='GitHub Wiki')
r = self.app.post(self.url + 'create', params, status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
示例12: main
def main(start, cnt):
n = M.Neighborhood.query.get(url_prefix='/p/')
admin = M.User.by_username('admin1')
#M.Project.query.remove({'shortname': re.compile('gen-proj-.*')})
#ThreadLocalORMSession.flush_all()
for i in range(start, cnt):
name = 'gen-proj-{}'.format(i)
project = n.register_project(name, admin)
if (i-start) > 0 and (i-start) % 100 == 0:
print 'Created {} projects'.format(i-start)
print 'Flushing...'
ThreadLocalORMSession.flush_all()
print 'Done'
示例13: test_create_limit
def test_create_limit(self, import_tool, requests):
requests.head.return_value.status_code = 200
p = M.Project.query.get(shortname=test_project_with_tracker)
p.set_tool_data('GitHubTrackerImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(
gh_user_name='spooky',
gh_project_name='mulder',
mount_point='issues',
mount_label='Issues')
r = self.app.post(self.url + 'create', params, status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
示例14: test_create_limit
def test_create_limit(self, import_tool):
project = M.Project.query.get(shortname=test_project_with_repo)
project.set_tool_data('GitHubRepoImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(
gh_user_name='spooky',
gh_project_name='poop',
mount_label='mylabel',
mount_point='mymount',
)
r = self.app.post('/p/{}/admin/ext/import/github-repo/create'.format(test_project_with_repo),
params,
status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
示例15: test_send_password_reset_link
def test_send_password_reset_link(self, gen_message_id, sendmail):
user = M.User.by_username('test-user')
user.set_pref('email_address', '[email protected]')
M.EmailAddress(email='[email protected]', confirmed=True, claimed_by_user_id=user._id)
ThreadLocalORMSession.flush_all()
with td.audits('Password recovery link sent to: [email protected]', user=True):
r = self.app.post('/nf/admin/user/send_password_reset_link', params={'username': 'test-user'})
hash = user.get_tool_data('AuthPasswordReset', 'hash')
text = '''Your username is test-user
To reset your password on %s, please visit the following URL:
%s/auth/forgotten_password/%s''' % (config['site_name'], config['base_url'], hash)
sendmail.post.assert_called_once_with(
toaddr='[email protected]',
fromaddr=config['forgemail.return_path'],
reply_to=config['forgemail.return_path'],
subject='Allura Password recovery',
message_id=gen_message_id(),
text=text)