Skip to content

Commit ae44648

Browse files
committed
添加MutexApiParameters异常类
1 parent 9186aa4 commit ae44648

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

chinaapi/utils/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def __init__(self, response, code=0, message='Request Api not found!'):
5656
super(NotExistApi, self).__init__(response, code, message)
5757

5858

59+
class MutexApiParameters(ApiError, ValueError):
60+
"""同时存在两个或两个以上互相排斥的参数"""
61+
62+
def __init__(self, key_list):
63+
super(MutexApiParameters, self).__init__('', '', u'{0}参数只能选择其一'.format(','.join(key_list)))
64+
65+
5966
class OAuth2Error(ApiError):
6067
"""OAuth2异常。"""
6168

tests/utils/test_exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
22
from unittest import TestCase
3-
from chinaapi.utils.exceptions import ApiError
3+
from chinaapi.utils.exceptions import ApiError, MutexApiParameters
44

55

66
class ExceptionTest(TestCase):
@@ -12,3 +12,7 @@ def test_api_error_with_sub(self):
1212
error = ApiError('http://request_url', 404, 'Request Api not found!', 1000, 'sub error msg')
1313
self.assertEqual('[404]: Request Api not found!, [1000]: sub error msg, request: http://request_url',
1414
str(error))
15+
16+
def test_mutex_api_parameters(self):
17+
error = MutexApiParameters(['pic', 'pic_url'])
18+
self.assertEqual(error.message, u'pic,pic_url参数只能选择其一')

0 commit comments

Comments
 (0)