Browse Source

[IMP] account_bank_statement_import_online_paypal: tests

12.0
Alexey Pelykh 5 years ago
parent
commit
cd61c38e9c
  1. 16
      account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py
  2. 18
      account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py

16
account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py

@ -478,18 +478,16 @@ class OnlineBankStatementProviderPayPal(models.Model):
@api.model
def _paypal_decode_error(self, content):
generic_error = content.get('name')
if generic_error:
if 'name' in content:
return UserError('%s: %s' % (
generic_error,
content.get('message') or _('Unknown error'),
content['name'],
content.get('message', _('Unknown error')),
))
identity_error = content.get('error')
if identity_error:
UserError('%s: %s' % (
generic_error,
content.get('error_description') or _('Unknown error'),
if 'error' in content:
return UserError('%s: %s' % (
content['error'],
content.get('error_description', _('Unknown error')),
))
return None

18
account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py

@ -226,18 +226,15 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
provider = journal.online_bank_statement_provider_id
mocked_response = UrlopenRetValMock("""{
"message": "MSG",
"message": "MESSAGE",
"name": "ERROR"
}""", throw=True)
with mock.patch(
_provider_class + '._paypal_urlopen',
return_value=mocked_response,
), self.mock_token():
):
with self.assertRaises(UserError):
provider._obtain_statement_data(
self.now - relativedelta(years=5),
self.now,
)
provider._paypal_retrieve('https://url', '')
def test_error_handling_2(self):
journal = self.AccountJournal.create({
@ -251,18 +248,15 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
provider = journal.online_bank_statement_provider_id
mocked_response = UrlopenRetValMock("""{
"error_description": "DESC",
"error_description": "ERROR DESCRIPTION",
"error": "ERROR"
}""", throw=True)
with mock.patch(
_provider_class + '._paypal_urlopen',
return_value=mocked_response,
), self.mock_token():
):
with self.assertRaises(UserError):
provider._obtain_statement_data(
self.now - relativedelta(years=5),
self.now,
)
provider._paypal_retrieve('https://url', '')
def test_empty_pull(self):
journal = self.AccountJournal.create({

Loading…
Cancel
Save