<commit_before>from decimal import Decimal
from six import text_type
from six.moves.urllib.parse import urlencode
from datetime import datetime
from ssl import SSLError

from suds import WebFault
from suds.client import Client
from authorize.data import Address, CreditCard

from authorize.apis.transaction import parse_response
from authorize.exceptions import AuthorizeConnectionError, \
    AuthorizeError, AuthorizeResponseError, AuthorizeInvalidError
from authorize.conf import settings

PROD_URL = 'https://api.authorize.net/soap/v1/Service.asmx?WSDL'
if settings.AUTHORIZE_TEST_URL:
    TEST_URL = settings.AUTHORIZE_TEST_URL
else:
    TEST_URL = 'https://apitest.authorize.net/soap/v1/Service.asmx?WSDL'


class CustomerAPI(object):
    def __init__(self, login_id, transaction_key, debug=True, test=False):
        self.url = TEST_URL if debug else PROD_URL
        self.login_id = login_id
        self.transaction_key = transaction_key
        self.transaction_options = urlencode({
            'x_version': '3.1',
            'x_test_request': 'Y' if test else 'F',
            'x_delim_data': 'TRUE',
            'x_delim_char': ';',
        })

    @property
    def client(self):
        # Lazy instantiation of SOAP client, which hits the WSDL url
        if not hasattr(self, '_client'):
            self._client = Client(self.url)
        return self._client

    @property
    def client_auth(self):
        if not hasattr(self, '_client_auth'):
            self._client_auth = self.client.factory.create(
                'MerchantAuthenticationType')<commit_msg>use getattr for test url to make the logic clearer<commit_after>from decimal import Decimal
from six import text_type
from six.moves.urllib.parse import urlencode
from datetime import datetime
from ssl import SSLError

from suds import WebFault
from suds.client import Client
from authorize.data import Address, CreditCard

from authorize.apis.transaction import parse_response
from authorize.exceptions import AuthorizeConnectionError, \
    AuthorizeError, AuthorizeResponseError, AuthorizeInvalidError
from authorize.conf import settings

PROD_URL = 'https://api.authorize.net/soap/v1/Service.asmx?WSDL'
TEST_URL = getattr(settings, 'AUTHORIZE_TEST_URL', 'https://apitest.authorize.net/soap/v1/Service.asmx?WSDL')


class CustomerAPI(object):
    def __init__(self, login_id, transaction_key, debug=True, test=False):
        self.url = TEST_URL if debug else PROD_URL
        self.login_id = login_id
        self.transaction_key = transaction_key
        self.transaction_options = urlencode({
            'x_version': '3.1',
            'x_test_request': 'Y' if test else 'F',
            'x_delim_data': 'TRUE',
            'x_delim_char': ';',
        })

    @property
    def client(self):
        # Lazy instantiation of SOAP client, which hits the WSDL url
        if not hasattr(self, '_client'):
            self._client = Client(self.url)
        return self._client

    @property
    def client_auth(self):
        if not hasattr(self, '_client_auth'):
            self._client_auth = self.client.factory.create(
                'MerchantAuthenticationType')
{'fraction_non_alphanumeric': 0.08710801393728224, 'fraction_numerical': 0.0025340513145391194, 'mean_word_length': 3.2907608695652173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2069569', 'n_tokens_mistral': 948, 'n_tokens_neox': 915, 'n_words': 243}