Browse Source

[FIX] account_statement_import_online_paypal: tests

12.0
Alexey Pelykh 2 years ago
parent
commit
bfc414df63
  1. 244
      account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py

244
account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py

@ -1,4 +1,5 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2022 CorporateHub (https://corporatehub.eu)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import datetime
@ -53,6 +54,13 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
super().setUp()
self.now = fields.Datetime.now()
self.now_isoformat = self.now.isoformat() + '+0000'
self.today = datetime(self.now.year, self.now.month, self.now.day)
self.today_isoformat = self.today.isoformat() + '+0000'
self.today_timestamp = str(int(self.today.timestamp()))
self.yesterday = self.today - relativedelta(days=1)
self.yesterday_isoformat = self.yesterday.isoformat() + '+0000'
self.yesterday_timestamp = str(int(self.yesterday.timestamp()))
self.currency_eur = self.env.ref('base.EUR')
self.currency_usd = self.env.ref('base.USD')
self.AccountJournal = self.env['account.journal']
@ -220,9 +228,10 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
}
],
"account_id": "1234567890",
"as_of_time": "2019-08-01T00:00:00+0000",
"last_refresh_time": "2019-08-01T00:00:00+0000"
}""")
"as_of_time": "%s",
"last_refresh_time": "%s"
}""" % (self.now_isoformat, self.now_isoformat,)
)
with mock.patch(
_provider_class + '._paypal_urlopen',
side_effect=[mocked_response_1, mocked_response_2],
@ -297,14 +306,17 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
mocked_response_1 = json.loads("""{
"transaction_details": [],
"account_number": "1234567890",
"start_date": "2019-08-01T00:00:00+0000",
"end_date": "2019-08-01T00:00:00+0000",
"last_refreshed_datetime": "2019-09-01T00:00:00+0000",
"start_date": "%s",
"end_date": "%s",
"last_refreshed_datetime": "%s",
"page": 1,
"total_items": 0,
"total_pages": 0
}""", parse_float=Decimal)
mocked_response_2 = json.loads("""{
}""" % (self.now_isoformat, self.now_isoformat, self.now_isoformat,),
parse_float=Decimal,
)
mocked_response_2 = json.loads(
"""{
"balances": [
{
"currency": "EUR",
@ -324,9 +336,12 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
}
],
"account_id": "1234567890",
"as_of_time": "2019-08-01T00:00:00+0000",
"last_refresh_time": "2019-08-01T00:00:00+0000"
}""", parse_float=Decimal)
"as_of_time": "%s",
"last_refresh_time": "%s"
}"""
% (self.now_isoformat, self.now_isoformat,),
parse_float=Decimal,
)
with mock.patch(
_provider_class + '._paypal_retrieve',
side_effect=[mocked_response_1, mocked_response_2],
@ -355,13 +370,15 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
mocked_response = json.loads("""{
"transaction_details": [],
"account_number": "1234567890",
"start_date": "2019-08-01T00:00:00+0000",
"end_date": "2019-08-01T00:00:00+0000",
"last_refreshed_datetime": "2019-09-01T00:00:00+0000",
"start_date": "%s",
"end_date": "%s",
"last_refreshed_datetime": "%s",
"page": 1,
"total_items": 0,
"total_pages": 0
}""", parse_float=Decimal)
}""" % (self.now_isoformat, self.now_isoformat, self.now_isoformat,),
parse_float=Decimal,
)
with mock.patch(
_provider_class + '._paypal_retrieve',
return_value=mocked_response,
@ -389,8 +406,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567890",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-01T00:00:00+0000",
"transaction_updated_date": "2019-08-01T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -431,8 +448,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567891",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-02T00:00:00+0000",
"transaction_updated_date": "2019-08-02T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -470,43 +487,53 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"incentive_info": {}
}],
"account_number": "1234567890",
"start_date": "2019-08-01T00:00:00+0000",
"end_date": "2019-08-02T00:00:00+0000",
"last_refreshed_datetime": "2019-09-01T00:00:00+0000",
"start_date": "%s",
"end_date": "%s",
"last_refreshed_datetime": "%s",
"page": 1,
"total_items": 1,
"total_pages": 1
}""", parse_float=Decimal)
}""" % (
self.yesterday_isoformat,
self.yesterday_isoformat,
self.today_isoformat,
self.today_isoformat,
self.yesterday_isoformat,
self.today_isoformat,
self.now_isoformat,
),
parse_float=Decimal,
)
with mock.patch(
_provider_class + '._paypal_retrieve',
return_value=mocked_response,
), self.mock_token():
data = provider._obtain_statement_data(
datetime(2019, 8, 1),
datetime(2019, 8, 2),
)
data = provider._obtain_statement_data(self.yesterday, self.today,)
self.assertEqual(len(data[0]), 2)
self.assertEqual(data[0][0], {
'date': datetime(2019, 8, 1),
'amount': '1000.00',
'name': 'Invoice 1',
'note': '1234567890: Payment for Invoice(s) 1',
'partner_name': 'Acme, Inc.',
'unique_import_id': '1234567890-1564617600',
})
self.assertEqual(data[0][1], {
'date': datetime(2019, 8, 1),
'amount': '-100.00',
'name': 'Fee for Invoice 1',
'note': 'Transaction fee for 1234567890: Payment for Invoice(s) 1',
'partner_name': 'PayPal',
'unique_import_id': '1234567890-1564617600-FEE',
})
self.assertEqual(data[1], {
'balance_start': 0.0,
'balance_end_real': 900.0,
})
self.assertEqual(
data[0][0],
{
"date": self.yesterday,
"amount": "1000.00",
"name": "Invoice 1",
"note": "1234567890: Payment for Invoice(s) 1",
"partner_name": "Acme, Inc.",
"unique_import_id": "1234567890-%s" % (self.yesterday_timestamp,),
},
)
self.assertEqual(
data[0][1],
{
"date": self.yesterday,
"amount": "-100.00",
"name": "Fee for Invoice 1",
"note": "Transaction fee for 1234567890: Payment for Invoice(s) 1",
"partner_name": "PayPal",
"unique_import_id": "1234567890-%s-FEE" % (self.yesterday_timestamp,),
},
)
self.assertEqual(data[1], {"balance_start": 0.0, "balance_end_real": 900.0})
def test_transaction_parse_1(self):
lines = self.paypal_parse_transaction("""{
@ -514,8 +541,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567890",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-01T00:00:00+0000",
"transaction_updated_date": "2019-08-01T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -551,16 +578,20 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"store_info": {},
"auction_info": {},
"incentive_info": {}
}""")
}""" % (self.today_isoformat, self.today_isoformat,)
)
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0], {
'date': datetime(2019, 8, 1),
'amount': '1000.00',
'name': 'Invoice 1',
'note': '1234567890: Payment for Invoice(s) 1',
'partner_name': 'Acme, Inc.',
'unique_import_id': '1234567890-1564617600',
})
self.assertEqual(
lines[0],
{
"date": self.today,
"amount": "1000.00",
"name": "Invoice 1",
"note": "1234567890: Payment for Invoice(s) 1",
"partner_name": "Acme, Inc.",
"unique_import_id": "1234567890-%s" % (self.today_timestamp,),
},
)
def test_transaction_parse_2(self):
lines = self.paypal_parse_transaction("""{
@ -568,8 +599,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567890",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-01T00:00:00+0000",
"transaction_updated_date": "2019-08-01T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -605,16 +636,20 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"store_info": {},
"auction_info": {},
"incentive_info": {}
}""")
}""" % (self.today_isoformat, self.today_isoformat,)
)
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0], {
'date': datetime(2019, 8, 1),
'amount': '1000.00',
'name': 'Invoice 1',
'note': '1234567890: Payment for Invoice(s) 1',
'partner_name': 'Acme, Inc.',
'unique_import_id': '1234567890-1564617600',
})
self.assertEqual(
lines[0],
{
"date": self.today,
"amount": "1000.00",
"name": "Invoice 1",
"note": "1234567890: Payment for Invoice(s) 1",
"partner_name": "Acme, Inc.",
"unique_import_id": "1234567890-%s" % (self.today_timestamp,),
},
)
def test_transaction_parse_3(self):
lines = self.paypal_parse_transaction("""{
@ -622,8 +657,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567890",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-01T00:00:00+0000",
"transaction_updated_date": "2019-08-01T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -659,24 +694,31 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"store_info": {},
"auction_info": {},
"incentive_info": {}
}""")
}""" % (self.today_isoformat, self.today_isoformat,)
)
self.assertEqual(len(lines), 2)
self.assertEqual(lines[0], {
'date': datetime(2019, 8, 1),
'amount': '1000.00',
'name': 'Invoice 1',
'note': '1234567890: Payment for Invoice(s) 1',
'partner_name': 'Acme, Inc.',
'unique_import_id': '1234567890-1564617600',
})
self.assertEqual(lines[1], {
'date': datetime(2019, 8, 1),
'amount': '-100.00',
'name': 'Fee for Invoice 1',
'note': 'Transaction fee for 1234567890: Payment for Invoice(s) 1',
'partner_name': 'PayPal',
'unique_import_id': '1234567890-1564617600-FEE',
})
self.assertEqual(
lines[0],
{
"date": self.today,
"amount": "1000.00",
"name": "Invoice 1",
"note": "1234567890: Payment for Invoice(s) 1",
"partner_name": "Acme, Inc.",
"unique_import_id": "1234567890-%s" % (self.today_timestamp,),
},
)
self.assertEqual(
lines[1],
{
"date": self.today,
"amount": "-100.00",
"name": "Fee for Invoice 1",
"note": "Transaction fee for 1234567890: Payment for Invoice(s) 1",
"partner_name": "PayPal",
"unique_import_id": "1234567890-%s-FEE" % (self.today_timestamp,),
},
)
def test_transaction_parse_4(self):
lines = self.paypal_parse_transaction("""{
@ -684,8 +726,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"paypal_account_id": "1234567890",
"transaction_id": "1234567890",
"transaction_event_code": "T1234",
"transaction_initiation_date": "2019-08-01T00:00:00+0000",
"transaction_updated_date": "2019-08-01T00:00:00+0000",
"transaction_initiation_date": "%s",
"transaction_updated_date": "%s",
"transaction_amount": {
"currency_code": "USD",
"value": "1000.00"
@ -717,13 +759,17 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
"store_info": {},
"auction_info": {},
"incentive_info": {}
}""")
}""" % (self.today_isoformat, self.today_isoformat,)
)
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0], {
'date': datetime(2019, 8, 1),
'amount': '1000.00',
'name': 'Invoice 1',
'note': '1234567890: Payment for Invoice(s) 1',
'partner_name': 'Acme, Inc.',
'unique_import_id': '1234567890-1564617600',
})
self.assertEqual(
lines[0],
{
"date": self.today,
"amount": "1000.00",
"name": "Invoice 1",
"note": "1234567890: Payment for Invoice(s) 1",
"partner_name": "Acme, Inc.",
"unique_import_id": "1234567890-%s" % (self.today_timestamp,),
},
)
Loading…
Cancel
Save