From ba49e05c03d74e9086a4dfc5b928d6400bde42c8 Mon Sep 17 00:00:00 2001 From: Shadi Romani Date: Wed, 17 Jul 2024 15:50:35 +0000 Subject: [PATCH] Don't modify private fields --- minfraud/webservice.py | 4 ++-- tests/test_webservice.py | 22 ++++------------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/minfraud/webservice.py b/minfraud/webservice.py index e9cb72a..28556b8 100644 --- a/minfraud/webservice.py +++ b/minfraud/webservice.py @@ -32,6 +32,7 @@ _REQUEST_UA = f"minFraud-API/{__version__} {requests.utils.default_user_agent()}" +_SCHEME = "https" # pylint: disable=too-many-instance-attributes, missing-class-docstring class BaseClient: @@ -57,8 +58,7 @@ def __init__( self._account_id = str(account_id) self._license_key = license_key self._timeout = timeout - - base_uri = f"https://{host}/minfraud/v2.0" + base_uri = f"{_SCHEME}://{host}/minfraud/v2.0" self._score_uri = "/".join([base_uri, "score"]) self._insights_uri = "/".join([base_uri, "insights"]) self._factors_uri = "/".join([base_uri, "factors"]) diff --git a/tests/test_webservice.py b/tests/test_webservice.py index 83e68b3..933e817 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -17,8 +17,10 @@ from minfraud.models import Factors, Insights, Score from minfraud.webservice import AsyncClient, Client +import minfraud.webservice import unittest +minfraud.webservice._SCHEME = "http" class BaseTest(unittest.TestCase): client_class: Union[Type[AsyncClient], Type[Client]] = Client @@ -28,16 +30,7 @@ def setup_httpserver(self, httpserver: HTTPServer): self.httpserver = httpserver def setUp(self): - self.client = self.client_class(42, "abcdef123456") - self.client._base_uri = self.httpserver.url_for("/minfraud/v2.0") - self.client._factors_uri = self.httpserver.url_for("/minfraud/v2.0/factors") - - self.client._insights_uri = self.httpserver.url_for("/minfraud/v2.0/insights") - self.client._score_uri = self.httpserver.url_for("/minfraud/v2.0/score") - self.client._report_uri = self.httpserver.url_for( - "/minfraud/v2.0/transactions/report" - ) - + self.client = self.client_class(42, "abcdef123456",host="{0}:{1}".format(self.httpserver.host,self.httpserver.port)) test_dir = os.path.join(os.path.dirname(__file__), "data") with open(os.path.join(test_dir, self.request_file), encoding="utf-8") as file: content = file.read() @@ -241,14 +234,7 @@ def custom_handler(r): def test_200_with_locales(self): locales = ("fr",) - client = self.client_class(42, "abcdef123456", locales=locales) - client._base_uri = self.httpserver.url_for("/minfraud/v2.0") - client._factors_uri = self.httpserver.url_for("/minfraud/v2.0/factors") - client._insights_uri = self.httpserver.url_for("/minfraud/v2.0/insights") - client._score_uri = self.httpserver.url_for("/minfraud/v2.0/score") - client._report_uri = self.httpserver.url_for( - "minfraud/v2.0/transactions/report" - ) + client = self.client_class(42, "abcdef123456", locales=locales,host="{0}:{1}".format(self.httpserver.host,self.httpserver.port)) model = self.create_success(client=client) response = json.loads(self.response) if self.has_ip_location():