incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1491127 - in /incubator/public/trunk/tools: src/asf/utils/committers.py tests/test_committers.py
Date Sun, 09 Jun 2013 02:45:33 GMT
Author: adc
Date: Sun Jun  9 02:45:32 2013
New Revision: 1491127

URL: http://svn.apache.org/r1491127
Log:
Better handling of non-existent committers and bad emails.

Modified:
    incubator/public/trunk/tools/src/asf/utils/committers.py
    incubator/public/trunk/tools/tests/test_committers.py

Modified: incubator/public/trunk/tools/src/asf/utils/committers.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/src/asf/utils/committers.py?rev=1491127&r1=1491126&r2=1491127&view=diff
==============================================================================
--- incubator/public/trunk/tools/src/asf/utils/committers.py (original)
+++ incubator/public/trunk/tools/src/asf/utils/committers.py Sun Jun  9 02:45:32 2013
@@ -17,13 +17,17 @@
 # under the License.
 #
 import json
-from restkit import Resource, BasicAuth
+from logging import getLogger
+
+from restkit import Resource, BasicAuth, ResourceNotFound
 
 from asf.utils.emails import canonical_email_address
 
 
 COMMITTERS_URL = 'https://whimsy.apache.org/roster/committer'
 
+log = getLogger(__name__)
+
 
 class Committer(object):
     def __init__(self, username, member, fullname, emails, urls, committees, projects, mentoring):
@@ -55,22 +59,32 @@ COMMITTERS = {}
 def get_committer(committer, username, password):
     global COMMITTERS
     if committer not in COMMITTERS:
-        committer_json = json.loads(Resource('%s/%s' % (COMMITTERS_URL, committer),
-                                             filters=[BasicAuth(username, password)],
-                                             timeout=10).get(headers={'Accept': 'application/json'}).body_string())
-
-        availid = committer_json['availid']
-        member = bool(committer_json['member'])
-        fullname = committer_json['name']
-        emails = [canonical_email_address(email) for email in committer_json['emails']]
-        urls = committer_json['urls']
-        committees = committer_json['committees']
-        projects = set(committer_json['groups'])
-        if 'apsite' in projects: projects.remove('apsite')
-        if 'committers' in projects: projects.remove('committers')
-        if 'member' in projects: projects.remove('member')
-        mentoring = committer_json['auth']
+        try:
+            committer_json = json.loads(Resource('%s/%s' % (COMMITTERS_URL, committer),
+                                                 filters=[BasicAuth(username, password)],
+                                                 timeout=10).get(headers={'Accept': 'application/json'}).body_string())
+        except ResourceNotFound:
+            log.warning('Unable to find committer %s' % committer)
+        else:
+            availid = committer_json['availid']
+            member = bool(committer_json['member'])
+            fullname = committer_json['name']
+
+            emails = set()
+            for email in committer_json['emails']:
+                try:
+                    emails.add(canonical_email_address(email))
+                except ValueError:
+                    log.warning('Malformed email address %s not added to committer %s', email,
committer)
+
+            urls = committer_json['urls']
+            committees = committer_json['committees']
+            projects = set(committer_json['groups'])
+            if 'apsite' in projects: projects.remove('apsite')
+            if 'committers' in projects: projects.remove('committers')
+            if 'member' in projects: projects.remove('member')
+            mentoring = committer_json['auth']
 
-        COMMITTERS[committer] = Committer(availid, member, fullname, emails, urls, committees,
projects, mentoring)
+            COMMITTERS[committer] = Committer(availid, member, fullname, emails, urls, committees,
projects, mentoring)
 
     return COMMITTERS[committer]

Modified: incubator/public/trunk/tools/tests/test_committers.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/tests/test_committers.py?rev=1491127&r1=1491126&r2=1491127&view=diff
==============================================================================
--- incubator/public/trunk/tools/tests/test_committers.py (original)
+++ incubator/public/trunk/tools/tests/test_committers.py Sun Jun  9 02:45:32 2013
@@ -18,7 +18,6 @@
 #
 from nose.plugins.attrib import attr
 
-from asf.utils.auth import get_username, get_password, AUTH_SECTION
 from asf.utils.committers import get_committer
 from asf.utils.test import ensure_credentials_stored
 
@@ -36,3 +35,13 @@ def test_get_committer(username, passwor
     assert 'chukwa' in committer.mentoring
 
     assert committer is get_committer('adc', username, password)
+
+
+@attr('integration')
+@ensure_credentials_stored
+def test_get_non_existent_committer(username, password):
+    try:
+        get_committer('pookie', username, password)
+        assert False, 'pookie is not a committer, yet...'
+    except KeyError:
+        pass



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message