From 5dc68d33131140a8401f875f280a13c2eeb1dc1f Mon Sep 17 00:00:00 2001 From: Humberto Morales Date: Tue, 22 Jan 2013 14:58:38 -0800 Subject: [PATCH 1/2] Changed classes to use new-style python classes and cleaned up a few PEP8 issues. --- setup.py | 2 +- telesign/api.py | 209 ++++++++++++++++++++-------------------- telesign/auth.py | 41 ++++---- telesign/exceptions.py | 29 +++--- test/test_auth.py | 17 ++-- test/test_exceptions.py | 20 ++-- test/test_phoneid.py | 19 ++-- test/test_verify.py | 22 ++--- 8 files changed, 175 insertions(+), 184 deletions(-) diff --git a/setup.py b/setup.py index de00a5e..1423915 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from distutils.cmd import Command -version = "1.0.5" +version = "1.0.6" f = open("README.rst") try: diff --git a/telesign/api.py b/telesign/api.py index e46c777..d49d535 100644 --- a/telesign/api.py +++ b/telesign/api.py @@ -8,31 +8,34 @@ import json from random import randint -from telesign.auth import generate_auth_headers, AUTH_METHOD -from telesign.exceptions import * +from telesign.auth import generate_auth_headers +from telesign.exceptions import TelesignError, AuthorizationError __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug" ] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com" __status__ = "Production" + def random_with_N_digits(n): - range_start = 10**(n-1) - range_end = (10**n)-1 + range_start = 10 ** (n - 1) + range_end = (10 ** n) - 1 return randint(range_start, range_end) -class Response(): - def __init__(self, data, http_response,verify_code=None): + +class Response(object): + def __init__(self, data, http_response, verify_code=None): self.data = data self.headers = http_response.headers self.status = http_response.status self.raw_data = http_response.data self.verify_code = verify_code -class servicebase(): + +class ServiceBase(object): def __init__(self, api_host, customer_id, secret_key, ssl=True): self._customer_id = customer_id self._secret_key = secret_key @@ -52,16 +55,17 @@ def _validate_response(self, response): return resp_obj -class PhoneId(servicebase): - """ + +class PhoneId(ServiceBase): + """ The **PhoneId** class exposes three services that each provide detailed information about a specified phone number. .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Attributes - - + - * - `customer_id` - A string value that identifies your TeleSign account. * - `secret_key` @@ -70,29 +74,29 @@ class PhoneId(servicebase): - Specifies whether to use a secure connection with the TeleSign server. Defaults to *True*. * - `api_host` - The Internet host used in the base URI for REST web services. The default is *rest.telesign.com* (and the base URI is https://rest.telesign.com/). - + .. note:: You can obtain both your Customer ID and Secret Key from the `TeleSign Customer Portal `_. """ def __init__(self, customer_id, secret_key, ssl=True, api_host="rest.telesign.com"): - servicebase.__init__(self, api_host, customer_id, secret_key, ssl) + super(PhoneId, self).__init__(api_host, customer_id, secret_key, ssl) def standard(self, phone_number): - """ - Retrieves the standard set of details about the specified phone number. This includes the type of phone (e.g., land line or mobile), and it's approximate geographic location. - + """ + Retrieves the standard set of details about the specified phone number. This includes the type of phone (e.g., land line or mobile), and it's approximate geographic location. + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. - + **Example**:: - + from telesign.api import PhoneId from telesign.exceptions import AuthorizationError, TelesignError @@ -104,39 +108,38 @@ def standard(self, phone_number): try: phone_info = phoneid.standard(phone_number) - + except AuthorizationError as ex: # API authorization failed. Check the API response for details. ... - + except TelesignError as ex: - # Failed to completely execute the PhoneID service. Check the API response + # Failed to completely execute the PhoneID service. Check the API response # for details. Data returned might be incomplete or invalid. ... - + """ resource = "/v1/phoneid/standard/%s" % phone_number headers = generate_auth_headers( - self._customer_id, - self._secret_key, - resource, + self._customer_id, + self._secret_key, + resource, "GET") req = self._pool.request('GET', resource, headers=headers) - return Response(self._validate_response(req), req) def score(self, phone_number, use_case_code): - """ + """ Retrieves a score for the specified phone number. This ranks the phone number's "risk level" on a scale from 0 to 1000, so you can code your web application to handle particular use cases (e.g., to stop things like chargebacks, identity theft, fraud, and spam). - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. * - `use_case_code` @@ -144,8 +147,8 @@ def score(self, phone_number, use_case_code): .. rubric:: Use-case Codes - The following table list the available use-case codes, and includes a description of each. - + The following table list the available use-case codes, and includes a description of each. + ======== ===================================== Code Description ======== ===================================== @@ -164,7 +167,7 @@ def score(self, phone_number, use_case_code): ======== ===================================== **Example**:: - + from telesign.api import PhoneId from telesign.exceptions import AuthorizationError, TelesignError @@ -174,36 +177,35 @@ def score(self, phone_number, use_case_code): use_case_code = "ATCK" phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object. - + try: score_info = phoneid.score(phone_number, use_case_code) except AuthorizationError as ex: ... except TelesignError as ex: ... - + """ resource = "/v1/phoneid/score/%s" % phone_number headers = generate_auth_headers( - self._customer_id, - self._secret_key, - resource, + self._customer_id, + self._secret_key, + resource, "GET") - req = self._pool.request('GET', resource, headers=headers, fields={'ucid':use_case_code}) - + req = self._pool.request('GET', resource, headers=headers, fields={'ucid': use_case_code}) return Response(self._validate_response(req), req) def contact(self, phone_number, use_case_code): - """ + """ In addition to the information retrieved by **standard**, this service provides the Name & Address associated with the specified phone number. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. * - `use_case_code` @@ -211,8 +213,8 @@ def contact(self, phone_number, use_case_code): .. rubric:: Use-case Codes - The following table list the available use-case codes, and includes a description of each. - + The following table list the available use-case codes, and includes a description of each. + ======== ===================================== Code Description ======== ===================================== @@ -229,9 +231,9 @@ def contact(self, phone_number, use_case_code): **OTHR** Other. **UNKN** Unknown/prefer not to say. ======== ===================================== - + **Example**:: - + from telesign.api import PhoneId from telesign.exceptions import AuthorizationError, TelesignError @@ -248,10 +250,10 @@ def contact(self, phone_number, use_case_code): # API authorization failed, the API response should tell you the reason ... except TelesignError as ex: - # failed to completely execute the PhoneID service, check the API response + # failed to completely execute the PhoneID service, check the API response # for details; data returned may be incomplete or not be valid ... - + """ resource = "/v1/phoneid/contact/%s" % phone_number headers = generate_auth_headers( @@ -260,21 +262,20 @@ def contact(self, phone_number, use_case_code): resource, "GET") - req = self._pool.request('GET', resource, headers=headers, fields={'ucid':use_case_code}) - + req = self._pool.request('GET', resource, headers=headers, fields={'ucid': use_case_code}) return Response(self._validate_response(req), req) def live(self, phone_number, use_case_code): - """ + """ In addition to the information retrieved by **standard**, this service provides actionable data associated with the specified phone number. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. * - `use_case_code` @@ -282,8 +283,8 @@ def live(self, phone_number, use_case_code): .. rubric:: Use-case Codes - The following table list the available use-case codes, and includes a description of each. - + The following table list the available use-case codes, and includes a description of each. + ======== ===================================== Code Description ======== ===================================== @@ -300,9 +301,9 @@ def live(self, phone_number, use_case_code): **OTHR** Other. **UNKN** Unknown/prefer not to say. ======== ===================================== - + **Example**:: - + from telesign.api import PhoneId from telesign.exceptions import AuthorizationError, TelesignError @@ -319,10 +320,10 @@ def live(self, phone_number, use_case_code): # API authorization failed, the API response should tell you the reason ... except TelesignError as ex: - # failed to completely execute the PhoneID service, check the API response + # failed to completely execute the PhoneID service, check the API response # for details; data returned may be incomplete or not be valid ... - + """ resource = "/v1/phoneid/live/%s" % phone_number headers = generate_auth_headers( @@ -331,25 +332,25 @@ def live(self, phone_number, use_case_code): resource, "GET") - req = self._pool.request('GET', resource, headers=headers, fields={'ucid':use_case_code}) - + req = self._pool.request('GET', resource, headers=headers, fields={'ucid': use_case_code}) return Response(self._validate_response(req), req) -class Verify(servicebase): + +class Verify(ServiceBase): """ The **Verify** class exposes two services for sending users a verification token (a three to five-digit number). You can use this mechanism to simply test whether you can reach users at the phone number they supplied, or you can have them use the token to authenticate themselves with your web application. - + This class also exposes a service that is used in conjunction with the first two services, in that it allows you to confirm the result of the authentication. - + You can use this verification factor in combination with username & password to provide two-factor authentication for higher security. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Attributes - - + - * - `customer_id` - A string value that identifies your TeleSign account. * - `secret_key` @@ -358,25 +359,25 @@ class Verify(servicebase): - Specifies whether to use a secure connection with the TeleSign server. Defaults to *True*. * - `api_host` - The Internet host used in the base URI for REST web services. The default is *rest.telesign.com* (and the base URI is https://rest.telesign.com/). - + .. note:: You can obtain both your Customer ID and Secret Key from the `TeleSign Customer Portal `_. """ def __init__(self, customer_id, secret_key, ssl=True, api_host="rest.telesign.com"): - servicebase.__init__(self, api_host, customer_id, secret_key, ssl) + super(Verify, self).__init__(api_host, customer_id, secret_key, ssl) def sms(self, phone_number, verify_code=None, language="en", template=""): - """ + """ Sends a text message containing the verification code, to the specified phone number (supported for mobile phones only). - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. * - `verify_code` @@ -424,10 +425,10 @@ def sms(self, phone_number, verify_code=None, language="en", template=""): method = "POST" fields = { - "phone_number":phone_number, - "language":language, - "verify_code":verify_code, - "template":template} + "phone_number": phone_number, + "language": language, + "verify_code": verify_code, + "template": template} headers = generate_auth_headers( self._customer_id, @@ -441,23 +442,23 @@ def sms(self, phone_number, verify_code=None, language="en", template=""): return Response(self._validate_response(req), req, verify_code=verify_code) def call(self, phone_number, verify_code=None, language="en"): - """ + """ Calls the specified phone number, and using speech synthesis, speaks the verification code to the user. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `phone_number` - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. * - `verify_code` - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you. * - `language` - (optional) The written language used in the message. The default is English. - - + + **Example**:: from telesign.api import Verify @@ -496,9 +497,9 @@ def call(self, phone_number, verify_code=None, language="en"): method = "POST" fields = { - "phone_number":phone_number, - "language":language, - "verify_code":verify_code} + "phone_number": phone_number, + "language": language, + "verify_code": verify_code} headers = generate_auth_headers( self._customer_id, @@ -512,20 +513,20 @@ def call(self, phone_number, verify_code=None, language="en"): return Response(self._validate_response(req), req, verify_code=verify_code) def status(self, ref_id, verify_code=None): - """ + """ Retrieves the verification result. You make this call in your web application after users complete the authentication transaction (using either a call or sms). - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Parameters - - + - * - `ref_id` - The Reference ID returned in the response from the TeleSign server, after you called either **call** or **sms**. * - `verify_code` - The verification code received from the user. - + **Example**:: from telesign.api import Verify @@ -552,20 +553,14 @@ def status(self, ref_id, verify_code=None): resource = "/v1/verify/%s" % ref_id headers = generate_auth_headers( - self._customer_id, - self._secret_key, - resource, + self._customer_id, + self._secret_key, + resource, "GET") fields = None if(verify_code != None): - fields = {"verify_code" : verify_code} + fields = {"verify_code": verify_code} req = self._pool.request('GET', resource, headers=headers, fields=fields) - return Response(self._validate_response(req), req) - - - - - diff --git a/telesign/auth.py b/telesign/auth.py index 59e32e3..5a2456b 100644 --- a/telesign/auth.py +++ b/telesign/auth.py @@ -12,63 +12,60 @@ __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", - "Nancy Vitug" ] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com" __status__ = "Production" - AUTH_METHOD = { - 'sha1': {"hash":sha1, "name":"HMAC-SHA1"}, - 'sha256': {"hash":sha256, "name":"HMAC-SHA256"} + 'sha1': {"hash": sha1, "name": "HMAC-SHA1"}, + 'sha256': {"hash": sha256, "name": "HMAC-SHA256"} } + def generate_auth_headers( - customer_id, - secret_key, - resource, - method, + customer_id, + secret_key, + resource, + method, content_type="", auth_method="sha1", fields=None): - now = datetime.datetime.now() stamp = mktime(now.timetuple()) currDate = formatdate( - timeval = stamp, - localtime = False, - usegmt = True + timeval=stamp, + localtime=False, + usegmt=True ) nonce = "%s" % random.random() - if(method in ("POST","PUT")): + if(method in ("POST", "PUT")): content_type = "application/x-www-form-urlencoded" string_to_sign = "%s\n%s\n\nx-ts-auth-method:%s\nx-ts-date:%s\nx-ts-nonce:%s" % ( - method, + method, content_type, AUTH_METHOD[auth_method]["name"], - currDate, + currDate, nonce) if(fields): string_to_sign = string_to_sign + "\n%s" % urllib.urlencode(fields) - string_to_sign = string_to_sign + "\n%s" % resource + string_to_sign = string_to_sign + "\n%s" % resource signer = hmac.new(b64decode(secret_key), string_to_sign, AUTH_METHOD[auth_method]["hash"]) signature = b64encode(signer.digest()) - headers = { - "Authorization" : "TSA %s:%s" % (customer_id, signature), - "x-ts-date" : currDate, - "x-ts-auth-method" : AUTH_METHOD[auth_method]["name"], - "x-ts-nonce" : nonce + "Authorization": "TSA %s:%s" % (customer_id, signature), + "x-ts-date": currDate, + "x-ts-auth-method": AUTH_METHOD[auth_method]["name"], + "x-ts-nonce": nonce } return headers diff --git a/telesign/exceptions.py b/telesign/exceptions.py index cd953e1..c31b5fc 100644 --- a/telesign/exceptions.py +++ b/telesign/exceptions.py @@ -7,7 +7,7 @@ __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug" ] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com" @@ -17,13 +17,13 @@ class TelesignError(Exception): """ The **exceptions** base class. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Attributes - - + - * - `data` - The data returned by the service, in a dictionary form. * - `http_response` @@ -32,7 +32,7 @@ class TelesignError(Exception): """ def __init__(self, data, http_response): - self.errors = data["errors"]; + self.errors = data["errors"] self.headers = http_response.headers self.status = http_response.status self.data = http_response.data @@ -40,7 +40,7 @@ def __init__(self, data, http_response): def __str__(self): result = "" - for x in xrange(0,len(self.errors)): + for x in xrange(0, len(self.errors)): result += "%s\n" % self.errors[x]["description"] return result @@ -49,39 +49,40 @@ def __str__(self): class AuthorizationError(TelesignError): """ Either the client failed to authenticate with the REST API server, or the service cannot be executed using the specified credentials. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Attributes - - + - * - `data` - The data returned by the service, in a dictionary form. * - `http_response` - The full HTTP Response object, including the HTTP status code, headers, and raw returned data. """ - + def __init__(self, data, http_response): TelesignError.__init__(self, data, http_response) + class ValidationError(TelesignError): """ The submitted data failed the intial validation, and the service was not executed. - + .. list-table:: :widths: 5 30 :header-rows: 1 - + * - Attributes - - + - * - `data` - The data returned by the service, in a dictionary form. * - `http_response` - The full HTTP Response object, including the HTTP status code, headers, and raw returned data. """ - + def __init__(self, data, http_response): TelesignError.__init__(self, data, http_response) diff --git a/test/test_auth.py b/test/test_auth.py index d03e318..6d48992 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -2,16 +2,16 @@ import mock import telesign.api import random -import datetime + class AuthTest(unittest.TestCase): '''Test for phone id telesign sdk''' - + def setUp(self): self.expected_cid = "99999999-1F7E-11E1-B760-000000000000" self.expected_secret_key = "8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M==" self.expected_resource = "/foo/bar/baz/" - + def tearDown(self): pass @@ -32,7 +32,7 @@ def test_nonce_is_set(self, random_mock): self.expected_resource, "GET") - self.assertEqual(headers["x-ts-nonce"], expected_nonce, "Nonce header did not match") + self.assertEqual(headers["x-ts-nonce"], expected_nonce, "Nonce header did not match") def test_date_is_set(self): headers = telesign.api.generate_auth_headers( @@ -42,7 +42,7 @@ def test_date_is_set(self): "GET") # Can't mock datetime - self.assertIsNotNone(headers["x-ts-date"]) + self.assertIsNotNone(headers["x-ts-date"]) def test_sha1__default_auth_method(self): expected_auth_method = "HMAC-SHA1" @@ -53,7 +53,7 @@ def test_sha1__default_auth_method(self): self.expected_resource, "GET") - self.assertEqual(headers["x-ts-auth-method"], expected_auth_method, "Auth method did not match") + self.assertEqual(headers["x-ts-auth-method"], expected_auth_method, "Auth method did not match") def test_sha256_auth_method(self): expected_auth_method = "HMAC-SHA256" @@ -65,7 +65,7 @@ def test_sha256_auth_method(self): "", "sha256") - self.assertEqual(headers["x-ts-auth-method"], expected_auth_method, "Auth method did not match") + self.assertEqual(headers["x-ts-auth-method"], expected_auth_method, "Auth method did not match") def test_customer_id_in_auth(self): expected_auth_start = "TSA %s:" % self.expected_cid @@ -75,5 +75,4 @@ def test_customer_id_in_auth(self): self.expected_resource, "GET") - self.assertTrue(headers["Authorization"].startswith(expected_auth_start), "Authorization did not start with TSA and customer ID") - + self.assertTrue(headers["Authorization"].startswith(expected_auth_start), "Authorization did not start with TSA and customer ID") diff --git a/test/test_exceptions.py b/test/test_exceptions.py index aab41a5..9548758 100644 --- a/test/test_exceptions.py +++ b/test/test_exceptions.py @@ -3,19 +3,20 @@ import telesign.api import telesign.exceptions + class ExceptionTestTest(unittest.TestCase): '''Test for exceptions in telesign sdk''' - + def setUp(self): - self.expected_errors = [ { "code": 1, "description": "Error 1" }, { "code": 2, "description": "Error 2" } ] - self.expected_headers = { "a": "AA", "b": "BB" } + self.expected_errors = [{"code": 1, "description": "Error 1"}, {"code": 2, "description": "Error 2"}] + self.expected_headers = {"a": "AA", "b": "BB"} self.expected_status = "200" self.expected_data = "abcdefg" self.expected_http_response = mock.Mock() self.expected_http_response .headers = self.expected_headers self.expected_http_response .status = self.expected_status - self.expected_http_response .data = self.expected_data - + self.expected_http_response .data = self.expected_data + def tearDown(self): pass @@ -32,21 +33,18 @@ def __validate_exception_properties(self, x): def test_properties_are_populated_in_TelesignError(self): try: - raise telesign.exceptions.TelesignError({ "errors": self.expected_errors }, self.expected_http_response) + raise telesign.exceptions.TelesignError({"errors": self.expected_errors}, self.expected_http_response) except telesign.exceptions.TelesignError as x: self.__validate_exception_properties(x) def test_properties_are_populated_in_AuthorizationError(self): try: - raise telesign.exceptions.AuthorizationError({ "errors": self.expected_errors }, self.expected_http_response) + raise telesign.exceptions.AuthorizationError({"errors": self.expected_errors}, self.expected_http_response) except telesign.exceptions.AuthorizationError as x: self.__validate_exception_properties(x) def test_properties_are_populated_in_ValidationError(self): try: - raise telesign.exceptions.ValidationError({ "errors": self.expected_errors }, self.expected_http_response) + raise telesign.exceptions.ValidationError({"errors": self.expected_errors}, self.expected_http_response) except telesign.exceptions.ValidationError as x: self.__validate_exception_properties(x) - - - diff --git a/test/test_phoneid.py b/test/test_phoneid.py index 1e6cd82..b000464 100644 --- a/test/test_phoneid.py +++ b/test/test_phoneid.py @@ -3,16 +3,17 @@ import telesign.api import urllib3 + class PhoneIdTest(unittest.TestCase): '''Test for phone id telesign sdk''' - + def setUp(self): self.expected_cid = "99999999-1F7E-11E1-B760-000000000000" self.expected_secret_key = "8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M==" self.expected_phone_no = "12343455678" self.expected_data = "{ \"a\": \"AA\", \"b\":\"BB\" }" self.expected_resource = "/v1/phoneid/%s/%s" - + def tearDown(self): pass @@ -25,7 +26,7 @@ def test_standard_phoneid(self, req_mock): req_mock.return_value = response p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) - r = p.standard(self.expected_phone_no) + p.standard(self.expected_phone_no) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -43,7 +44,7 @@ def test_standard_phoneid_unauthorized(self, req_mock): p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) with self.assertRaises(telesign.exceptions.AuthorizationError): - r = p.standard(self.expected_phone_no) + p.standard(self.expected_phone_no) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -61,7 +62,7 @@ def test_standard_phoneid_other_error(self, req_mock): p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) with self.assertRaises(telesign.exceptions.TelesignError): - r = p.standard(self.expected_phone_no) + p.standard(self.expected_phone_no) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -77,7 +78,7 @@ def test_score_phoneid(self, req_mock): req_mock.return_value = response p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) - r = p.score(self.expected_phone_no, 'OTHR') + p.score(self.expected_phone_no, 'OTHR') self.assertTrue(req_mock.called) args = req_mock.call_args @@ -93,7 +94,7 @@ def test_contact_phoneid(self, req_mock): req_mock.return_value = response p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) - r = p.contact(self.expected_phone_no, 'OTHR') + p.contact(self.expected_phone_no, 'OTHR') self.assertTrue(req_mock.called) args = req_mock.call_args @@ -109,9 +110,9 @@ def test_live_phoneid(self, req_mock): req_mock.return_value = response p = telesign.api.PhoneId(self.expected_cid, self.expected_secret_key) - r = p.live(self.expected_phone_no, 'OTHR') + p.live(self.expected_phone_no, 'OTHR') self.assertTrue(req_mock.called) args = req_mock.call_args self.assertEqual(args[0][0], "GET", "Expected GET") - self.assertEqual(args[0][1], self.expected_resource % ('live', self.expected_phone_no), "Phone ID resource name is incorrect") \ No newline at end of file + self.assertEqual(args[0][1], self.expected_resource % ('live', self.expected_phone_no), "Phone ID resource name is incorrect") diff --git a/test/test_verify.py b/test/test_verify.py index 5800ad3..506d48a 100644 --- a/test/test_verify.py +++ b/test/test_verify.py @@ -3,21 +3,22 @@ import telesign.api import urllib3 + class VerifyTest(unittest.TestCase): '''Test for Verify telesign sdk''' - + def setUp(self): self.expected_cid = "99999999-1F7E-11E1-B760-000000000000" self.expected_secret_key = "8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M==" self.expected_phone_no = "12343455678" self.expected_language = "en" self.expected_verify_code = 54321 - self.expected_ref_id = "99999999999999999" + self.expected_ref_id = "99999999999999999" self.expected_data = "{ \"a\": \"AA\", \"b\":\"BB\" }" self.expected_sms_resource = "/v1/verify/sms" self.expected_call_resource = "/v1/verify/call" self.expected_status_resource = "/v1/verify/%s" % self.expected_ref_id - + def tearDown(self): pass @@ -30,7 +31,7 @@ def test_verify_sms(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.sms(self.expected_phone_no, self.expected_verify_code, self.expected_language) + p.sms(self.expected_phone_no, self.expected_verify_code, self.expected_language) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -49,7 +50,7 @@ def test_verify_call(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.call(self.expected_phone_no, self.expected_verify_code, self.expected_language) + p.call(self.expected_phone_no, self.expected_verify_code, self.expected_language) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -68,7 +69,7 @@ def test_verify_sms_default_code(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.sms(self.expected_phone_no, language=self.expected_language) + p.sms(self.expected_phone_no, language=self.expected_language) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -87,7 +88,7 @@ def test_verify_call_default_code(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.call(self.expected_phone_no, language=self.expected_language) + p.call(self.expected_phone_no, language=self.expected_language) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -95,7 +96,7 @@ def test_verify_call_default_code(self, req_mock): self.assertEqual(args[0][1], self.expected_call_resource, "Call verify resource was incorrect") self.assertEqual(args[1]["fields"]["phone_number"], self.expected_phone_no, "Phone number field did not match") self.assertEqual(args[1]["fields"]["language"], self.expected_language, "Language field did not match") - self.assertEqual(len("%s" % args[1]["fields"]["verify_code"]), 5, "Expected default verify code to be 5 digits") + self.assertEqual(len("%s" % args[1]["fields"]["verify_code"]), 5, "Expected default verify code to be 5 digits") @mock.patch.object(urllib3.HTTPConnectionPool, "request") def test_status_check(self, req_mock): @@ -106,7 +107,7 @@ def test_status_check(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.status(self.expected_ref_id) + p.status(self.expected_ref_id) self.assertTrue(req_mock.called) args = req_mock.call_args @@ -122,11 +123,10 @@ def test_report_code(self, req_mock): req_mock.return_value = response p = telesign.api.Verify(self.expected_cid, self.expected_secret_key) - r = p.status(self.expected_ref_id, self.expected_verify_code) + p.status(self.expected_ref_id, self.expected_verify_code) self.assertTrue(req_mock.called) args = req_mock.call_args self.assertEqual(args[0][0], "GET", "Expected GET") self.assertEqual(args[0][1], self.expected_status_resource, "Status resource was incorrect") self.assertEqual(args[1]["fields"]["verify_code"], self.expected_verify_code, "Verify code did not match") - \ No newline at end of file From ce339657c9ab8e4932f0c56b6dec2b9f0fd81c26 Mon Sep 17 00:00:00 2001 From: Humberto Morales Date: Tue, 22 Jan 2013 15:51:56 -0800 Subject: [PATCH 2/2] Added name to contrib list. --- telesign/api.py | 2 +- telesign/auth.py | 2 +- telesign/exceptions.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telesign/api.py b/telesign/api.py index d49d535..23ea873 100644 --- a/telesign/api.py +++ b/telesign/api.py @@ -13,7 +13,7 @@ __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug", "Humberto Morales"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com" diff --git a/telesign/auth.py b/telesign/auth.py index 5a2456b..3658431 100644 --- a/telesign/auth.py +++ b/telesign/auth.py @@ -12,7 +12,7 @@ __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug", "Humberto Morales"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com" diff --git a/telesign/exceptions.py b/telesign/exceptions.py index c31b5fc..d5f7b93 100644 --- a/telesign/exceptions.py +++ b/telesign/exceptions.py @@ -7,7 +7,7 @@ __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean" __copyright__ = "Copyright 2012, TeleSign Corp." -__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug"] +__credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug", "Humberto Morales"] __license__ = "MIT" __maintainer__ = "Jeremy Cunningham" __email__ = "support@telesign.com"