jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348503 )

Change subject: Test PP audit with CSV files
......................................................................


Test PP audit with CSV files

Get more realistic fakes than the rows built in code.
This patch tests express checkout types except for recurring, which
is currently not finding the subsc id.
We should also convert the tests for the classic API

Change-Id: I1feb85c7473747dfac2ca4f8dc1ce5a0c80c5a27
---
A audit/paypal/tests/data/express_checkout_donation.csv
A audit/paypal/tests/data/express_checkout_recurring_donation.csv
A audit/paypal/tests/data/express_checkout_recurring_refund.csv
A audit/paypal/tests/data/express_checkout_refund.csv
M audit/paypal/tests/test_trr_file.py
5 files changed, 45 insertions(+), 38 deletions(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/audit/paypal/tests/data/express_checkout_donation.csv 
b/audit/paypal/tests/data/express_checkout_donation.csv
new file mode 100644
index 0000000..1c9add6
--- /dev/null
+++ b/audit/paypal/tests/data/express_checkout_donation.csv
@@ -0,0 +1,2 @@
+"CH","Transaction ID","Invoice ID","PayPal Reference ID","PayPal Reference ID 
Type","Transaction Event Code","Transaction Initiation Date","Transaction 
Completion Date","Transaction  Debit or Credit","Gross Transaction 
Amount","Gross Transaction Currency","Fee Debit or Credit","Fee Amount","Fee 
Currency","Transactional Status","Insurance Amount","Sales Tax 
Amount","Shipping Amount","Transaction Subject","Transaction Note","Payer's 
Account ID","Payer Address Status","Item Name","Item ID","Option 1 
Name","Option 1 Value","Option 2 Name","Option 2 Value","Auction Site","Auction 
Buyer ID","Auction Closing Date","Shipping Address Line1","Shipping Address 
Line2","Shipping Address City","Shipping Address State","Shipping Address 
Zip","Shipping Address Country","Shipping Method","Custom Field","Billing 
Address Line1","Billing Address Line2","Billing Address City","Billing Address 
State","Billing Address Zip","Billing Address Country","Consumer ID","First 
Name","Last Name","Consumer Business Name","Card Type","Payment 
Source","Shipping Name","Authorization Review Status","Protection 
Eligibility","Payment Tracking ID"
+"SB","1V551844CE5526421","46239229.0","","","T0006",2017/03/02 09:59:55 
-0800,2017/03/02 09:59:55 
-0800,"CR",15000,"JPY","DR",4300,"JPY","S",,0,0,"Donation to the Wikimedia 
Foundation","","[email protected]","N","Donation to the Wikimedia 
Foundation","","","","","","","",,"","","","","","","","46239229","321 Notta 
Boulevard","","Whoville","OR","97211","US","RTWSDJI4S8DWK","Cindy 
Lou","Who","Cindy Lou Who","","Express Checkout","Cindy Lou, Who","01","02",""
diff --git a/audit/paypal/tests/data/express_checkout_recurring_donation.csv 
b/audit/paypal/tests/data/express_checkout_recurring_donation.csv
new file mode 100644
index 0000000..4232a33
--- /dev/null
+++ b/audit/paypal/tests/data/express_checkout_recurring_donation.csv
@@ -0,0 +1,3 @@
+"CH","Transaction ID","Invoice ID","PayPal Reference ID","PayPal Reference ID 
Type","Transaction Event Code","Transaction Initiation Date","Transaction 
Completion Date","Transaction  Debit or Credit","Gross Transaction 
Amount","Gross Transaction Currency","Fee Debit or Credit","Fee Amount","Fee 
Currency","Transactional Status","Insurance Amount","Sales Tax 
Amount","Shipping Amount","Transaction Subject","Transaction Note","Payer's 
Account ID","Payer Address Status","Item Name","Item ID","Option 1 
Name","Option 1 Value","Option 2 Name","Option 2 Value","Auction Site","Auction 
Buyer ID","Auction Closing Date","Shipping Address Line1","Shipping Address 
Line2","Shipping Address City","Shipping Address State","Shipping Address 
Zip","Shipping Address Country","Shipping Method","Custom Field","Billing 
Address Line1","Billing Address Line2","Billing Address City","Billing Address 
State","Billing Address Zip","Billing Address Country","Consumer ID","First 
Name","Last Name","Consumer Business Name","Card Type","Payment 
Source","Shipping Name","Authorization Review Status","Protection 
Eligibility","Payment Tracking ID" 
+"SB","4JH2438EE9876546W","45931681","I-SS5RD7POSD46","","T0002",2017/03/04 
05:36:05 -0800,2017/03/04 05:36:05 
-0800,"CR",15000,"JPY","DR",4300,"JPY","S",,,0,"Monthly donation to the 
Wikimedia Foundation","","[email protected]","N","Monthly donation to the 
Wikimedia 
Foundation","","","","","","","",,"","","","","","","","","","","","","","","RTWSDJI4S8DWK","Cindy
 Lou","Who","Cindy Lou Who","","Others","Cindy Lou, Who","01","02",""
+
diff --git a/audit/paypal/tests/data/express_checkout_recurring_refund.csv 
b/audit/paypal/tests/data/express_checkout_recurring_refund.csv
new file mode 100644
index 0000000..b8286f5
--- /dev/null
+++ b/audit/paypal/tests/data/express_checkout_recurring_refund.csv
@@ -0,0 +1,2 @@
+"CH","Transaction ID","Invoice ID","PayPal Reference ID","PayPal Reference ID 
Type","Transaction Event Code","Transaction Initiation Date","Transaction 
Completion Date","Transaction  Debit or Credit","Gross Transaction 
Amount","Gross Transaction Currency","Fee Debit or Credit","Fee Amount","Fee 
Currency","Transactional Status","Insurance Amount","Sales Tax 
Amount","Shipping Amount","Transaction Subject","Transaction Note","Payer's 
Account ID","Payer Address Status","Item Name","Item ID","Option 1 
Name","Option 1 Value","Option 2 Name","Option 2 Value","Auction Site","Auction 
Buyer ID","Auction Closing Date","Shipping Address Line1","Shipping Address 
Line2","Shipping Address City","Shipping Address State","Shipping Address 
Zip","Shipping Address Country","Shipping Method","Custom Field","Billing 
Address Line1","Billing Address Line2","Billing Address City","Billing Address 
State","Billing Address Zip","Billing Address Country","Consumer ID","First 
Name","Last Name","Consumer Business Name","Card Type","Payment 
Source","Shipping Name","Authorization Review Status","Protection 
Eligibility","Payment Tracking ID"
+"SB","8WG23468CX793000L","45931681","4JH2438EE9876546W","TXN","T1107",2017/03/22
 09:33:51 -0700,2017/03/22 09:33:51 
-0700,"DR",15000,"JPY","CR",4300,"JPY","S",,,0,"","refund","[email protected]","N","Monthly
 donation to the Wikimedia 
Foundation","","","","","","","",,"","","","","","","","","","","","","","","RTWSDJI4S8DWK","Cindy
 Lou","Who","Cindy Lou Who","","Others","Cindy Lou, Who","","02",""
diff --git a/audit/paypal/tests/data/express_checkout_refund.csv 
b/audit/paypal/tests/data/express_checkout_refund.csv
new file mode 100644
index 0000000..33ab6f2
--- /dev/null
+++ b/audit/paypal/tests/data/express_checkout_refund.csv
@@ -0,0 +1,2 @@
+"CH","Transaction ID","Invoice ID","PayPal Reference ID","PayPal Reference ID 
Type","Transaction Event Code","Transaction Initiation Date","Transaction 
Completion Date","Transaction  Debit or Credit","Gross Transaction 
Amount","Gross Transaction Currency","Fee Debit or Credit","Fee Amount","Fee 
Currency","Transactional Status","Insurance Amount","Sales Tax 
Amount","Shipping Amount","Transaction Subject","Transaction Note","Payer's 
Account ID","Payer Address Status","Item Name","Item ID","Option 1 
Name","Option 1 Value","Option 2 Name","Option 2 Value","Auction Site","Auction 
Buyer ID","Auction Closing Date","Shipping Address Line1","Shipping Address 
Line2","Shipping Address City","Shipping Address State","Shipping Address 
Zip","Shipping Address Country","Shipping Method","Custom Field","Billing 
Address Line1","Billing Address Line2","Billing Address City","Billing Address 
State","Billing Address Zip","Billing Address Country","Consumer ID","First 
Name","Last Name","Consumer Business Name","Card Type","Payment 
Source","Shipping Name","Authorization Review Status","Protection 
Eligibility","Payment Tracking ID"
+"SB","3HD08833MR473623T","46239229.0","1V551844CE5526421","TXN","T1107",2017/03/22
 09:34:59 -0700,2017/03/22 09:34:59 
-0700,"DR",15000,"JPY","CR",4300,"JPY","S",,0,0,"","refund","[email protected]","N","Donation
 to the Wikimedia 
Foundation","","","","","","","",,"","","","","","","","46239229","321 Notta 
Boulevard","","Whoville","OR","97211","US","RTWSDJI4S8DWK","Cindy 
Lou","Who","Cindy Lou Who","","Others","Cindy Lou, Who","","02",""
diff --git a/audit/paypal/tests/test_trr_file.py 
b/audit/paypal/tests/test_trr_file.py
index fc2ed56..aa70bca 100644
--- a/audit/paypal/tests/test_trr_file.py
+++ b/audit/paypal/tests/test_trr_file.py
@@ -1,5 +1,7 @@
+import csv
 from mock import patch
 import nose.tools
+import os
 
 import audit.paypal.TrrFile
 
@@ -83,40 +85,6 @@
     return row
 
 
-def get_ec_refund_row():
-
-    row = get_base_row()
-    row.update({
-        "Invoice ID": "4123422",
-        "PayPal Reference ID": "3GJH3GJ3334214812",
-        "PayPal Reference ID Type": "TXN",
-        "Transaction Event Code": "T1107",
-        "Transaction  Debit or Credit": "DR",
-        "Fee Debit or Credit": "CR",
-        "Transaction Note": "refund",
-        "Custom Field": "4123422",
-        "Item ID": "",
-    })
-    return row
-
-
-def get_ec_recurring_refund_row():
-
-    row = get_base_row()
-    row.update({
-        "Invoice ID": "4123422",
-        "PayPal Reference ID": "3GJH3GJ3334214812",
-        "PayPal Reference ID Type": "TXN",
-        "Transaction Event Code": "T1107",
-        "Transaction  Debit or Credit": "DR",
-        "Fee Debit or Credit": "CR",
-        "Transaction Note": "refund",
-        "Custom Field": "",
-        "Item ID": "",
-    })
-    return row
-
-
 def get_recurring_row():
     row = get_base_row()
     row.update({
@@ -126,6 +94,13 @@
         "Gross Transaction Amount": "10.00",
     })
     return row
+
+
+def get_csv_row(filename):
+    path = os.path.dirname(__file__) + "/data/" + filename + ".csv"
+    with open(path, 'r') as datafile:
+        r = csv.DictReader(datafile)
+        return r.next()
 
 
 @patch("queue.redis_wrap.Redis")
@@ -179,11 +154,34 @@
 @patch("queue.redis_wrap.Redis")
 @patch("civicrm.civicrm.Civicrm")
 @patch("process.globals")
+def test_ec_donation_send(MockGlobals, MockCivicrm, MockRedis):
+    '''
+    Test that express checkout donations are marked as such
+    '''
+    row = get_csv_row("express_checkout_donation")
+
+    MockCivicrm().transaction_exists.return_value = False
+
+    parser = audit.paypal.TrrFile.TrrFile("dummy_path")
+
+    parser.parse_line(row)
+
+    # Did we send it?
+    args = MockRedis().send.call_args
+    expected = {'last_name': 'Who', 'thankyou_date': 0, 'city': 'Whoville', 
'payment_method': 'Express Checkout', 'gateway_status': 'S', 'currency': 'JPY', 
'postal_code': '97211', 'date': 1488477595, 'gateway': 'paypal_ec', 
'state_province': 'OR', 'gross': 150.0, 'first_name': 'Cindy Lou', 'fee': 43.0, 
'gateway_txn_id': '1V551844CE5526421', 'country': 'US', 'payment_submethod': 
'', 'note': '', 'supplemental_address_1': '', 'settled_date': 1488477595, 
'email': '[email protected]', 'street_address': '321 Notta Boulevard', 
'contribution_tracking_id': '46239229', 'order_id': '46239229'}
+    nose.tools.assert_equals('donations', args[0][0])
+    actual = args[0][1]
+    nose.tools.assert_equals(expected, actual)
+
+
+@patch("queue.redis_wrap.Redis")
+@patch("civicrm.civicrm.Civicrm")
+@patch("process.globals")
 def test_ec_refund_send(MockGlobals, MockCivicrm, MockRedis):
     '''
     Test that express checkout refunds are marked as such
     '''
-    row = get_ec_refund_row()
+    row = get_csv_row("express_checkout_refund")
 
     MockCivicrm().transaction_refunded.return_value = False
 
@@ -193,7 +191,7 @@
 
     # Did we send it?
     args = MockRedis().send.call_args
-    expected = {'last_name': 'Man', 'thankyou_date': 0, 'city': '', 
'payment_method': '', 'gateway_status': 'S', 'currency': 'USD', 'postal_code': 
'', 'date': 1474743301, 'gateway_refund_id': 'AS7D98AS7D9A8S7D9AS', 'gateway': 
'paypal_ec', 'state_province': '', 'gross': 10.0, 'first_name': 'Banana', 
'fee': 0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS', 'gross_currency': 'USD', 
'country': '', 'payment_submethod': '', 'note': 'refund', 
'supplemental_address_1': '', 'settled_date': 1474743301, 'gateway_parent_id': 
'3GJH3GJ3334214812', 'type': 'refund', 'email': '[email protected]', 
'street_address': '', 'contribution_tracking_id': '4123422', 'order_id': 
'4123422'}
+    expected = {'last_name': 'Who', 'thankyou_date': 0, 'city': 'Whoville', 
'payment_method': 'Others', 'gateway_status': 'S', 'currency': 'JPY', 
'postal_code': '97211', 'date': 1490200499, 'gateway_refund_id': 
'3HD08833MR473623T', 'gateway': 'paypal_ec', 'state_province': 'OR', 'gross': 
150.0, 'first_name': 'Cindy Lou', 'fee': 43.0, 'gateway_txn_id': 
'3HD08833MR473623T', 'gross_currency': 'JPY', 'country': 'US', 
'payment_submethod': '', 'note': 'refund', 'supplemental_address_1': '', 
'settled_date': 1490200499, 'gateway_parent_id': '1V551844CE5526421', 'type': 
'refund', 'email': '[email protected]', 'street_address': '321 Notta 
Boulevard', 'contribution_tracking_id': '46239229', 'order_id': '46239229'}
     assert args[0][0] == 'refund'
     actual = args[0][1]
     nose.tools.assert_equals(expected, actual)
@@ -206,7 +204,7 @@
     '''
     Test that express checkout recurring refunds are marked as ec too
     '''
-    row = get_ec_recurring_refund_row()
+    row = get_csv_row("express_checkout_recurring_refund")
 
     MockCivicrm().transaction_refunded.return_value = False
 
@@ -216,7 +214,7 @@
 
     # Did we send it?
     args = MockRedis().send.call_args
-    expected = {'last_name': 'Man', 'thankyou_date': 0, 'city': '', 
'payment_method': '', 'gateway_status': 'S', 'currency': 'USD', 'postal_code': 
'', 'date': 1474743301, 'gateway_refund_id': 'AS7D98AS7D9A8S7D9AS', 'gateway': 
'paypal_ec', 'state_province': '', 'gross': 10.0, 'first_name': 'Banana', 
'fee': 0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS', 'gross_currency': 'USD', 
'country': '', 'payment_submethod': '', 'note': 'refund', 
'supplemental_address_1': '', 'settled_date': 1474743301, 'gateway_parent_id': 
'3GJH3GJ3334214812', 'type': 'refund', 'email': '[email protected]', 
'street_address': '', 'contribution_tracking_id': '4123422', 'order_id': 
'4123422'}
+    expected = {'last_name': 'Who', 'thankyou_date': 0, 'city': '', 
'payment_method': 'Others', 'gateway_status': 'S', 'currency': 'JPY', 
'postal_code': '', 'date': 1490200431, 'gateway_refund_id': 
'8WG23468CX793000L', 'gateway': 'paypal_ec', 'state_province': '', 'gross': 
150.0, 'first_name': 'Cindy Lou', 'fee': 43.0, 'gateway_txn_id': 
'8WG23468CX793000L', 'gross_currency': 'JPY', 'country': '', 
'payment_submethod': '', 'note': 'refund', 'supplemental_address_1': '', 
'settled_date': 1490200431, 'gateway_parent_id': '4JH2438EE9876546W', 'type': 
'refund', 'email': '[email protected]', 'street_address': '', 
'contribution_tracking_id': '45931681', 'order_id': '45931681'}
     assert args[0][0] == 'refund'
     actual = args[0][1]
     nose.tools.assert_equals(expected, actual)

-- 
To view, visit https://gerrit.wikimedia.org/r/348503
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1feb85c7473747dfac2ca4f8dc1ce5a0c80c5a27
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/tools
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to