Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Create clean environment for running tests.
A lightweight alternative is setup_config_test which doesn't bootstrap app data.
'''
try:
conf_dir = tg.config.here
except AttributeError:
conf_dir = os.getcwd()
ew.TemplateEngine.initialize({})
test_file = os.path.join(conf_dir, get_config_file(config))
cmd = SetupCommand('setup-app')
cmd.run([test_file])
# run all tasks, e.g. indexing from bootstrap operations
while M.MonQTask.run_ready('setup'):
ThreadLocalORMSession.flush_all()
setup_basic_test.__test__ = False # sometimes __test__ above isn't sufficient
def uninstall(**kwargs):
from allura import model as M
repo = c.app.repo
if repo is not None:
shutil.rmtree(repo.full_fs_path, ignore_errors=True)
repo.delete()
M.MergeRequest.query.remove(dict(
app_config_id=c.app.config._id))
super(RepositoryApp, c.app).uninstall(c.project)
from ming.orm import ThreadLocalORMSession
ThreadLocalORMSession.flush_all()
def main():
query = {'tool_name': {'$regex': '^tickets$', '$options': 'i'}}
for chunk in utils.chunked_find(M.AppConfig, query):
for a in chunk:
# change 'deny write' and 'write' permission
role_ids = [(p.role_id, p.access)
for p in a.acl if p.permission == 'write']
for role_id, access in role_ids:
if access == M.ACE.DENY:
add(a.acl, M.ACE.deny(role_id, 'create'))
add(a.acl, M.ACE.deny(role_id, 'update'))
else:
add(a.acl, M.ACE.allow(role_id, 'create'))
add(a.acl, M.ACE.allow(role_id, 'update'))
ThreadLocalORMSession.flush_all()
c.app = app
c.project = p
c.user = user
if "This is the personal project of" in page.text:
if description not in page.text:
page.text = "%s\n\n%s" % (page.text, description)
log.info("Update wiki home page text for %s" % user.username)
elif "This is the default page" in page.text:
page.text = default_personal_project_tmpl % (user.display_name, description)
log.info("Update wiki home page text for %s" % user.username)
else:
pass
ThreadLocalORMSession.flush_all()
def reclone(*args, **kwargs):
from allura import model as M
from ming.orm import ThreadLocalORMSession
repo = c.app.repo
if repo is not None:
shutil.rmtree(repo.full_fs_path, ignore_errors=True)
M.MergeRequest.query.remove(dict(
app_config_id=c.app.config._id))
ThreadLocalORMSession.flush_all()
clone(*args, **kwargs)
def main():
for chunk in utils.chunked_find(SM.Repository):
for r in chunk:
print 'Processing {0}'.format(r)
all_commit_ids = r._impl.all_commit_ids()
if all_commit_ids:
for commit in M.repository.Commit.query.find({'_id': {'$in': all_commit_ids}}):
if commit.tree_id and M.repository.Tree.query.get(_id=commit.tree_id):
kill_tree(r._impl, commit._id, '', commit.tree)
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
q = {'neighborhood_id': nbhd._id,
'is_nbhd_project': False, 'deleted': False}
private_count = public_count = 0
for projects in utils.chunked_find(M.Project, q):
for p in projects:
role_anon = M.ProjectRole.upsert(name='*anonymous',
project_id=p.root_project._id)
if M.ACE.allow(role_anon._id, 'read') not in p.acl:
if options.test:
log.info('Would be made public: "%s"' % p.shortname)
else:
log.info('Making public: "%s"' % p.shortname)
p.acl.append(M.ACE.allow(role_anon._id, 'read'))
with h.push_config(c, project=p, user=nbhd_admin):
ThreadLocalORMSession.flush_all()
g.post_event('project_updated')
private_count += 1
else:
log.info('Already public: "%s"' % p.shortname)
public_count += 1
log.info('Already public: %s' % public_count)
if options.test:
log.info('Would be made public: %s' % private_count)
else:
log.info('Made public: %s' % private_count)
return 0
def execute(cls, options):
query = {'tool_name': {'$regex': '^svn$', '$options': 'i'},
'options.checkout_url': ''}
for chunk in utils.chunked_find(M.AppConfig, query):
for config in chunk:
repo = Repository.query.get(app_config_id=config._id)
trunk_path = "file://{0}{1}/trunk".format(repo.fs_path,
repo.name)
if svn_path_exists(trunk_path):
config.options['checkout_url'] = "trunk"
log.info("Update checkout_url for: %s", trunk_path)
ThreadLocalORMSession.flush_all()
# 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()
def reclone(*args, **kwargs):
from allura import model as M
from ming.orm import ThreadLocalORMSession
repo = c.app.repo
if repo is not None:
shutil.rmtree(repo.full_fs_path, ignore_errors=True)
repo.delete()
ThreadLocalORMSession.flush_all()
M.MergeRequest.query.remove(dict(
app_config_id=c.app.config._id))
clone(*args, **kwargs)