diff --git a/README.rst b/README.rst index 67a087e..c134a5a 100644 --- a/README.rst +++ b/README.rst @@ -51,22 +51,22 @@ The Factors service is called with the ``factors()`` method: .. code-block:: pycon - >>> client.factors({'device': {'ip_address': '81.2.69.160'}}) - >>> await async_client.factors({'device': {'ip_address': '81.2.69.160'}}) + >>> client.factors({'device': {'ip_address': '152.216.7.110'}}) + >>> await async_client.factors({'device': {'ip_address': '152.216.7.110'}}) The Insights service is called with the ``insights()`` method: .. code-block:: pycon - >>> client.insights({'device': {'ip_address': '81.2.69.160'}}) - >>> await async_client.insights({'device': {'ip_address': '81.2.69.160'}}) + >>> client.insights({'device': {'ip_address': '152.216.7.110'}}) + >>> await async_client.insights({'device': {'ip_address': '152.216.7.110'}}) The Score web service is called with the ``score()`` method: .. code-block:: pycon - >>> client.score({'device': {'ip_address': '81.2.69.160'}}) - >>> await async_client.score({'device': {'ip_address': '81.2.69.160'}}) + >>> client.score({'device': {'ip_address': '152.216.7.110'}}) + >>> await async_client.score({'device': {'ip_address': '152.216.7.110'}}) Each of these methods takes a dictionary representing the transaction to be sent to the web service. The structure of this dictionary should be in `the format @@ -84,8 +84,8 @@ Report Transaction web service is called with the ``report()`` method: .. code-block:: pycon - >>> client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'}) - >>> await async_client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'}) + >>> client.report({'ip_address': '152.216.7.110', 'tag': 'chargeback'}) + >>> await async_client.report({'ip_address': '152.216.7.110', 'tag': 'chargeback'}) The method takes a dictionary representing the report to be sent to the web service. The structure of this dictionary should be in `the format specified @@ -141,7 +141,7 @@ Score, Insights and Factors Example >>> >>> request = { >>> 'device': { - >>> 'ip_address': '81.2.69.160', + >>> 'ip_address': '152.216.7.110', >>> 'accept_language': 'en-US,en;q=0.8', >>> 'session_age': 3600, >>> 'session_id': 'a333a4e127f880d8820e56a66f40717c', @@ -172,7 +172,7 @@ Score, Insights and Factors Example >>> 'country': 'US', >>> 'postal': '06510', >>> 'phone_country_code': '1', - >>> 'phone_number': '323-123-4321', + >>> 'phone_number': '123-456-7890', >>> }, >>> 'shipping': { >>> 'first_name': 'John', @@ -185,17 +185,17 @@ Score, Insights and Factors Example >>> 'country': 'US', >>> 'postal': '06510', >>> 'phone_country_code': '1', - >>> 'phone_number': '403-321-2323', + >>> 'phone_number': '123-456-0000', >>> 'delivery_speed': 'same_day', >>> }, >>> 'credit_card': { >>> 'bank_phone_country_code': '1', >>> 'avs_result': 'Y', - >>> 'bank_phone_number': '800-342-1232', + >>> 'bank_phone_number': '123-456-1234', >>> 'last_4_digits': '7643', >>> 'cvv_result': 'N', >>> 'bank_name': 'Bank of No Hope', - >>> 'issuer_id_number': '323132' + >>> 'issuer_id_number': '411111' >>> }, >>> 'payment': { >>> 'decline_code': 'invalid number', @@ -271,7 +271,7 @@ For synchronous reporting: >>> >>> with Client(42, 'licensekey') as client >>> transaction_report = { - >>> 'ip_address': '81.2.69.160', + >>> 'ip_address': '152.216.7.110', >>> 'tag': 'chargeback', >>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa', >>> } @@ -287,7 +287,7 @@ For asynchronous reporting: >>> async def report(): >>> async with AsyncClient(42, 'licensekey') as client >>> transaction_report = { - >>> 'ip_address': '81.2.69.160', + >>> 'ip_address': '152.216.7.110', >>> 'tag': 'chargeback', >>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa', >>> } diff --git a/minfraud/errors.py b/minfraud/errors.py index 43ce283..4e8d93c 100644 --- a/minfraud/errors.py +++ b/minfraud/errors.py @@ -44,7 +44,7 @@ class HTTPError(MinFraudError): def __init__( self, message: str, http_status: Optional[int] = None, uri: Optional[str] = None ) -> None: - super(HTTPError, self).__init__(message) + super().__init__(message) self.http_status = http_status self.uri = uri diff --git a/minfraud/models.py b/minfraud/models.py index 9f91997..a23d675 100644 --- a/minfraud/models.py +++ b/minfraud/models.py @@ -85,7 +85,7 @@ class GeoIP2Location(geoip2.records.Location): def __init__(self, *args, **kwargs) -> None: self.local_time = kwargs.get("local_time", None) - super(GeoIP2Location, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class GeoIP2Country(geoip2.records.Country): @@ -113,7 +113,7 @@ class GeoIP2Country(geoip2.records.Country): def __init__(self, *args, **kwargs) -> None: self.is_high_risk = kwargs.get("is_high_risk", False) - super(GeoIP2Country, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class IPAddress(geoip2.models.Insights): @@ -196,7 +196,7 @@ def __init__(self, ip_address: Dict[str, Any]) -> None: locales = ip_address.get("_locales") if "_locales" in ip_address: del ip_address["_locales"] - super(IPAddress, self).__init__(ip_address, locales=locales) + super().__init__(ip_address, locales=locales) self.country = GeoIP2Country(locales, **ip_address.get("country", {})) self.location = GeoIP2Location(**ip_address.get("location", {})) self.risk = ip_address.get("risk", None) @@ -207,7 +207,7 @@ def __init__(self, ip_address: Dict[str, Any]) -> None: def __setattr__(self, name: str, value: Any) -> None: if hasattr(self, "_finalized") and self._finalized: raise AttributeError("can't set attribute") - super(IPAddress, self).__setattr__(name, value) + super().__setattr__(name, value) @_inflate_to_namedtuple diff --git a/minfraud/webservice.py b/minfraud/webservice.py index 534cb66..ea33bf6 100644 --- a/minfraud/webservice.py +++ b/minfraud/webservice.py @@ -71,7 +71,7 @@ def _prepare_report(self, request: Dict[str, Any], validate: bool): try: validate_report(cleaned_request) except MultipleInvalid as ex: - raise InvalidRequestError("Invalid report data: {0}".format(ex)) + raise InvalidRequestError("Invalid report data: {0}".format(ex)) from ex return cleaned_request def _prepare_transaction(self, request: Dict[str, Any], validate: bool): @@ -80,7 +80,9 @@ def _prepare_transaction(self, request: Dict[str, Any], validate: bool): try: validate_transaction(cleaned_request) except MultipleInvalid as ex: - raise InvalidRequestError("Invalid transaction data: {0}".format(ex)) + raise InvalidRequestError( + "Invalid transaction data: {0}".format(ex) + ) from ex return cleaned_request def _copy_and_clean(self, data: Any) -> Any: @@ -102,14 +104,14 @@ def _handle_success( """Handle successful response.""" try: decoded_body = json.loads(body) - except ValueError: + except ValueError as ex: raise MinFraudError( "Received a 200 response" " but could not decode the response as " "JSON: {0}".format(body), 200, uri, - ) + ) from ex if "ip_address" in body: decoded_body["ip_address"]["_locales"] = self._locales return model_class(decoded_body) # type: ignore diff --git a/tests/data/factors-response.json b/tests/data/factors-response.json index 2e5197f..7b93b66 100644 --- a/tests/data/factors-response.json +++ b/tests/data/factors-response.json @@ -89,7 +89,7 @@ ], "traits": { "domain": "in-addr.arpa", - "ip_address": "81.2.69.160", + "ip_address": "152.216.7.110", "is_anonymous": true, "is_anonymous_vpn": true, "is_hosting_provider": true, diff --git a/tests/data/full-report-request.json b/tests/data/full-report-request.json index 150b4dc..85a3927 100644 --- a/tests/data/full-report-request.json +++ b/tests/data/full-report-request.json @@ -1,5 +1,5 @@ { - "ip_address": "81.2.69.160", + "ip_address": "152.216.7.110", "tag": "chargeback", "chargeback_code": "UA01 Fraud - Card Present Transaction", "maxmind_id": "a1b2c3d4", diff --git a/tests/data/full-transaction-request.json b/tests/data/full-transaction-request.json index 3acfc06..f03dcc9 100644 --- a/tests/data/full-transaction-request.json +++ b/tests/data/full-transaction-request.json @@ -23,7 +23,7 @@ "region": "CT", "country": "US", "postal": "06510", - "phone_number": "323-123-4321", + "phone_number": "123-456-7890", "phone_country_code": "1" }, "shipping": { @@ -36,7 +36,7 @@ "region": "OK", "country": "US", "postal": "73003", - "phone_number": "403-321-2323", + "phone_number": "123-456-0000", "phone_country_code": "1", "delivery_speed": "same_day" }, @@ -46,11 +46,11 @@ "decline_code": "invalid number" }, "credit_card": { - "issuer_id_number": "323132", + "issuer_id_number": "411111", "last_4_digits": "7643", "bank_name": "Bank of No Hope", "bank_phone_country_code": "1", - "bank_phone_number": "800-342-1232", + "bank_phone_number": "123-456-1234", "avs_result": "Y", "cvv_result": "N", "token": "123456abc1234" @@ -80,7 +80,7 @@ } ], "device": { - "ip_address": "81.2.69.160", + "ip_address": "152.216.7.110", "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36", "accept_language": "en-US,en;q=0.8", "session_id": "foobar", diff --git a/tests/data/insights-response.json b/tests/data/insights-response.json index 777bfa8..fe0043d 100644 --- a/tests/data/insights-response.json +++ b/tests/data/insights-response.json @@ -89,7 +89,7 @@ ], "traits": { "domain": "in-addr.arpa", - "ip_address": "81.2.69.160", + "ip_address": "152.216.7.110", "is_anonymous": true, "is_anonymous_vpn": true, "is_hosting_provider": true, diff --git a/tests/test_webservice.py b/tests/test_webservice.py index 5889b7b..987a62e 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -200,7 +200,7 @@ def test_200(self): def test_200_on_request_with_nones(self): model = self.create_success( request={ - "device": {"ip_address": "81.2.69.160", "accept_language": None}, + "device": {"ip_address": "152.216.7.110", "accept_language": None}, "event": {"shop_id": None}, "shopping_cart": [{"category": None, "quantity": 2,}, None], }