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 2015/08/14 21:42:03 UTC
[1/3] allura git commit: [#7953] add a custom pylint checker to find
@expose('json') needing **kwargs
Repository: allura
Updated Branches:
refs/heads/db/7953 [created] 2a1faf6e1
[#7953] add a custom pylint checker to find @expose('json') needing **kwargs
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/31ba21a3
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/31ba21a3
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/31ba21a3
Branch: refs/heads/db/7953
Commit: 31ba21a3a991e3c7f38a12d26c16575133261ed0
Parents: c0e2faa
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Aug 14 15:35:52 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Aug 14 15:35:52 2015 -0400
----------------------------------------------------------------------
AlluraTest/alluratest/pylint_checkers.py | 56 +++++++++++++++++++++++++++
AlluraTest/alluratest/test_syntax.py | 4 ++
requirements.txt | 3 ++
3 files changed, 63 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/31ba21a3/AlluraTest/alluratest/pylint_checkers.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/pylint_checkers.py b/AlluraTest/alluratest/pylint_checkers.py
new file mode 100644
index 0000000..27350b0
--- /dev/null
+++ b/AlluraTest/alluratest/pylint_checkers.py
@@ -0,0 +1,56 @@
+import astroid
+
+from pylint.checkers import BaseChecker, utils
+from pylint.interfaces import IAstroidChecker
+
+
+def register(linter):
+ linter.register_checker(ExposedAPIHasKwargs(linter))
+
+
+# FIXME?
+BASE_ID = 76 # taken from https://github.com/edx/edx-lint/tree/master/edx_lint/pylint
+
+class ExposedAPIHasKwargs(BaseChecker):
+
+ __implements__ = (IAstroidChecker,)
+
+ name = 'exposed-api-needs-kwargs'
+
+ MESSAGE_ID = name
+ msgs = {
+ 'E%d10' % BASE_ID: (
+ "@expose'd method %s() looks like an API and needs **kwargs",
+ MESSAGE_ID,
+ "@expose'd API methods should have **kwargs to avoid an error when accessed with ?access_token=XYZ",
+ ),
+ }
+
+ @utils.check_messages(MESSAGE_ID)
+ def visit_function(self, node):
+ # special TurboGears method name, doesn't need **kw
+ if node.name == '_lookup':
+ return
+
+ # Assume @expose('json:') means its an API endpoint. Not a perfect assumption:
+ # - could be an API endpoint used only for PUT/POST with no json result)
+ # - there are non-API endpoints that return json (for ajax)
+ has_json_expose = False
+ if node.decorators:
+ for dec in node.decorators.nodes:
+ if hasattr(dec, 'func'): # otherwise its a @deco without parens
+ if getattr(dec.func, 'name', '') == 'expose':
+ for arg in dec.args:
+ if getattr(arg, 'value', '') in ('json', 'json:'):
+ has_json_expose = True
+
+ if not has_json_expose:
+ return
+
+ if node.args.kwarg:
+ return
+
+ if not self.linter.is_message_enabled(self.MESSAGE_ID, line=node.fromlineno):
+ return
+
+ self.add_message(self.MESSAGE_ID, args=node.name, node=node)
http://git-wip-us.apache.org/repos/asf/allura/blob/31ba21a3/AlluraTest/alluratest/test_syntax.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/test_syntax.py b/AlluraTest/alluratest/test_syntax.py
index b30a6b8..d29b00b 100644
--- a/AlluraTest/alluratest/test_syntax.py
+++ b/AlluraTest/alluratest/test_syntax.py
@@ -103,3 +103,7 @@ def test_no_prints():
def test_no_tabs():
if run(find_py + " | xargs grep ' ' ") not in [1, 123]:
raise Exception('These should not use tab chars')
+
+def test_linters():
+ if run(find_py + ' | xargs pylint -E --disable=all --enable=exposed-api-needs-kwargs --load-plugins alluratest.pylint_checkers') != 0:
+ raise Exception('Custom Allura pylint errors found.')
http://git-wip-us.apache.org/repos/asf/allura/blob/31ba21a3/requirements.txt
----------------------------------------------------------------------
diff --git a/requirements.txt b/requirements.txt
index 0c96317..854688f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -78,6 +78,9 @@ nose==1.3.4
pyflakes==0.8.1
WebTest==1.4.0
testfixtures==3.0.0
+pylint==1.4.4
+astroid==1.3.8
+logilab-common==1.0.2
q==2.3
WebError==0.10.3
-e git://github.com/brondsem/sphinx-argparse.git#egg=sphinx-argparse # pending merge requests
[3/3] allura git commit: [#7953] and one functional test update for
the specific reported issue
Posted by br...@apache.org.
[#7953] and one functional test update for the specific reported issue
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2a1faf6e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2a1faf6e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2a1faf6e
Branch: refs/heads/db/7953
Commit: 2a1faf6e1d7597a55837bbb14f03e1cd3f4de73c
Parents: 24b410c
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Aug 14 15:39:51 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Aug 14 15:39:51 2015 -0400
----------------------------------------------------------------------
ForgeBlog/forgeblog/tests/functional/test_rest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2a1faf6e/ForgeBlog/forgeblog/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/functional/test_rest.py b/ForgeBlog/forgeblog/tests/functional/test_rest.py
index 3fc7647..3df73da 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_rest.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_rest.py
@@ -243,7 +243,7 @@ class TestBlogApi(TestRestApiBase):
def test_has_access(self):
r = self.api_get(
- '/rest/p/test/blog/has_access?user=test-admin&perm=post',
+ '/rest/p/test/blog/has_access?user=test-admin&perm=post&access_token=ABCDEF',
user='root')
assert_equal(r.status_int, 200)
assert_equal(r.json['result'], True)
[2/3] allura git commit: [#7953] add **kw to api endpoints so
?access_token=X doesn't error,
and some more ajax endpoints to make the test happy
Posted by br...@apache.org.
[#7953] add **kw to api endpoints so ?access_token=X doesn't error, and some more ajax endpoints to make the test happy
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/24b410ce
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/24b410ce
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/24b410ce
Branch: refs/heads/db/7953
Commit: 24b410ceb4238978a4e56be650fc94968f35b25e
Parents: 31ba21a
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Aug 14 15:36:37 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Aug 14 15:36:37 2015 -0400
----------------------------------------------------------------------
Allura/allura/app.py | 4 ++--
Allura/allura/controllers/project.py | 16 ++++++++--------
Allura/allura/controllers/repository.py | 6 +++---
Allura/allura/controllers/rest.py | 6 +++---
Allura/allura/controllers/site_admin.py | 2 +-
Allura/allura/webhooks.py | 2 +-
ForgeShortUrl/forgeshorturl/main.py | 2 +-
ForgeTracker/forgetracker/tracker_main.py | 10 +++++-----
ForgeWiki/forgewiki/wiki_main.py | 4 ++--
9 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 62b82fe..1d02ffa 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -747,7 +747,7 @@ class DefaultAdminController(BaseController):
@expose('json:')
@require_post()
- def block_user(self, username, perm, reason=None):
+ def block_user(self, username, perm, reason=None, **kw):
if not username or not perm:
return dict(error='Enter username')
user = model.User.by_username(username)
@@ -764,7 +764,7 @@ class DefaultAdminController(BaseController):
perm=V.UnicodeString()))
@expose('json:')
@require_post()
- def unblock_user(self, user_id=None, perm=None):
+ def unblock_user(self, user_id=None, perm=None, **kw):
try:
user_id = map(ObjectId, user_id)
except InvalidId:
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 4526e62..20d9f63 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -199,7 +199,7 @@ class NeighborhoodController(object):
return {}
@expose('json:')
- def verify_phone(self, number):
+ def verify_phone(self, number, **kw):
p = plugin.ProjectRegistrationProvider.get()
result = p.verify_phone(c.user, number)
request_id = result.pop('request_id', None)
@@ -214,7 +214,7 @@ class NeighborhoodController(object):
return result
@expose('json:')
- def check_phone_verification(self, pin):
+ def check_phone_verification(self, pin, **kw):
p = plugin.ProjectRegistrationProvider.get()
request_id = session.get('phone_verification.request_id')
number_hash = session.get('phone_verification.number_hash')
@@ -225,7 +225,7 @@ class NeighborhoodController(object):
return res
@expose('json:')
- def suggest_name(self, project_name=''):
+ def suggest_name(self, project_name='', **kw):
provider = plugin.ProjectRegistrationProvider.get()
return dict(suggested_name=provider.suggest_name(project_name,
self.neighborhood))
@@ -295,7 +295,7 @@ class NeighborhoodController(object):
return icon.serve()
@expose('json:')
- def users(self):
+ def users(self, **kw):
p = self.neighborhood.neighborhood_project
return {
'options': [{
@@ -380,7 +380,7 @@ class ProjectController(FeedController):
self._list = ToolListController()
@expose('json:')
- def _nav(self):
+ def _nav(self, **kw):
menu = []
for s in c.project.grouped_navbar_entries():
entry = dict(name=s.label, url=s.url,
@@ -480,7 +480,7 @@ class ProjectController(FeedController):
redirect(g.forge_static('images/user.png'))
@expose('json:')
- def user_search(self, term=''):
+ def user_search(self, term='', **kw):
if len(term) < 3:
raise exc.HTTPBadRequest('"term" param must be at least length 3')
named_roles = RoleCache(
@@ -501,7 +501,7 @@ class ProjectController(FeedController):
for u in users])
@expose('json:')
- def users(self):
+ def users(self, **kw):
users = c.project.users()
if c.user and c.user in users:
users.remove(c.user)
@@ -604,7 +604,7 @@ class NeighborhoodAdminController(object):
return dict(neighborhood=self.neighborhood)
@expose('json:')
- def project_search(self, term=''):
+ def project_search(self, term='', **kw):
if len(term) < 3:
raise exc.HTTPBadRequest('"term" param must be at least length 3')
project_regex = re.compile('(?i)%s' % re.escape(term))
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 699931b..b51d3c7 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -469,15 +469,15 @@ class MergeRequestController(object):
redirect(self.req.url())
@expose('json:')
- def merge_task_status(self):
+ def merge_task_status(self, **kw):
return {'status': self.req.merge_task_status()}
@expose('json:')
- def can_merge_task_status(self):
+ def can_merge_task_status(self, **kw):
return {'status': self.req.can_merge_task_status()}
@expose('json:')
- def can_merge_result(self):
+ def can_merge_result(self, **kw):
"""Return result from the cache. Used by js, after task was completed."""
return {'can_merge': self.req.can_merge()}
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index df5b0ea..2578fa2 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -265,7 +265,7 @@ def rest_has_access(obj, user, perm):
class AppRestControllerMixin(object):
@expose('json:')
- def has_access(self, user, perm):
+ def has_access(self, user, perm, **kw):
return rest_has_access(c.app, user, perm)
@@ -275,7 +275,7 @@ class NeighborhoodRestController(object):
self._neighborhood = neighborhood
@expose('json:')
- def has_access(self, user, perm):
+ def has_access(self, user, perm, **kw):
return rest_has_access(self._neighborhood, user, perm)
@expose()
@@ -335,5 +335,5 @@ class ProjectRestController(object):
return c.project.__json__()
@expose('json:')
- def has_access(self, user, perm):
+ def has_access(self, user, perm, **kw):
return rest_has_access(c.project, user, perm)
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index ee47274..8bcd192 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -434,7 +434,7 @@ class TaskManagerController(object):
redirect('../view/%s' % task._id)
@expose('json:')
- def task_doc(self, task_name):
+ def task_doc(self, task_name, **kw):
"""Return a task's docstring"""
error, doc = None, None
try:
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index c42be86..1447802 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -165,7 +165,7 @@ class WebhookController(BaseController):
@expose('json:')
@require_post()
- def delete(self, webhook):
+ def delete(self, webhook, **kw):
form = self.edit_form(self.sender, self.app)
try:
wh = form.fields['webhook'].to_python(webhook)
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/ForgeShortUrl/forgeshorturl/main.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/main.py b/ForgeShortUrl/forgeshorturl/main.py
index b259e92..5a42ea1 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -204,7 +204,7 @@ class ShortURLAdminController(DefaultAdminController):
@without_trailing_slash
@expose('json:')
- def remove(self, shorturl):
+ def remove(self, shorturl, **kw):
require_access(self.app, 'update')
ShortUrl.query.remove({
'app_config_id': self.app.config._id,
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index ddf570d..47a5d8b 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1093,7 +1093,7 @@ class RootController(BaseController, FeedController):
@expose('json:')
@require_post()
@validate(W.subscribe_form)
- def subscribe(self, subscribe=None, unsubscribe=None):
+ def subscribe(self, subscribe=None, unsubscribe=None, **kw):
if subscribe:
M.Mailbox.subscribe(type='direct')
elif unsubscribe:
@@ -1418,7 +1418,7 @@ class TicketController(BaseController, FeedController):
@without_trailing_slash
@expose('json:')
@require_post()
- def delete(self):
+ def delete(self, **kw):
require_access(self.ticket, 'delete')
M.Shortlink.query.remove(dict(ref_id=self.ticket.index_id()))
self.ticket.deleted = True
@@ -1431,7 +1431,7 @@ class TicketController(BaseController, FeedController):
@without_trailing_slash
@expose('json:')
@require_post()
- def undelete(self):
+ def undelete(self, **kw):
require_access(self.ticket, 'delete')
self.ticket.deleted = False
self.ticket.summary = re.sub(
@@ -1527,7 +1527,7 @@ class TicketController(BaseController, FeedController):
@expose('json:')
@require_post()
@validate(W.subscribe_form)
- def subscribe(self, subscribe=None, unsubscribe=None):
+ def subscribe(self, subscribe=None, unsubscribe=None, **kw):
if subscribe:
self.ticket.subscribe(type='direct')
elif unsubscribe:
@@ -1540,7 +1540,7 @@ class TicketController(BaseController, FeedController):
@expose('json:')
@require_post()
- def vote(self, vote):
+ def vote(self, vote, **kw):
require_authenticated()
require_access(self.ticket, 'post')
status = 'ok'
http://git-wip-us.apache.org/repos/asf/allura/blob/24b410ce/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 513b1e2..d23cff8 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -587,7 +587,7 @@ class PageController(BaseController, FeedController):
@without_trailing_slash
@expose('json:')
@require_post()
- def delete(self):
+ def delete(self, **kw):
require_access(self.page, 'delete')
self.page.delete()
return dict(location='../' + self.page.title + '/?deleted=True')
@@ -595,7 +595,7 @@ class PageController(BaseController, FeedController):
@without_trailing_slash
@expose('json:')
@require_post()
- def undelete(self):
+ def undelete(self, **kw):
require_access(self.page, 'delete')
self.page.deleted = False
M.Shortlink.from_artifact(self.page)