jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/344725 )
Change subject: Fix dictionary comparison
..
Fix dictionary comparison
Oops! sorted(dict) was just leaving us with the keys
Also, fix date parsing to take timezone into account and get
correct unix timestamp.
Change-Id: I9827b9fcdd62549583dd54031589306542c1f39b
---
M audit/paypal/ppreport.py
M audit/paypal/tests/test_trr_file.py
2 files changed, 15 insertions(+), 7 deletions(-)
Approvals:
XenoRyet: Looks good to me, approved
jenkins-bot: Verified
diff --git a/audit/paypal/ppreport.py b/audit/paypal/ppreport.py
index a04c159..7fa405a 100644
--- a/audit/paypal/ppreport.py
+++ b/audit/paypal/ppreport.py
@@ -1,4 +1,6 @@
+import datetime
import dateutil.parser
+import dateutil.tz
import io
from failmail.mailer import FailMailer
@@ -52,4 +54,7 @@
def parse_date(date_string):
date_object = dateutil.parser.parse(date_string)
-return date_object.strftime('%s')
+utc = dateutil.tz.gettz('UTC')
+date_utc = date_object.astimezone(utc)
+epoch = datetime.datetime(1970, 1, 1, tzinfo=utc)
+return int((date_utc - epoch).total_seconds())
diff --git a/audit/paypal/tests/test_trr_file.py
b/audit/paypal/tests/test_trr_file.py
index 2cf3c3e..0249477 100644
--- a/audit/paypal/tests/test_trr_file.py
+++ b/audit/paypal/tests/test_trr_file.py
@@ -3,6 +3,9 @@
import audit.paypal.TrrFile
+# weird thing we have to do to get better assert_equals feedback
+nose.tools.assert_equals.im_class.maxDiff = None
+
def get_base_row():
@@ -135,9 +138,9 @@
# Did we send it?
args = MockRedis().send.call_args
assert args[0][0] == 'refund'
-expected = sorted({'last_name': 'Man', 'thankyou_date': 0, 'city': '',
'payment_method': '', 'gateway_status': 'S', 'currency': 'USD', 'postal_code':
'', 'date': '1474736101', 'gateway_refund_id': 'AS7D98AS7D9A8S7D9AS',
'gateway': 'paypal', 'state_province': '', 'gross': 10.0, 'first_name':
'Banana', 'fee': 0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS',
'gross_currency': 'USD', 'country': '', 'payment_submethod': '', 'note': 'r',
'supplemental_address_1': '', 'settled_date': '1474736101',
'gateway_parent_id': '3GJH3GJ3334214812', 'type': 'refund', 'email':
'pranks...@anonymous.net', 'street_address': '', 'contribution_tracking_id':
'1234567', 'order_id': '1234567'})
-actual = sorted(args[0][1])
-assert actual == expected
+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', 'state_province': '', 'gross': 10.0, 'first_name': 'Banana', 'fee':
0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS', 'gross_currency': 'USD',
'country': '', 'payment_submethod': '', 'note': 'r', 'supplemental_address_1':
'', 'settled_date': 1474743301, 'gateway_parent_id': '3GJH3GJ3334214812',
'type': 'refund', 'email': 'pranks...@anonymous.net', 'street_address': '',
'contribution_tracking_id': '1234567', 'order_id': '1234567'}
+actual = args[0][1]
+nose.tools.assert_equals(expected, actual)
@patch("queue.redis_wrap.Redis")
@@ -175,6 +178,6 @@
# Did we send it?
args = MockRedis().send.call_args
assert args[0][0] == 'recurring'
-expected = sorted({'last_name': 'Man', 'txn_type': 'subscr_payment',
'thankyou_date': 0, 'city': '', 'payment_method': '', 'gateway_status': 'S',
'currency': 'USD', 'postal_code': '', 'date': '1474736101', 'subscr_id':
'3GJH3GJ3334214812', 'gateway': 'paypal', 'state_province': '', 'gross': 0.1,
'first_name': 'Banana', 'fee': 0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS',
'country': '', 'payment_submethod': '', 'note': '', 'supplemental_address_1':
'', 'settled_date': '1474736101', 'email': 'pranks...@anonymous.net',
'street_address': '', 'contribution_tracking_id': '1234567', 'order_id':
'1234567'})
-actual = sorted(args[0][1])
-assert actual == expected
+expected = {'last_name': 'Man', 'txn_type': 'subscr_payment',
'thankyou_date': 0, 'city': '', 'payment_method': '', 'gateway_status': 'S',
'currency': 'USD', 'postal_code': '', 'date': 1474743301, 'subscr_id':
'3GJH3GJ3334214812', 'gateway': 'paypal', 'state_province': '', 'gross': 0.1,
'first_name': 'Banana', 'fee': 0.55, 'gateway_txn_id': 'AS7D98AS7D9A8S7D9AS',
'country': '', 'payment_submethod': '', 'note': '', 'supplemental_address_1':
'', 'settled_date': 1474743301, 'email': 'pranks...@anonymous.net',
'street_address': '', 'contribution_tracking_id': '1234567', 'order_id':
'1234567'}
+actual = args[0][1]
+nose.tools.assert_equals(expected, actual)
--
To view, visit https://gerrit.wikimedia.org/r/344725
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9827b9fcdd62549583dd54031589306542c1f39b
Ger