You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/07/18 21:02:18 UTC
[11/28] git commit: [#7293] PEP8 & Import optimization
[#7293] PEP8 & Import optimization
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/42da7f79
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/42da7f79
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/42da7f79
Branch: refs/heads/db/7523
Commit: 42da7f79506df99592d26fa90675c2afb823b68d
Parents: 326ba27
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Mon Jul 7 22:41:59 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Jul 9 18:07:08 2014 +0000
----------------------------------------------------------------------
.gitignore | 2 +
Allura/allura/controllers/trovecategories.py | 3 +-
Allura/allura/ext/admin/admin_main.py | 95 +++++++++-----------
.../tests/functional/test_trovecategory.py | 42 +++++----
4 files changed, 69 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/42da7f79/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index a792fb7..cb2f607 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,5 @@ scripts/teamforge-export/
report.clonedigger
.ropeproject
.idea
+._*
+.DS_Store
http://git-wip-us.apache.org/repos/asf/allura/blob/42da7f79/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index c208e2f..b57e517 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -39,7 +39,6 @@ class F(object):
class TroveCategoryController(BaseController):
-
@expose()
def _lookup(self, catshortname, *remainder):
cat = M.TroveCategory.query.get(shortname=catshortname)
@@ -246,4 +245,4 @@ class TroveCategorySiteAdminExtension(SiteAdminExtension):
enable_editing = config.get('trovecategories.enableediting', 'false')
if enable_editing in ('admin', 'true'):
links.append(SitemapEntry('Troves', '/categories',
- ui_icon=g.icons['admin']))
+ ui_icon=g.icons['admin']))
http://git-wip-us.apache.org/repos/asf/allura/blob/42da7f79/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 6a1287b..2257287 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -14,14 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from collections import OrderedDict
import logging
from datetime import datetime
from urlparse import urlparse
import json
from operator import itemgetter
-
import pkg_resources
from pylons import tmpl_context as c, app_globals as g
from pylons import request
@@ -32,7 +30,6 @@ from webob import exc
from bson import ObjectId
from ming.orm.ormsession import ThreadLocalORMSession
from ming.odm import session
-
from allura.app import Application, DefaultAdminController, SitemapEntry
from allura.lib import helpers as h
from allura import version
@@ -45,9 +42,10 @@ from allura.lib import plugin
from allura.controllers import BaseController
from allura.lib.decorators import require_post
from allura.tasks import export_tasks
+from allura.lib.widgets.project_list import ProjectScreenshots
from . import widgets as aw
-from allura.lib.widgets.project_list import ProjectScreenshots
+
log = logging.getLogger(__name__)
@@ -73,7 +71,6 @@ class W:
class AdminApp(Application):
-
'''This is the admin app. It is pretty much required for
a functioning allura project.
'''
@@ -136,7 +133,7 @@ class AdminApp(Application):
if c.project.is_nbhd_project:
links.append(SitemapEntry('Add Project', c.project.url()
- + 'add_project', ui_icon=g.icons['plus']))
+ + 'add_project', ui_icon=g.icons['plus']))
nbhd_admin_url = c.project.neighborhood.url() + '_admin/'
links = links + [
SitemapEntry('Neighborhood'),
@@ -184,7 +181,6 @@ class AdminApp(Application):
class AdminExtensionLookup(object):
-
@expose()
def _lookup(self, name, *remainder):
for ep_name in sorted(g.entry_points['admin'].keys()):
@@ -196,7 +192,6 @@ class AdminExtensionLookup(object):
class ProjectAdminController(BaseController):
-
def _check_security(self):
require_access(c.project, 'admin')
@@ -229,14 +224,15 @@ class ProjectAdminController(BaseController):
c.explain_export_modal = W.explain_export_modal
show_export_control = asbool(config.get('show_export_control', False))
allow_project_delete = asbool(config.get('allow_project_delete', True))
- explain_export_text = '''The purpose of this section is to determine whether your project is subject to the provisions of the
- US Export Administration Regulations. You should consult section 734.4 and Supplement 2 to Part 734 for information on such items
- and the calculation of U.S. controlled content.
- <a href="http://www.bis.doc.gov/encryption/default.htm" target="_blank">http://www.bis.doc.gov/encryption/default.htm</a>'''
+ explain_export_text = '''The purpose of this section is to determine whether your project is subject to the
+ provisions of the US Export Administration Regulations. You should consult section 734.4 and Supplement 2
+ to Part 734 for information on such items and the calculation of U.S. controlled content.
+ <a href="http://www.bis.doc.gov/encryption/default.htm" target="_blank">
+ http://www.bis.doc.gov/encryption/default.htm</a>'''
if 'us_export_contact' in config:
- explain_export_text += 'If you have additional questions, please contact <a href="mailto:{contact}">{contact}</a>.'.format(
- contact=config['us_export_contact']
- )
+ explain_export_text += \
+ 'If you have additional questions, ' \
+ 'please contact <a href="mailto:{contact}">{contact}</a>.'.format(contact=config['us_export_contact'])
return dict(show_export_control=show_export_control,
allow_project_delete=allow_project_delete,
explain_export_text=explain_export_text)
@@ -722,7 +718,6 @@ class ProjectAdminController(BaseController):
class ProjectAdminRestController(BaseController):
-
"""
Exposes RESTful APi for project admin actions.
"""
@@ -817,36 +812,35 @@ class ProjectAdminRestController(BaseController):
controller = ProjectAdminController()
if not tool or not mount_point or not mount_label:
- return {'success': False,
- 'info': 'All arguments required.'
- }
+ return {
+ 'success': False,
+ 'info': 'All arguments required.'
+ }
installable_tools = AdminApp.installable_tools_for(c.project)
tools_names = [t['name'] for t in installable_tools]
- if not tool in tools_names:
- return {'success': False,
- 'info': 'Incorrect tool name, or limit is reached.'
- }
+ if not (tool in tools_names):
+ return {
+ 'success': False,
+ 'info': 'Incorrect tool name, or limit is reached.'
+ }
if c.project.app_instance(mount_point) is not None:
- return {'success': False,
- 'info': 'Mount point already exists.',
- }
+ return {
+ 'success': False,
+ 'info': 'Mount point already exists.',
+ }
if order is None:
order = 'last'
- mounts = [{
- 'ordinal': ac.options.ordinal,
- 'label': ac.options.mount_label,
- 'mount': ac.options.mount_point,
- 'type': ac.tool_name.lower(),
- } for ac in c.project.app_configs]
- subs = {p.shortname:
- p for p in M.Project.query.find({'parent_id': c.project._id})}
+ mounts = [{'ordinal': ac.options.ordinal,
+ 'label': ac.options.mount_label,
+ 'mount': ac.options.mount_point,
+ 'type': ac.tool_name.lower()}
+ for ac in c.project.app_configs]
+ subs = {p.shortname: p for p in M.Project.query.find({'parent_id': c.project._id})}
for sub in subs.values():
- mounts.append({
- 'ordinal': sub.ordinal,
- 'mount': sub.shortname,
- 'type': 'sub-project',
- })
+ mounts.append({'ordinal': sub.ordinal,
+ 'mount': sub.shortname,
+ 'type': 'sub-project'})
mounts.sort(key=itemgetter('ordinal'))
if order == 'first':
ordinal = 0
@@ -879,17 +873,18 @@ class ProjectAdminRestController(BaseController):
try:
controller._update_mounts(new=data)
except forge_exc.ForgeError as e:
- return {'success': False,
- 'info': str(e),
- }
- return {'success': True,
- 'info': 'Tool %s with mount_point %s and mount_label %s was created.'
- % (tool, mount_point, mount_label)
- }
+ return {
+ 'success': False,
+ 'info': str(e),
+ }
+ return {
+ 'success': True,
+ 'info': 'Tool %s with mount_point %s and mount_label %s was created.'
+ % (tool, mount_point, mount_label)
+ }
class PermissionsController(BaseController):
-
def _check_security(self):
require_access(c.project, 'admin')
@@ -951,7 +946,6 @@ class PermissionsController(BaseController):
class GroupsController(BaseController):
-
def _check_security(self):
require_access(c.project, 'admin')
@@ -973,7 +967,7 @@ class GroupsController(BaseController):
permissions_by_role[str(role._id)] = []
for perm in permissions:
perm_info = dict(has="no", text="Does not have permission %s" %
- perm, name=perm)
+ perm, name=perm)
role_ids = permissions[perm]
if role._id in role_ids:
perm_info['text'] = "Has permission %s" % perm
@@ -1161,7 +1155,6 @@ class GroupsController(BaseController):
class GroupController(BaseController):
-
def __init__(self, name):
self._group = M.ProjectRole.query.get(_id=ObjectId(name))
@@ -1201,7 +1194,6 @@ class GroupController(BaseController):
class AuditController(BaseController):
-
@with_trailing_slash
@expose('jinja:allura.ext.admin:templates/audit.html')
def index(self, limit=10, page=0, **kwargs):
@@ -1224,6 +1216,5 @@ class AuditController(BaseController):
class AdminAppAdminController(DefaultAdminController):
-
'''Administer the admin app'''
pass
http://git-wip-us.apache.org/repos/asf/allura/blob/42da7f79/Allura/allura/tests/functional/test_trovecategory.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_trovecategory.py b/Allura/allura/tests/functional/test_trovecategory.py
index 3e0facc..64992a7 100644
--- a/Allura/allura/tests/functional/test_trovecategory.py
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -14,8 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from collections import OrderedDict
-
+from BeautifulSoup import BeautifulSoup
import mock
from tg import config
@@ -30,7 +29,6 @@ from allura.tests import decorators as td
class TestTroveCategory(TestController):
-
@mock.patch('allura.model.project.g.post_event')
def test_events(self, post_event):
setup_trove_categories()
@@ -82,6 +80,7 @@ class TestTroveCategory(TestController):
check_access(username='test-user', status=403)
check_access(username='root', status=200)
+
class TestTroveCategoryController(TestController):
@td.with_tool('test2', 'admin_main', 'admin')
def test_trove_hierarchy(self):
@@ -94,23 +93,28 @@ class TestTroveCategoryController(TestController):
session(M.TroveCategory).flush()
r = self.app.get('/categories/browse')
- tree = r.controller_output['tree']
-
- expected_data = OrderedDict(
- [('Root', OrderedDict(
- [('CategoryA', OrderedDict([
- ('ChildA', OrderedDict()),
- ('ChildB', OrderedDict())
- ])),
- ('CategoryB', OrderedDict())
- ])
- )]
- )
- assert tree == expected_data
+ rendered_tree = r.html.find('div', {'id': 'content_base'}).find('div').find('div').find('ul')
+ expected = BeautifulSoup("""
+ <ul>
+ <li>Root</li>
+ <ul>
+ <li>CategoryA</li>
+ <ul>
+ <li>ChildA</li>
+ <li>ChildB</li>
+ </ul>
+ <li>CategoryB</li>
+ </ul>
+ </ul>
+ """.strip())
+ assert str(expected) == str(rendered_tree)
@td.with_tool('test2', 'admin_main', 'admin')
def test_trove_empty_hierarchy(self):
r = self.app.get('/categories/browse')
- tree = r.controller_output['tree']
- assert tree == OrderedDict()
-
+ rendered_tree = r.html.find('div', {'id': 'content_base'}).find('div').find('div').find('ul')
+ expected = BeautifulSoup("""
+ <ul>
+ </ul>
+ """.strip())
+ assert str(expected) == str(rendered_tree)
\ No newline at end of file