Changeset 14754 for main


Ignore:
Timestamp:
3 Aug 2017, 05:41:45 (7 years ago)
Author:
Henrik Bettermann
Message:

Add and improve tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py

    r14743 r14754  
    1818import os
    1919import unittest
     20import random
    2021from datetime import datetime, timedelta, date
    2122from zope.component import createObject, getUtility
     
    5152    serviceTypeId = '4430731'
    5253    api_key = '1946'
    53     orderId = '987698769876'
    54     amount = '1000'
    5554    responseurl = 'http://xxxx'
    5655    host = 'www.remitademo.net'
     56    url = '/remita/ecomm/split/init.reg'  # /remita/ecomm/v2/init.reg
    5757    lineitems = (
    5858                  {"lineItemsId":"itemid1","beneficiaryName":"Oshadami Mike",
     
    6363                  "beneficiaryAmount":"500","deductFeeFrom":"0"}
    6464                )
    65 
    66     @external_test
    67     def test_get_JSON_POST_response(self):
    68 
    69         url = '/remita/ecomm/split/init.reg'  # /remita/ecomm/v2/init.reg
    70 
     65    amount = 1000.0
     66
     67    def _get_transaction_data(self):
     68        self.orderId = str(random.randint(100000000, 999999999))
    7169        resp = get_JSON_POST_response(
    7270                merchantId=self.merchantId, serviceTypeId=self.serviceTypeId,
    7371                api_key=self.api_key, orderId=self.orderId,
    7472                amount=self.amount, responseurl=self.responseurl,
    75                 host=self.host, url=url, https=False,
     73                host=self.host, url=self.url, https=False,
     74                fullname='Anton Meier', email='am@xxx.de',
     75                lineitems=self.lineitems)
     76        self.rrr = resp['RRR'].rstrip()
     77
     78    @external_test
     79    def test_get_JSON_POST_response(self):
     80        self._get_transaction_data()
     81        resp = get_JSON_POST_response(
     82                merchantId=self.merchantId, serviceTypeId=self.serviceTypeId,
     83                api_key=self.api_key, orderId=self.orderId,
     84                amount=self.amount, responseurl=self.responseurl,
     85                host=self.host, url=self.url, https=False,
    7686                fullname='Anton Meier', email='am@xxx.de',
    7787                lineitems=self.lineitems)
    7888        assert resp == {
    7989            u'status': u'RRR Already Exist for the orderId',
    80             u'orderID': u'987698769876',
    81             u'RRR': u'320007640976 ',  # strange trailing whitespace which
    82                                        # obviously does not belong to the RRR
     90            u'orderID': self.orderId,
     91            u'RRR': self.rrr + ' ',  # strange trailing whitespace which
     92                                     # obviously does not belong to the RRR
    8393            u'statuscode': u'055'}
    84 
    85     @external_test
    86     def test_payment_status_via_rrr(self):
    8794
    8895        resp = get_payment_status_via_rrr(
    8996                merchantId=self.merchantId,
    9097                api_key=self.api_key,
    91                 RRR='320007640976',
     98                RRR=self.rrr,
    9299                host=self.host,
    93100                https=False,
    94101                )
    95         assert resp == {
    96             u'orderId': u'987698769876',
    97             u'status': u'021',
    98             u'amount': 1000.0,
    99             u'transactiontime': u'2017-08-01 12:10:32 PM',
    100             u'message': u'Transaction Pending',
    101             u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'},
    102                            {u'status': u'021', u'lineItemsId': u'itemid2'}
    103                           ],
    104             u'RRR': u'320007640976'}
     102        assert resp['orderId'] == self.orderId
     103        assert resp['status'] == '021'
     104        assert resp['amount'] == self.amount
     105        assert resp['lineitems'] == [
     106            {u'status': u'021', u'lineItemsId': u'itemid1'},
     107            {u'status': u'021', u'lineItemsId': u'itemid2'}]
     108        assert resp['RRR'] == self.rrr
     109        assert resp['message'] == u'Transaction Pending'
    105110
    106111class RemitaTestsStudents(StudentsFullSetup):
     
    113118    serviceTypeId = '4430731'
    114119    api_key = '1946'
    115     orderId = '3456346346'
    116     amount = '1000'
    117120    responseurl = 'http://xxxx'
    118121    host = 'www.remitademo.net'
     122
     123    # successful transaction
     124    # (hopefully this transaction remain in the Remita database)
     125    orderId = '3456346346'
     126    rrr = u'280007640804'
     127    amount = 1000.0
     128
     129    # pending transaction
     130    #orderId_p = '987698769876'
     131    rrr_p = u'320007640976'
    119132
    120133    def setUp(self):
     
    141154    @external_test
    142155    def test_query_remita(self):
    143         # We can only test the first part of query_interswitch since
    144         # we have no succesful payment.
     156        #requery pending transaction
    145157        qr = query_remita(
    146158            self.payment,
    147159            merchantId=self.merchantId,
    148160            api_key=self.api_key,
    149             RRR='320007640976',
     161            RRR=self.rrr_p,
    150162            host=self.host,
    151163            https=False,
     
    157169            % self.payment.p_id)
    158170
     171        #requery successful transaction
     172        self.payment.amount_auth = 1000.0
     173        self.payment.p_id = self.orderId
     174        qr = query_remita(
     175            self.payment,
     176            merchantId=self.merchantId,
     177            api_key=self.api_key,
     178            RRR=self.rrr,
     179            host=self.host,
     180            https=False,
     181            verify=False)
     182        assert qr[0] == True
     183        assert qr[1] == u'Successful callback received'
     184
    159185    @external_test
    160186    def test_remita_form(self):
     
    162188        self.browser.getLink("Pay via Remita").click()
    163189        # The RRR has been retrieved
    164         self.assertTrue('<input name="rrr" type="hidden" value="280007640804">'
    165             in self.browser.contents)
    166         self.assertEqual(self.payment.r_pay_reference, '280007640804')
     190        self.assertTrue('<input name="rrr" type="hidden" value="%s">' % self.rrr
     191            in self.browser.contents)
     192        self.assertEqual(self.payment.r_pay_reference, self.rrr)
    167193        # Means of testing end here.
    168194        return
     195
     196    @external_test
     197    def test_requery_verify_payment_status(self):
     198        # Manager can access InterswitchForm
     199        self.browser.getLink("Requery Remita Payment Status").click()
     200        self.assertTrue('Remita Retrieval Reference not found.'
     201            in self.browser.contents)
     202        self.payment.r_pay_reference = self.rrr
     203        self.browser.getLink("Requery Remita Payment Status").click()
     204        self.assertTrue('Callback amount does not match.'
     205            in self.browser.contents)
     206        self.payment.amount_auth = 1000.0
     207        self.browser.getLink("Requery Remita Payment Status").click()
     208        self.assertTrue('Callback order id does not match.'
     209            in self.browser.contents)
     210        self.payment.p_id = self.orderId
     211        self.browser.getLink("Requery Remita Payment Status").click()
     212        self.assertTrue('Successful payment' in self.browser.contents)
     213        self.assertEqual(self.payment.r_desc, 'Approved')
     214        self.assertEqual(self.payment.r_amount_approved , 1000.0)
     215        self.assertEqual(self.payment.r_code, '01')
     216        self.browser.getLink("Verify Remita Payment Status").click()
     217        self.assertTrue('Successful payment' in self.browser.contents)
     218        return
Note: See TracChangeset for help on using the changeset viewer.