Commit e5d1c90a authored by Guillaume Risbourg's avatar Guillaume Risbourg Committed by hydrargyrum
Browse files

[bp] Changed ProAccountsList page is_here and handle new errors

The is_here on ProAccountsList caused the errors to not be catched.
New ActionNeeded error catched in ProAccountsList.
New BrowserUnavailable error catched in the RedirectPage.
parent 71c8205a
......@@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import os
from datetime import datetime, timedelta
......@@ -24,7 +26,10 @@
from weboob.browser.browsers import StatesMixin
from weboob.browser.exceptions import ServerError
from weboob.capabilities.base import NotAvailable
from weboob.exceptions import BrowserIncorrectPassword, BrowserBanned, NoAccountsException, BrowserUnavailable
from weboob.exceptions import (
BrowserIncorrectPassword, BrowserBanned, NoAccountsException,
BrowserUnavailable, ActionNeeded,
)
from weboob.tools.compat import urlsplit, urlunsplit, parse_qsl
from weboob.tools.decorators import retry
......@@ -233,8 +238,11 @@ def do_login(self):
self.location(self.login_url)
self.page.login(self.username, self.password)
if self.redirect_page.is_here() and self.page.check_for_perso():
raise BrowserIncorrectPassword(u"L'identifiant utilisé est celui d'un compte de Particuliers.")
if self.redirect_page.is_here():
if self.page.check_for_perso():
raise BrowserIncorrectPassword("L'identifiant utilisé est celui d'un compte de Particuliers.")
error = self.page.get_error()
raise BrowserUnavailable(error or '')
if self.badlogin.is_here():
raise BrowserIncorrectPassword()
if self.disabled_account.is_here():
......@@ -635,6 +643,13 @@ def get_history(self, account):
def _get_coming_transactions(self, account):
return []
def check_accounts_list_error(self):
error = self.page.get_errors()
if error:
if 'veuillez-vous rapprocher du mandataire principal de votre contrat' in error.lower():
raise ActionNeeded(error)
raise BrowserUnavailable(error or '')
@need_login
def get_accounts_list(self):
if self.accounts is None:
......@@ -646,6 +661,7 @@ def get_accounts_list(self):
self.location(self.accounts_url)
assert self.pro_accounts_list.is_here()
self.check_accounts_list_error()
for account in self.page.iter_accounts():
ids.add(account.id)
accounts.append(account)
......@@ -654,6 +670,7 @@ def get_accounts_list(self):
self.location(self.accounts_and_loans_url)
assert self.pro_accounts_list.is_here()
self.check_accounts_list_error()
for account in self.page.iter_accounts():
if account.id not in ids:
ids.add(account.id)
......
......@@ -26,7 +26,6 @@
from weboob.capabilities.bank import Account
from weboob.capabilities.profile import Company
from weboob.capabilities.base import NotAvailable
from weboob.exceptions import BrowserUnavailable
from .accounthistory import Transaction
from .base import MyHTMLPage
......@@ -36,6 +35,9 @@ class RedirectPage(LoggedPage, MyHTMLPage):
def check_for_perso(self):
return self.doc.xpath('''//p[contains(text(), "L'identifiant utilisé est celui d'un compte de Particuliers")]''')
def get_error(self):
return CleanText('//div[contains(@class, "bloc-erreur")]/h3')(self.doc)
ACCOUNT_TYPES = {
'Comptes titres': Account.TYPE_MARKET,
......@@ -51,12 +53,15 @@ class ProAccountsList(LoggedPage, MyHTMLPage):
# on the new website people are able to make personnalized groups of account instead of the usual drop-down categories on which to parse to find a match in ACCOUNT_TYPES
# If clients use the functionnality we might need to add entries new in ACCOUNT_TYPES
def on_load(self):
if self.doc.xpath('//div[@id="erreur_generale"]'):
raise BrowserUnavailable(CleanText('//div[@id="erreur_generale"]//p[contains(text(), "Le service est momentanément indisponible")]')(self.doc))
def is_here(self):
return CleanText('//h1[contains(text(), "Synthèse des comptes")]')(self.doc)
def get_errors(self):
# Full message for the second error is :
# Vous êtes uniquement habilité à accéder à OPnet.
# Pour toute modification de vos accès, veuillez-vous rapprocher
# du Mandataire Principal de votre contrat de banque en ligne.
return (
CleanText('//div[@id="erreur_generale"]//p[contains(text(), "Le service est momentanément indisponible")]')(self.doc)
or CleanText('//p[contains(text(), "veuillez-vous rapprocher du Mandataire Principal de votre contrat")]')(self.doc)
)
@method
class iter_accounts(ListElement):
......
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