Skip to content

Commit efabff5

Browse files
committed
Update parameter type checking
Update parameter type checking in the `CiscoSparkAPI` class. Timeouts should be in intger seconds (not float). `check_type()` should be able to recieve a single type as part of the `acceptable_types` parameter; convert it to a single element tuple to make the error reporting code work.
1 parent 5d511d2 commit efabff5

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

ciscosparkapi/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
RestSession as _RestSession,
5252
)
5353

54+
from .utils import check_type
55+
5456

5557
__author__ = "Chris Lunsford"
5658
__author_email__ = "[email protected]"
@@ -152,15 +154,19 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
152154
CiscoSparkAPI: A new CiscoSparkAPI object.
153155
154156
Raises:
155-
AssertionError: If the parameter types are incorrect.
157+
TypeError: If the parameter types are incorrect.
156158
ciscosparkapiException: If an access token is not provided via the
157159
access_token argument or SPARK_ACCESS_TOKEN environment
158160
variable.
159161
160162
"""
161-
assert access_token is None or isinstance(access_token, basestring)
163+
check_type(access_token, basestring)
164+
check_type(base_url, basestring)
165+
check_type(single_request_timeout, int)
166+
check_type(wait_on_rate_limit, bool)
167+
162168
env_access_token = os.environ.get(ACCESS_TOKEN_ENVIRONMENT_VARIABLE)
163-
access_token = access_token if access_token else env_access_token
169+
access_token = access_token or env_access_token
164170
if not access_token:
165171
error_message = "You must provide an Spark access token to " \
166172
"interact with the Cisco Spark APIs, either via " \

ciscosparkapi/restsession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
# Module Constants
44-
DEFAULT_SINGLE_REQUEST_TIMEOUT = 60.0
44+
DEFAULT_SINGLE_REQUEST_TIMEOUT = 60
4545
DEFAULT_WAIT_ON_RATE_LIMIT = True
4646

4747

ciscosparkapi/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def check_type(o, acceptable_types, may_be_none=True):
120120
object is not an instance of one of the acceptable types.
121121
122122
"""
123+
if not isinstance(acceptable_types, tuple):
124+
acceptable_types = (acceptable_types,)
125+
123126
if may_be_none and o is None:
124127
# Object is None, and that is OK!
125128
pass

0 commit comments

Comments
 (0)