Index: /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py	(revision 14753)
+++ /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py	(revision 14754)
@@ -18,4 +18,5 @@
 import os
 import unittest
+import random
 from datetime import datetime, timedelta, date
 from zope.component import createObject, getUtility
@@ -51,8 +52,7 @@
     serviceTypeId = '4430731'
     api_key = '1946'
-    orderId = '987698769876'
-    amount = '1000'
     responseurl = 'http://xxxx'
     host = 'www.remitademo.net'
+    url = '/remita/ecomm/split/init.reg'  # /remita/ecomm/v2/init.reg
     lineitems = (
                   {"lineItemsId":"itemid1","beneficiaryName":"Oshadami Mike",
@@ -63,44 +63,49 @@
                   "beneficiaryAmount":"500","deductFeeFrom":"0"}
                 )
-
-    @external_test
-    def test_get_JSON_POST_response(self):
-
-        url = '/remita/ecomm/split/init.reg'  # /remita/ecomm/v2/init.reg
-
+    amount = 1000.0
+
+    def _get_transaction_data(self):
+        self.orderId = str(random.randint(100000000, 999999999))
         resp = get_JSON_POST_response(
                 merchantId=self.merchantId, serviceTypeId=self.serviceTypeId,
                 api_key=self.api_key, orderId=self.orderId,
                 amount=self.amount, responseurl=self.responseurl,
-                host=self.host, url=url, https=False,
+                host=self.host, url=self.url, https=False,
+                fullname='Anton Meier', email='am@xxx.de',
+                lineitems=self.lineitems)
+        self.rrr = resp['RRR'].rstrip()
+
+    @external_test
+    def test_get_JSON_POST_response(self):
+        self._get_transaction_data()
+        resp = get_JSON_POST_response(
+                merchantId=self.merchantId, serviceTypeId=self.serviceTypeId,
+                api_key=self.api_key, orderId=self.orderId,
+                amount=self.amount, responseurl=self.responseurl,
+                host=self.host, url=self.url, https=False,
                 fullname='Anton Meier', email='am@xxx.de',
                 lineitems=self.lineitems)
         assert resp == {
             u'status': u'RRR Already Exist for the orderId',
-            u'orderID': u'987698769876',
-            u'RRR': u'320007640976 ',  # strange trailing whitespace which
-                                       # obviously does not belong to the RRR
+            u'orderID': self.orderId,
+            u'RRR': self.rrr + ' ',  # strange trailing whitespace which
+                                     # obviously does not belong to the RRR
             u'statuscode': u'055'}
-
-    @external_test
-    def test_payment_status_via_rrr(self):
 
         resp = get_payment_status_via_rrr(
                 merchantId=self.merchantId,
                 api_key=self.api_key,
-                RRR='320007640976',
+                RRR=self.rrr,
                 host=self.host,
                 https=False,
                 )
-        assert resp == {
-            u'orderId': u'987698769876',
-            u'status': u'021',
-            u'amount': 1000.0,
-            u'transactiontime': u'2017-08-01 12:10:32 PM',
-            u'message': u'Transaction Pending',
-            u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'},
-                           {u'status': u'021', u'lineItemsId': u'itemid2'}
-                          ],
-            u'RRR': u'320007640976'}
+        assert resp['orderId'] == self.orderId
+        assert resp['status'] == '021'
+        assert resp['amount'] == self.amount
+        assert resp['lineitems'] == [
+            {u'status': u'021', u'lineItemsId': u'itemid1'},
+            {u'status': u'021', u'lineItemsId': u'itemid2'}]
+        assert resp['RRR'] == self.rrr
+        assert resp['message'] == u'Transaction Pending'
 
 class RemitaTestsStudents(StudentsFullSetup):
@@ -113,8 +118,16 @@
     serviceTypeId = '4430731'
     api_key = '1946'
-    orderId = '3456346346'
-    amount = '1000'
     responseurl = 'http://xxxx'
     host = 'www.remitademo.net'
+
+    # successful transaction
+    # (hopefully this transaction remain in the Remita database)
+    orderId = '3456346346'
+    rrr = u'280007640804'
+    amount = 1000.0
+
+    # pending transaction
+    #orderId_p = '987698769876'
+    rrr_p = u'320007640976'
 
     def setUp(self):
@@ -141,11 +154,10 @@
     @external_test
     def test_query_remita(self):
-        # We can only test the first part of query_interswitch since
-        # we have no succesful payment.
+        #requery pending transaction
         qr = query_remita(
             self.payment,
             merchantId=self.merchantId,
             api_key=self.api_key,
-            RRR='320007640976',
+            RRR=self.rrr_p,
             host=self.host,
             https=False,
@@ -157,4 +169,18 @@
             % self.payment.p_id)
 
+        #requery successful transaction
+        self.payment.amount_auth = 1000.0
+        self.payment.p_id = self.orderId
+        qr = query_remita(
+            self.payment,
+            merchantId=self.merchantId,
+            api_key=self.api_key,
+            RRR=self.rrr,
+            host=self.host,
+            https=False,
+            verify=False)
+        assert qr[0] == True
+        assert qr[1] == u'Successful callback received'
+
     @external_test
     def test_remita_form(self):
@@ -162,7 +188,31 @@
         self.browser.getLink("Pay via Remita").click()
         # The RRR has been retrieved
-        self.assertTrue('<input name="rrr" type="hidden" value="280007640804">'
-            in self.browser.contents)
-        self.assertEqual(self.payment.r_pay_reference, '280007640804')
+        self.assertTrue('<input name="rrr" type="hidden" value="%s">' % self.rrr
+            in self.browser.contents)
+        self.assertEqual(self.payment.r_pay_reference, self.rrr)
         # Means of testing end here.
         return
+
+    @external_test
+    def test_requery_verify_payment_status(self):
+        # Manager can access InterswitchForm
+        self.browser.getLink("Requery Remita Payment Status").click()
+        self.assertTrue('Remita Retrieval Reference not found.'
+            in self.browser.contents)
+        self.payment.r_pay_reference = self.rrr
+        self.browser.getLink("Requery Remita Payment Status").click()
+        self.assertTrue('Callback amount does not match.'
+            in self.browser.contents)
+        self.payment.amount_auth = 1000.0
+        self.browser.getLink("Requery Remita Payment Status").click()
+        self.assertTrue('Callback order id does not match.'
+            in self.browser.contents)
+        self.payment.p_id = self.orderId
+        self.browser.getLink("Requery Remita Payment Status").click()
+        self.assertTrue('Successful payment' in self.browser.contents)
+        self.assertEqual(self.payment.r_desc, 'Approved')
+        self.assertEqual(self.payment.r_amount_approved , 1000.0)
+        self.assertEqual(self.payment.r_code, '01')
+        self.browser.getLink("Verify Remita Payment Status").click()
+        self.assertTrue('Successful payment' in self.browser.contents)
+        return
