You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/06/05 20:41:57 UTC
[42/50] [abbrv] allura git commit: [#7887] ticket:790 Filter error
messages from nexmo
[#7887] ticket:790 Filter error messages from nexmo
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/55a1aaa7
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/55a1aaa7
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/55a1aaa7
Branch: refs/heads/hs/7873
Commit: 55a1aaa70ee1f3171c6d582b68980ebefffe3785
Parents: bc5aa4b
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jun 4 07:48:35 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jun 4 07:48:35 2015 +0000
----------------------------------------------------------------------
Allura/allura/lib/phone/nexmo.py | 12 +++++++-----
Allura/allura/tests/unit/phone/test_nexmo.py | 14 +++++++++++---
2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/55a1aaa7/Allura/allura/lib/phone/nexmo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/phone/nexmo.py b/Allura/allura/lib/phone/nexmo.py
index 0ee4269..3b28c71 100644
--- a/Allura/allura/lib/phone/nexmo.py
+++ b/Allura/allura/lib/phone/nexmo.py
@@ -46,7 +46,10 @@ class NexmoPhoneService(PhoneService):
}
return dict(params, **common)
- def error(self, msg):
+ def error(self, code=None, msg=None):
+ allowed_codes = ['3', '10', '15', '16', '17']
+ if code is None or str(code) not in allowed_codes:
+ msg = 'Failed sending request to Nexmo'
return {'status': 'error', 'error': msg}
def ok(self, **params):
@@ -68,12 +71,11 @@ class NexmoPhoneService(PhoneService):
log.info('PhoneService (nexmo) response: %s', resp.content)
resp = resp.json()
except Exception:
- msg = 'Failed sending request to Nexmo'
- log.exception(msg)
- return self.error(msg)
+ log.exception('Failed sending request to Nexmo')
+ return self.error()
if resp.get('status') == '0':
return self.ok(request_id=resp.get('request_id'))
- return self.error(resp.get('error_text'))
+ return self.error(code=resp.get('status'), msg=resp.get('error_text'))
def verify(self, number):
url = urljoin(self.BASE_URL, 'verify')
http://git-wip-us.apache.org/repos/asf/allura/blob/55a1aaa7/Allura/allura/tests/unit/phone/test_nexmo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/phone/test_nexmo.py b/Allura/allura/tests/unit/phone/test_nexmo.py
index 6f6ec42..0d9c419 100644
--- a/Allura/allura/tests/unit/phone/test_nexmo.py
+++ b/Allura/allura/tests/unit/phone/test_nexmo.py
@@ -40,7 +40,15 @@ class TestPhoneService(object):
assert_equal(expected, res)
def test_error(self):
- res = self.phone.error('text')
+ res = self.phone.error()
+ expected = {'status': 'error',
+ 'error': 'Failed sending request to Nexmo'}
+ assert_equal(expected, res)
+ # not allowed code
+ res = self.phone.error(code='2', msg='text')
+ assert_equal(expected, res)
+ # allowed code
+ res = self.phone.error(code='15', msg='text')
expected = {'status': 'error', 'error': 'text'}
assert_equal(expected, res)
@@ -73,7 +81,7 @@ class TestPhoneService(object):
req.post.reset_mock()
req.post.return_value.json.return_value = {
- 'status': '1',
+ 'status': '3',
'error_text': 'Something went wrong',
}
resp = self.phone.verify('1234567890')
@@ -116,7 +124,7 @@ class TestPhoneService(object):
req.post.reset_mock()
req.post.return_value.json.return_value = {
- 'status': '1',
+ 'status': '3',
'error_text': 'Something went wrong',
}
resp = self.phone.check('test-req-id', '1234')