From cd61c38e9c9e6c585bafbd25562a27542d419c91 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 10 Apr 2020 14:10:00 +0200 Subject: [PATCH] [IMP] account_bank_statement_import_online_paypal: tests --- .../online_bank_statement_provider_paypal.py | 16 +++++++--------- ...ount_bank_statement_import_online_paypal.py | 18 ++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py b/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py index b0e27b9..96bb158 100644 --- a/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py +++ b/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 diff --git a/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py b/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py index c600184..792eb25 100644 --- a/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py +++ b/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({