Commit c1b5b6fe authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Romain Bignon

[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
parent f5745d12
......@@ -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 @@ class S2eBrowser(LoginBrowser, StatesMixin):
@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 @@ class S2eBrowser(LoginBrowser, StatesMixin):
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']
......
......@@ -31,7 +31,7 @@ from weboob.browser.filters.html import Attr, TableCell
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 @@ class MultiPage(HTMLPage):
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 @@ class AccountsPage(LoggedPage, MultiPage):
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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment