From c1b5b6feff63cee3eebe40a5dfbd25230db441c9 Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Fri, 3 May 2019 11:41:50 +0200 Subject: [PATCH] [s2e] Raise NoAccountException only if we found message & found no account The NoAccountsException was raised in the on_load() of the AccountsPage, except that if there are several spaces, no account will be returned just because one of the spaces has no accounts. This patch raises NoAccounts only if the accounts list is empty after visiting all the perimeters. Closes: 10264@zendesk --- modules/s2e/browser.py | 13 +++++++++++-- modules/s2e/pages.py | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/modules/s2e/browser.py b/modules/s2e/browser.py index 4ab71dcc0b..4bb140d32d 100644 --- a/modules/s2e/browser.py +++ b/modules/s2e/browser.py @@ -19,7 +19,7 @@ from weboob.browser import LoginBrowser, URL, need_login, StatesMixin -from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded +from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded, NoAccountsException from .pages import ( LoginPage, AccountsPage, AMFHSBCPage, AMFAmundiPage, AMFSGPage, HistoryPage, @@ -82,6 +82,7 @@ def do_login(self): @need_login def iter_accounts(self): if 'accs' not in self.cache.keys(): + no_accounts_message = None self.accounts.stay_or_go(slug=self.SLUG, lang=self.LANG) # weird wrongpass if not self.accounts.is_here(): @@ -92,11 +93,19 @@ def iter_accounts(self): accs = [] for id in multi: self.page.go_multi(id) - for a in self.accounts.go(slug=self.SLUG).iter_accounts(): + self.accounts.go(slug=self.SLUG) + if not no_accounts_message: + no_accounts_message = self.page.get_no_accounts_message() + for a in self.page.iter_accounts(): a._multi = id accs.append(a) else: + no_accounts_message = self.page.get_no_accounts_message() accs = [a for a in self.page.iter_accounts()] + if not len(accs) and no_accounts_message: + # Accounts list is empty and we found the + # message on at least one of the spaces: + raise NoAccountsException(no_accounts_message) self.cache['accs'] = accs return self.cache['accs'] diff --git a/modules/s2e/pages.py b/modules/s2e/pages.py index 24b5804b0e..324e6a01cc 100644 --- a/modules/s2e/pages.py +++ b/modules/s2e/pages.py @@ -31,7 +31,7 @@ from weboob.capabilities.bank import Account, Investment, Pocket, Transaction from weboob.capabilities.base import NotAvailable from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard -from weboob.exceptions import NoAccountsException, BrowserUnavailable, ActionNeeded, BrowserQuestion, BrowserIncorrectPassword +from weboob.exceptions import BrowserUnavailable, ActionNeeded, BrowserQuestion, BrowserIncorrectPassword from weboob.tools.value import Value from weboob.tools.compat import urljoin @@ -329,13 +329,6 @@ def go_multi(self, id): class AccountsPage(LoggedPage, MultiPage): def on_load(self): - no_accounts_message = CleanText('//span[contains(text(), "On this date, you still have no employee savings in this company.")] | ' - '//span[contains(text(), "On this date, you do not yet have any employee savings in this company.")] | ' - '//span[contains(text(), "On this date, you no longer have any employee savings in this company.")] | ' - '//p[contains(text(), "You no longer have any employee savings.")]')(self.doc) - if no_accounts_message: - raise NoAccountsException(no_accounts_message) - if CleanText('//a//span[contains(text(), "J\'ACCEPTE LES CONDITIONS GENERALES D\'UTILISATION") or' ' contains(text(), "I ACCEPT THE GENERAL CONDITIONS OF USE")]')(self.doc): raise ActionNeeded("Veuillez valider les conditions générales d'utilisation") @@ -361,6 +354,16 @@ def on_load(self): u'retraite': Pocket.CONDITION_RETIREMENT, } + def get_no_accounts_message(self): + no_accounts_message = CleanText( + '//span[contains(text(), "A ce jour, vous ne disposez plus d\'épargne salariale dans cette entreprise.")] | ' + '//span[contains(text(), "On this date, you still have no employee savings in this company.")] | ' + '//span[contains(text(), "On this date, you do not yet have any employee savings in this company.")] | ' + '//span[contains(text(), "On this date, you no longer have any employee savings in this company.")] | ' + '//p[contains(text(), "You no longer have any employee savings.")]' + )(self.doc) + return no_accounts_message + @method class iter_accounts(TableElement): item_xpath = '//div[contains(@id, "Dispositif")]//table/tbody/tr' -- GitLab