def test_submit_cancel_request(self):
        '''
        Large test:
        - Do we make our HTTP request with the expected values?
        - Do we get back the proper response type
        - Does the response contain the data we think it should?
        '''
        with patch('veritranspay.veritrans.requests.post') as mock_post:

            order_id = ''.join([fake.random_letter() for _ in range(25)])

            # mock out our approval request
            req = MagicMock(spec=request.CancelRequest)
            req.order_id = order_id
            # req.attach_mock(MagicMock(return_value=order_id), 'order_id')
            req.attach_mock(MagicMock(return_value=None), 'validate_all')

            # mock out our HTTP post
            mock_resp = MagicMock()
            mock_resp.attach_mock(
                MagicMock(return_value=fixtures.CANCEL_RESPONSE), 'json')
            mock_post.return_value = mock_resp

            # get a response from the gateway
            gateway = veritrans.VTDirect(self.server_key)
            resp = gateway.submit_cancel_request(req)

            # did we make our HTTP request properly?
            mock_post.assert_called_once_with(
                'https://api.midtrans.com/v2/'
                '{order_id}/cancel'.format(order_id=order_id),
                auth=(self.server_key, ''),
                headers={'accept': 'application/json'})

            # was it the correct type?
            self.assertIsInstance(resp, response.CancelResponse)

            # last, take our expected return values and do a little
            # massaging out to account for modifications performed
            # by response object
            exp = deepcopy(fixtures.CANCEL_RESPONSE)
            exp['status_code'] = int(exp['status_code'])
            exp['transaction_time'] = \
                helpers.parse_veritrans_datetime(exp['transaction_time'])
            exp['gross_amount'] = \
                helpers.parse_veritrans_amount(exp['gross_amount'])

            # does it have our expected attributes?
            self.assertEqual(resp.status_code, int(exp['status_code']))
            self.assertEqual(resp.status_message, exp['status_message'])
            self.assertEqual(resp.transaction_id, exp['transaction_id'])
            self.assertEqual(resp.masked_card, exp['masked_card'])
            self.assertEqual(resp.order_id, exp['order_id'])
            self.assertEqual(resp.payment_type, exp['payment_type'])
            self.assertEqual(resp.transaction_time, exp['transaction_time'])
            self.assertEqual(resp.transaction_status,
                             exp['transaction_status'])
            self.assertEqual(resp.fraud_status, exp['fraud_status'])
            self.assertEqual(resp.bank, exp['bank'])
            self.assertEqual(resp.gross_amount, exp['gross_amount'])
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     super(ChargeResponseBase, self).__init__(*args, **kwargs)
     self.transaction_id = kwargs.get('transaction_id', None)
     self.order_id = kwargs.get('order_id', None)
     self.payment_type = kwargs.get('payment_type', None)
     self.transaction_time = \
         helpers.parse_veritrans_datetime(
             kwargs.get('transaction_time', None))
     self.transaction_status = kwargs.get('transaction_status', None)
     self.fraud_status = kwargs.get('fraud_status', None)
     self.approval_code = kwargs.get('approval_code', None)
     self.gross_amount = \
         helpers.parse_veritrans_amount(
             kwargs.get('gross_amount', None))
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(ChargeResponseBase, self).__init__(*args, **kwargs)
     self.transaction_id = kwargs.get('transaction_id', None)
     self.order_id = kwargs.get('order_id', None)
     self.payment_type = kwargs.get('payment_type', None)
     self.transaction_time = \
         helpers.parse_veritrans_datetime(
             kwargs.get('transaction_time', None))
     self.transaction_status = kwargs.get('transaction_status', None)
     self.fraud_status = kwargs.get('fraud_status', None)
     self.approval_code = kwargs.get('approval_code', None)
     self.gross_amount = \
         helpers.parse_veritrans_amount(
             kwargs.get('gross_amount', None))
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(StatusResponse, self).__init__(*args, **kwargs)
     self.transaction_id = kwargs.get('transaction_id', None)
     self.masked_card = kwargs.get('masked_card', None)
     self.order_id = kwargs.get('order_id', None)
     self.payment_type = kwargs.get('payment_type', None)
     self.transaction_time = \
         helpers.parse_veritrans_datetime(
             kwargs.get('transaction_time', None))
     self.transaction_status = kwargs.get('transaction_status', None)
     self.fraud_status = kwargs.get('fraud_status', None)
     self.approval_code = kwargs.get('approval_code', None)
     self.signature_key = kwargs.get('signature_key', None)
     self.bank = kwargs.get('bank', None)
     self.gross_amount = \
         helpers.parse_veritrans_amount(
             kwargs.get('gross_amount', None))
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(ApproveResponse, self).__init__(*args, **kwargs)
     self.transaction_id = kwargs.get('transaction_id', None)
     self.masked_card = kwargs.get('masked_card', None)
     self.order_id = kwargs.get('order_id', None)
     self.payment_type = kwargs.get('payment_type', None)
     self.transaction_time = \
         helpers.parse_veritrans_datetime(
             kwargs.get('transaction_time', None))
     self.transaction_status = kwargs.get('transaction_status', None)
     self.fraud_status = kwargs.get('fraud_status', None)
     self.approval_code = kwargs.get('approval_code', None)
     self.signature_key = kwargs.get('signature_key', None)
     self.bank = kwargs.get('bank', None)
     self.permata_va_number = kwargs.get('permata_va_number', None)
     self.va_number = kwargs.get('va_number', None)
     self.bill_key = kwargs.get('bill_key', None)
     self.biller_code = kwargs.get('biller_code', None)
     self.redirect_url = kwargs.get('redirect_url', None)
     self.gross_amount = \
         helpers.parse_veritrans_amount(
             kwargs.get('gross_amount', None))
Exemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     super(CancelResponse, self).__init__(*args, **kwargs)
     self.transaction_id = kwargs.get('transaction_id', None)
     self.masked_card = kwargs.get('masked_card', None)
     self.order_id = kwargs.get('order_id', None)
     self.payment_type = kwargs.get('payment_type', None)
     self.transaction_time = \
         helpers.parse_veritrans_datetime(
             kwargs.get('transaction_time', None))
     self.transaction_status = kwargs.get('transaction_status', None)
     self.fraud_status = kwargs.get('fraud_status', None)
     self.approval_code = kwargs.get('approval_code', None)
     self.signature_key = kwargs.get('signature_key', None)
     self.bank = kwargs.get('bank', None)
     self.permata_va_number = kwargs.get('permata_va_number', None)
     self.va_number = kwargs.get('va_number', None)
     self.bill_key = kwargs.get('bill_key', None)
     self.biller_code = kwargs.get('biller_code', None)
     self.redirect_url = kwargs.get('redirect_url', None)
     self.gross_amount = \
         helpers.parse_veritrans_amount(
             kwargs.get('gross_amount', None))
Exemplo n.º 7
0
    def test_submit_status_request(self):
        '''
        Large test:
        - Do we make our HTTP request with the expected values?
        - Do we get back the proper response type
        - Does the response contain the data we think it should?
        '''
        with patch('veritranspay.veritrans.requests.post') as mock_post:

            order_id = ''.join([fake.random_letter() for _ in range(25)])

            # mock out our approval request
            req = MagicMock(spec=request.ApprovalRequest)
            req.order_id = order_id
            # req.attach_mock(MagicMock(return_value=order_id), 'order_id')
            req.attach_mock(MagicMock(return_value=None), 'validate_all')

            # mock out our HTTP post
            mock_resp = MagicMock()
            mock_resp.attach_mock(
                MagicMock(return_value=fixtures.STATUS_RESPONSE),
                'json')
            mock_post.return_value = mock_resp

            # get a response from the gateway
            gateway = veritrans.VTDirect(self.server_key)
            resp = gateway.submit_approval_request(req)

            # did we make our HTTP request properly?
            mock_post.assert_called_once_with(
                'https://api.veritrans.co.id/v2/'
                '{order_id}/approve'.format(order_id=order_id),
                auth=(self.server_key, ''),
                headers={'accept': 'application/json'}
            )

            # was it the correct type?
            self.assertIsInstance(resp, response.ApproveResponse)

            # last, take our expected return values and do a little
            # massaging out to account for modifications performed
            # by response object
            exp = deepcopy(fixtures.STATUS_RESPONSE)
            exp['status_code'] = int(exp['status_code'])
            exp['transaction_time'] = \
                helpers.parse_veritrans_datetime(exp['transaction_time'])
            exp['gross_amount'] = \
                helpers.parse_veritrans_amount(exp['gross_amount'])

            # does it have our expected attributes?
            self.assertEqual(resp.status_code,
                             int(exp['status_code']))
            self.assertEqual(resp.status_message, exp['status_message'])
            self.assertEqual(resp.transaction_id, exp['transaction_id'])
            self.assertEqual(resp.masked_card, exp['masked_card'])
            self.assertEqual(resp.order_id, exp['order_id'])
            self.assertEqual(resp.payment_type, exp['payment_type'])
            self.assertEqual(resp.transaction_time, exp['transaction_time'])
            self.assertEqual(resp.transaction_status,
                             exp['transaction_status'])
            self.assertEqual(resp.fraud_status, exp['fraud_status'])
            self.assertEqual(resp.approval_code, exp['approval_code'])
            self.assertEqual(resp.signature_key, exp['signature_key'])
            self.assertEqual(resp.bank, exp['bank'])
            self.assertEqual(resp.gross_amount, exp['gross_amount'])
Exemplo n.º 8
0
 def test_emptystring_input_returns_0(self):
     val = ''
     expected = 0
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 9
0
 def test_none_input_returns_0(self):
     val = None
     expected = 0
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 10
0
 def test_ignores_fractional(self):
     val = "100.99"
     expected = 100
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 11
0
 def test_returns_integer(self):
     val = "100.00"
     actual = helpers.parse_veritrans_amount(val)
     self.assertIsInstance(actual, int)
Exemplo n.º 12
0
 def test_emptystring_input_returns_0(self):
     val = ''
     expected = 0
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 13
0
 def test_none_input_returns_0(self):
     val = None
     expected = 0
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 14
0
 def test_ignores_fractional(self):
     val = "100.99"
     expected = 100
     actual = helpers.parse_veritrans_amount(val)
     self.assertEqual(actual, expected)
Exemplo n.º 15
0
 def test_returns_integer(self):
     val = "100.00"
     actual = helpers.parse_veritrans_amount(val)
     self.assertIsInstance(actual, int)