Browse Source

Merge PR #271 into 12.0

Signed-off-by alexey-pelykh
12.0
OCA-git-bot 5 years ago
parent
commit
2b23212de5
  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 @api.model
def _paypal_decode_error(self, content): def _paypal_decode_error(self, content):
generic_error = content.get('name')
if generic_error:
if 'name' in content:
return UserError('%s: %s' % ( 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 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 provider = journal.online_bank_statement_provider_id
mocked_response = UrlopenRetValMock("""{ mocked_response = UrlopenRetValMock("""{
"message": "MSG",
"message": "MESSAGE",
"name": "ERROR" "name": "ERROR"
}""", throw=True) }""", throw=True)
with mock.patch( with mock.patch(
_provider_class + '._paypal_urlopen', _provider_class + '._paypal_urlopen',
return_value=mocked_response, return_value=mocked_response,
), self.mock_token():
):
with self.assertRaises(UserError): 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): def test_error_handling_2(self):
journal = self.AccountJournal.create({ journal = self.AccountJournal.create({
@ -251,18 +248,15 @@ class TestAccountBankAccountStatementImportOnlinePayPal(
provider = journal.online_bank_statement_provider_id provider = journal.online_bank_statement_provider_id
mocked_response = UrlopenRetValMock("""{ mocked_response = UrlopenRetValMock("""{
"error_description": "DESC",
"error_description": "ERROR DESCRIPTION",
"error": "ERROR" "error": "ERROR"
}""", throw=True) }""", throw=True)
with mock.patch( with mock.patch(
_provider_class + '._paypal_urlopen', _provider_class + '._paypal_urlopen',
return_value=mocked_response, return_value=mocked_response,
), self.mock_token():
):
with self.assertRaises(UserError): 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): def test_empty_pull(self):
journal = self.AccountJournal.create({ journal = self.AccountJournal.create({

Loading…
Cancel
Save