Exemplo n.º 1
0
 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 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_numAccountUpdates(self, mock__get_file_str_from_sftp):
        transaction = fields.authorization()
        transaction.reportGroup = 'Planets'
        transaction.orderId = '12344'
        transaction.amount = 106
        transaction.orderSource = 'ecommerce'
        transaction.id = 'thisisid'

        card = fields.cardType()
        card.number = '4100000000000000'
        card.expDate = '1210'
        card.type = 'VI'

        mock__get_file_str_from_sftp.return_value = """<cnpResponse version='12.10' response='0' message='Valid Format' xmlns='http://www.vantivcnp.com/schema'>
                        <batchResponse cnpBatchId='12344' merchantId='56789' numAccountUpdates='3' xmlns='http://www.vantivcnp.com/schema'>
                            <saleResponse>
                                <cnpTxnId>123</cnpTxnId>
                                <accountUpdater>
                                    <accountUpdateSource>N</accountUpdateSource>
                                </accountUpdater>
                                </saleResponse>
                            </batchResponse>
                       </cnpResponse>
                       """

        response = batch.retrieve('retrieve_file', conf)
        self.assertEquals(
            response['batchResponse']['saleResponse']['cnpTxnId'], '123')
        self.assertEquals(response['batchResponse']['@numAccountUpdates'], '3')
    def test_request_relturn_format(self, mock__http_post):
        transaction = fields.authorization()
        transaction.reportGroup = 'Planets'
        transaction.orderId = '12344'
        transaction.amount = 106
        transaction.orderSource = 'ecommerce'
        transaction.id = 'thisisid'

        card = fields.cardType()
        card.number = '4100000000000000'
        card.expDate = '1210'
        card.type = 'VI'

        transaction.card = card

        mock__http_post.return_value = """<cnpOnlineResponse version='11.0' response='1' message='Valid Format' xmlns='http://www.vantivcnp.com/schema'>
</cnpOnlineResponse>
        """
        self.assertRaises(utils.VantivException, online.request, transaction,
                          conf, 'dict')

        mock__http_post.return_value = """<cnpOnlineResponse version='11.0' response='0' message='Valid Format' xmlns='http://www.vantivcnp.com/schema'>
          <authorizationResponse id='thisisid' reportGroup='Planets' customerId=''>
            <cnpTxnId>4544691351798650001</cnpTxnId>
            <orderId>12344</orderId>
            <response>000</response>
            <responseTime>2017-03-13T12:14:00</responseTime>
            <message>Approved</message>
            <authCode>07585</authCode>
            <accountUpdater>
              <originalCardInfo>
                <type>VI</type>
                <number>4100100000000000</number>
                <expDate>1110</expDate>
              </originalCardInfo>
              <newCardInfo>
                <type>VI</type>
                <number>4532694461984309</number>
                <expDate>1114</expDate>
              </newCardInfo>
            </accountUpdater>
            <networkTransactionId>63225578415568556365452427825</networkTransactionId>
          </authorizationResponse>
        </cnpOnlineResponse>
                """
        # return dict
        response = online.request(transaction, conf)
        self.assertEquals('0', response['@response'])
        self.assertEquals('4544691351798650001',
                          response['authorizationResponse']['cnpTxnId'])
        self.assertIsInstance(response, dict)

        # return xml string
        response = online.request(transaction, conf, 'xml')
        self.assertIsInstance(response, str)

        # return fields object.
        response = online.request(transaction, conf, 'object')
        self.assertEquals('0', response.response)
Exemplo n.º 5
0
    def test_Transactions_mix_rfrrequest_normal_txn(self):
        rfr = fields.RFRRequest()
        normal = fields.authorization()

        txns = batch.Transactions()
        txns.add(rfr)
        self.assertRaises(utils.VantivException, txns.add, normal)

        txns = batch.Transactions()
        txns.add(normal)
        self.assertRaises(utils.VantivException, txns.add, rfr)
Exemplo n.º 6
0
    def test_request_args_invalid_conf(self):
        transaction = fields.authorization()
        transaction.reportGroup = 'Planets'
        transaction.orderId = '12344'
        transaction.amount = 106
        transaction.orderSource = 'ecommerce'
        transaction.id = 'thisisid'

        card = fields.cardType()
        card.number = '4100000000000000'
        card.expDate = '1210'
        card.type = 'VI'

        transaction.card = card
        conf_wrong = 1
        self.assertRaises(utils.VantivException, online.request, transaction, conf_wrong)
    def test_submit(self, mock__put_file_to_sftp):
        transaction = fields.authorization()
        transaction.reportGroup = 'Planets'
        transaction.orderId = '12344'
        transaction.amount = 106
        transaction.orderSource = 'ecommerce'
        transaction.id = 'thisisid'

        card = fields.cardType()
        card.number = '4100000000000000'
        card.expDate = '1210'
        card.type = 'VI'

        transaction.card = card

        txns = batch.Transactions()
        txns.add(transaction)

        # first arg is not instance of batch.Transactions
        self.assertRaises(utils.VantivException, batch.submit, transaction,
                          conf)

        # first arg is an new instance of utils.Configuration
        self.assertRaises(utils.VantivException, batch.submit,
                          batch.Transactions(), conf)

        # second arg is not instance of utils.Configuration
        self.assertRaises(utils.VantivException, batch.submit, txns, 1)

        # Third arg is not sring
        self.assertRaises(utils.VantivException, batch.submit, txns, conf,
                          txns)

        # Fourth arg is not positive int
        self.assertRaises(utils.VantivException, batch.submit, txns, conf,
                          'aaa', -1)

        mock__put_file_to_sftp.return_value = 'filename'

        self.assertEquals('filename', batch.submit(txns, conf))
Exemplo n.º 8
0
 def test_Transactions_duplicate_normal_txn(self):
     normal = fields.authorization()
     txns = batch.Transactions()
     txns.add(normal)
     self.assertRaises(utils.VantivException, txns.add, normal)