def test_not_load_save(self): conf_ori = utils.Configuration() conf = utils.Configuration() conf.proxy = 'TestCase %d' % random.randint(0,100) conf.url = 'TestCase %d' % random.randint(0,100) conf.save() conf_new = utils.Configuration() conf_ori.save() self.assertEquals(conf.proxy, conf_new.proxy) self.assertEquals(conf.url, conf_new.url) self.assertNotEqual(conf_ori.url, conf_new.url)
# IF YOU ARE RUNNING THIS ON THE ECOM VMS: # - This file needs to be run as root # MAKE SURE YOU HAVE COMMENTED OUT THE REDUNDANCIES IN cnpOnline: # vendorCredit, vendorDebit, submerchantCredit, submerchantDebit, customerCredit, customerDebit from __future__ import absolute_import, division, print_function import os import sys package_root = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) sys.path.insert(0, package_root) from vantivsdk import utils version = utils.Configuration().VERSION xsd_name = 'SchemaCombined_v%s.xsd' % version # Since PyXB doesn't like complex paths if os.path.dirname(os.path.abspath(__file__)) != os.getcwd(): print('Please run this in the tools directory.') sys.exit(0) # Run pregen print('Generate %s' % xsd_name) pre_gen_path = os.path.join(package_root, 'tools', 'preGeneration.py') os.system('python %s' % pre_gen_path) # print('Generate module fields using pyxb') xsd_abs_path = os.path.join(package_root, xsd_name)
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. import os import sys import unittest from unittest import mock import six package_root = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) sys.path.insert(0, package_root) from vantivsdk import (utils, batch, fields) conf = utils.Configuration() class TestBatch(unittest.TestCase): def test_Transactions_add_normal_txn(self): txns = batch.Transactions() for i in range(1,3): transaction = fields.authorization() txns.add(transaction) self.assertEquals(False, txns.is_rfr_request) self.assertEquals(2, len(txns.transactions)) def test_Transactions_add_rfrrequest(self): txns = batch.Transactions() transaction = fields.RFRRequest() txns.add(transaction)
class TestCommManagerMultiThreaded(unittest.TestCase): threadCount = 10 cycleCount = 100 config = utils.Configuration() config.multiSite = True successCount = 0 failedCount = 0 def multiThreadTests(self, threadId): startTime = (int(round(time.time() * 1000))) totalTransactionTime = 0 requestCount = 0 for i in range(1, self.cycleCount + 1): requestCount += 1 target = commManager(self.config).manager.findUrl() try: sleepTime = (100 + random.randint(0, 500)) / 1000 totalTransactionTime += sleepTime time.sleep(sleepTime) except Exception: traceback.print_exc() target.reportResult(target, 1, 200) duration = (int(round(time.time() * 1000))) - startTime print("Thread " + str(threadId) + " completed. Total Requests:" + str(requestCount) + " Elapsed Time:" + str((duration / 1000)) + " secs Average Txn Time:" + str((totalTransactionTime / requestCount)) + " ms") def test_multiThreaded_without_request(self): pool = ThreadPool(self.threadCount) id = list(range(1, self.threadCount + 1)) pool.map(self.multiThreadTests, id) def multiThreadTests_with_request(self, threadId): startTime = (int(round(time.time() * 1000))) totalTransactionTime = 0 requestCount = 0 self.successCount = 0 self.failedCount = 0 for i in range(1, self.cycleCount + 1): requestCount += 1 totalTransactionTime += self.doCycle(threadId) try: sleepTime = (random.randint(0, 50)) / 1000 time.sleep(sleepTime) except Exception: traceback.print_exc() duration = (int(round(time.time() * 1000))) - startTime print("Thread " + str(threadId) + " completed. Total Requests:" + str(requestCount) + " Success:" + str(self.successCount) + " Failed:" + str(self.failedCount) + " Elapsed Time:" + str((duration / 1000)) + " secs Average Txn Time:" + str((totalTransactionTime / requestCount)) + " ms") def doCycle(self, threadId): authorization = fields.authorization() authorization.reportGroup = '123456' authorization.orderId = str(threadId - (int(round(time.time() * 1000)))) authorization.amount = '106' authorization.orderSource = 'ecommerce' authorization.id = 'id' + str(threadId) card = fields.cardType() card.number = '4100000000000000' card.expDate = '1210' card.type = 'VI' authorization.card = card startTime = (int(round(time.time() * 1000))) response = online.request(authorization, self.config) # print(response) responseTime = (int(round(time.time() * 1000))) - startTime self.assertEquals("123456", response['authorizationResponse']['@reportGroup']) if (response['authorizationResponse']['response'] == '000'): self.successCount += 1 else: self.failedCount += 1 return responseTime def test_multiThreaded_with_request(self): pool = ThreadPool(self.threadCount) id = list(range(1, self.threadCount + 1)) pool.map(self.multiThreadTests_with_request, id) def test_findUrl(self): target = commManager(self.config).manager doMultiSite_record = target.doMultiSite printDebug_record = target.printDebug currentMultiSiteUrlIndex_reCord = target.currentMultiSiteUrlIndex errorCount_record = target.errorCount lastSiteSwitchTime_record = target.lastSiteSwitchTime # condition1: doMultiSite as false target.doMultiSite = False url = target.legacyUrl self.assertEquals(url, target.findUrl()['targetUrl']) target.doMultiSite = doMultiSite_record # condition2 target.doMultiSite = True target.printDebug = True target.currentMultiSiteUrlIndex = 0 url = target.multiSiteUrls[0] self.assertEquals(url, target.findUrl()['targetUrl']) target.doMultiSite = doMultiSite_record target.printDebug = printDebug_record target.currentMultiSiteUrlIndex = currentMultiSiteUrlIndex_reCord # condition3 target.doMultiSite = True target.printDebug = True target.errorCount = 100 target.currentMultiSiteUrlIndex = 0 url = target.multiSiteUrls[1] self.assertEquals(url, target.findUrl()['targetUrl']) target.doMultiSite = doMultiSite_record target.printDebug = printDebug_record target.errorCount = errorCount_record target.currentMultiSiteUrlIndex = currentMultiSiteUrlIndex_reCord target.lastSiteSwitchTime = lastSiteSwitchTime_record # condition4 target.doMultiSite = True target.printDebug = True target.errorCount = 100 target.currentMultiSiteUrlIndex = 1 url = target.multiSiteUrls[0] self.assertEquals(url, target.findUrl()['targetUrl']) target.doMultiSite = doMultiSite_record target.printDebug = printDebug_record target.errorCount = errorCount_record target.currentMultiSiteUrlIndex = currentMultiSiteUrlIndex_reCord target.lastSiteSwitchTime = lastSiteSwitchTime_record
def ask_user(): attrs = [ 'user', 'password', 'merchantId', 'reportGroup', 'url', 'proxy', 'sftp_username', 'sftp_password', 'sftp_url', 'batch_requests_path', 'batch_response_path', # 'fast_url', # 'fast_ssl', # 'fast_port', 'print_xml', 'id', 'deleteBatchFiles', 'useEncryption', 'vantivPublicKeyID', 'gpgPassphrase' ] attr_dict = { 'user': '', 'password': '', 'merchantId': '', 'reportGroup': 'Default Report Group', 'url': 'sandbox', 'proxy': '', 'sftp_username': '', 'sftp_password': '', 'sftp_url': '', 'batch_requests_path': os.path.join(tempfile.gettempdir(), 'vantiv_sdk_batch_request'), 'batch_response_path': os.path.join(tempfile.gettempdir(), 'vantiv_sdk_batch_response'), # 'fast_url': '', # 'fast_ssl': 'y', # 'fast_port': '', 'print_xml': 'n', 'id': '', 'deleteBatchFiles': 'y', 'useEncryption': 'y', 'vantivPublicKeyID': '', 'gpgPassphrase': '', 'multiSiteUrl1': '', 'multiSiteUrl2': '', 'multiSite': 'False', 'printMultiSiteDebug': 'False', 'multiSiteErrorThreshold': '5', 'maxHoursWithoutSwitch': '48' } attr_valid_dict = { 'url': { 'sandbox': [ 'https://www.testvantivcnp.com/sandbox/communicator/online', 'https://www.testvantivcnp.com/sandbox/new/sandbox/communicator/online', 'https://www.testvantivcnp.com/sandbox/new/sandbox/communicator/online' ], 'prelive': [ 'https://payments.vantivprelive.com/vap/communicator/online', 'https://payments.east.vantivprelive.com/vap/communicator/online', 'https://payments.west.vantivprelive.com/vap/communicator/online' ], 'postlive': [ 'https://payments.vantivpostlive.com/vap/communicator/online', 'https://payments.east.vantivpostlive.com/vap/communicator/online', 'https://payments.west.vantivpostlive.com/vap/communicator/online' ], 'prod': [ 'https://payments.vantivcnp.com/vap/communicator/online', 'https://payments.east.vantivcnp.com/vap/communicator/online', 'https://payments.west.vantivcnp.com/vap/communicator/online' ], 'transactprelive': 'https://transact.vantivprelive.com/vap/communicator/online', 'transactpostlive': 'https://transact.vantivpostlive.com/vap/communicator/online', 'transactprod': 'https://transact.vantivcnp.com/vap/communicator/online' }, # 'fast_ssl': { # 'y': True, # 'n': False, # }, 'print_xml': { 'y': True, 'n': False, } } attr_des_dict = { 'user': '******', 'password': '******', 'merchantId': 'Your merchantId:', 'reportGroup': 'Your default report group:', 'url': 'URL for you online request', 'proxy': 'If you want to using https proxy, please input your proxy server address. Must start with "https://"', 'sftp_username': '******', 'sftp_password': '******', 'sftp_url': 'Please input your sftp address:', 'batch_requests_path': 'Please input location for saving generated batch request xml:', 'batch_response_path': 'Please input location for saving batch response xml', # 'fast_url': 'Please input fast address, using for batch stream:', # 'fast_ssl': 'Using ssl for fast stream? y for Yes, n for No.', # 'fast_port': 'Please input fast port, using for batch stream', 'print_xml': 'Do you want to print xml in console? y for Yes, n for No.', 'id': 'cnpRequest id for batch', 'deleteBatchFiles': 'Do you want to delete xml batch files after the data is retrieved? y for Yes, n for No.', 'useEncryption': 'Are you a pgp enabled presenter? y for Yes, n for No.', 'vantivPublicKeyID': 'What is the ID of Vantiv\'s public key on your keyring?', 'gpgPassphrase': 'What is the passphrase of the gpg key you will use to decrypt the batches?' } print(CC.bpurple('Vantiv eCommerce Python SDK configuration!')) print(''' Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets).''') for attr in attrs: while True: print(gene_prompt(attr, attr_dict, attr_valid_dict, attr_des_dict)) if six.PY3: x = input('') else: x = raw_input('') if not x: x = attr_dict[attr] if attr in attr_valid_dict: if x.lower() in attr_valid_dict[attr]: x = attr_valid_dict[attr][x.lower()] else: print('Invalid input for "%s" = "%s"' % (attr, x)) continue if (isinstance(x, list)): attr_dict[attr] = x[0] attr_dict['multiSiteUrl1'] = x[1] attr_dict['multiSiteUrl2'] = x[2] else: attr_dict[attr] = x break conf = utils.Configuration() for k in attr_dict: setattr(conf, k, attr_dict[k]) print(CC.bgreen('Configurations have saved at: %s ' % conf.save())) print(CC.bpurple('Successful!'))
def ask_user(): attrs = [ 'user', 'password', 'merchantId', 'reportGroup', 'url', 'proxy', 'sftp_username', 'sftp_password', 'sftp_url', 'batch_requests_path', 'batch_response_path', 'fast_url', 'fast_ssl', 'fast_port', 'print_xml', 'id' ] attr_dict = { 'user': '', 'password': '', 'merchantId': '', 'reportGroup': 'Default Report Group', 'url': 'sandbox', 'proxy': '', 'sftp_username': '', 'sftp_password': '', 'sftp_url': '', 'batch_requests_path': os.path.join(tempfile.gettempdir(), 'vantiv_sdk_batch_request'), 'batch_response_path': os.path.join(tempfile.gettempdir(), 'vantiv_sdk_batch_response'), 'fast_url': '', 'fast_ssl': 'y', 'fast_port': '', 'print_xml': 'n', 'id': '' } attr_valid_dict = { 'url': { 'sandbox': 'https://www.testvantivcnp.com/sandbox/communicator/online', 'prelive': 'https://payments.vantivprelive.com/vap/communicator/online', 'postlive': 'https://payments.vantivpostlive.com/vap/communicator/online', 'prod': 'https://payments.vantivcnp.com/vap/communicator/online', 'transactprelive': 'https://transact.vantivprelive.com/vap/communicator/online', 'transactpostlive': 'https://transact.vantivpostlive.com/vap/communicator/online', 'transactprod': 'https://transact.vantivcnp.com/vap/communicator/online' }, 'fast_ssl': { 'y': True, 'n': False, }, 'print_xml': { 'y': True, 'n': False, } } attr_des_dict = { 'user': '******', 'password': '******', 'merchantId': 'Your merchantId:', 'reportGroup': 'Your default report group:', 'url': 'URL for you online request', 'proxy': 'If you want to using https proxy, please input your proxy server address. Must start with "https://"', 'sftp_username': '******', 'sftp_password': '******', 'sftp_url': 'Please input your sftp address:', 'batch_requests_path': 'Please input location for saving generated batch request xml:', 'batch_response_path': 'Please input location for saving batch response xml', 'fast_url': 'Please input fast address, using for batch stream:', 'fast_ssl': 'Using ssl for fast stream? y for Yes, n for No.', 'fast_port': 'Please input fast port, using for batch stream', 'print_xml': 'Do you want to print xml in console? y for Yes, n for No.', 'id': 'litleRequest id for batch' } print(CC.bpurple('Vantiv eCommerce Python SDK configuration!')) print(''' Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets).''') for attr in attrs: while True: print(gene_prompt(attr, attr_dict, attr_valid_dict, attr_des_dict)) if six.PY3: x = input('') else: x = raw_input('') if not x: x = attr_dict[attr] if attr in attr_valid_dict: if x.lower() in attr_valid_dict[attr]: x = attr_valid_dict[attr][x.lower()] else: print('Invalid input for "%s" = "%s"' % (attr, x)) continue attr_dict[attr] = x break conf = utils.Configuration() for k in attr_dict: setattr(conf, k, attr_dict[k]) print(CC.bgreen('Configurations have saved at: %s ' % conf.save())) print(CC.bpurple('Successful!'))