From 0ac06309cd5a8884d5f45b7cb40cb96c84a9a904 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 --- .../__manifest__.py | 2 +- ...unt_bank_statement_import_online_paypal.pot | 8 ++++---- .../online_bank_statement_provider_paypal.py | 16 +++++++--------- ...ount_bank_statement_import_online_paypal.py | 18 ++++++------------ 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/account_bank_statement_import_online_paypal/__manifest__.py b/account_bank_statement_import_online_paypal/__manifest__.py index 30040ea3..777ccd7b 100644 --- a/account_bank_statement_import_online_paypal/__manifest__.py +++ b/account_bank_statement_import_online_paypal/__manifest__.py @@ -4,7 +4,7 @@ { 'name': 'Online Bank Statements: PayPal.com', - 'version': '12.0.1.0.1', + 'version': '12.0.1.0.2', 'author': 'Brainbean Apps, ' 'Dataplug, ' diff --git a/account_bank_statement_import_online_paypal/i18n/account_bank_statement_import_online_paypal.pot b/account_bank_statement_import_online_paypal/i18n/account_bank_statement_import_online_paypal.pot index fe712b34..d7cb41e7 100644 --- a/account_bank_statement_import_online_paypal/i18n/account_bank_statement_import_online_paypal.pot +++ b/account_bank_statement_import_online_paypal/i18n/account_bank_statement_import_online_paypal.pot @@ -554,7 +554,7 @@ msgid "Mobile payment, made through a mobile phone" msgstr "" #. module: account_bank_statement_import_online_paypal -#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:522 +#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:520 #, python-format msgid "No authentication specified!" msgstr "" @@ -852,14 +852,14 @@ msgid "Transfer to external GL entity" msgstr "" #. module: account_bank_statement_import_online_paypal -#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:538 +#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:536 #, python-format msgid "Unknown authentication specified!" msgstr "" #. module: account_bank_statement_import_online_paypal -#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:485 -#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:492 +#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:484 +#: code:addons/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py:490 #, python-format msgid "Unknown error" msgstr "" 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 b0e27b9c..96bb1583 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 c600184a..792eb25e 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({