Commit ae823412 authored by Olivier Da Rocha's avatar Olivier Da Rocha Committed by Vincent A

[bp] handle account details page not being available

Sometimes the details page is not yet accessible for some accounts.
Prevent crashing in this case.
parent bf342691
......@@ -564,9 +564,15 @@ class BPBrowser(LoginBrowser, StatesMixin):
elif account.type == Account.TYPE_PERP:
# PERP balances must be fetched from the details page,
# otherwise we just scrape the "Rente annuelle estimée":
balance = self.open(account.url).page.get_balance()
if balance is not None:
account.balance = balance
balance_page = self.open(account.url).page
# Sometimes the balance page is not available (with the site saying the account detail will
# soon be available). In the meantime, just skip it and use the balance we already have.
if balance_page and isinstance(balance_page, SavingAccountSummary):
balance = balance_page.get_balance()
if balance is not None:
account.balance = balance
else:
self.logger.debug('Balance page not yet available for account %r', account)
accounts.append(account)
else:
......
......@@ -116,6 +116,10 @@ class item_account_generic(ItemElement):
coming = 0
details_page = self.page.browser.open(Field('url')(self))
if not details_page.page:
# Details page might not always be available
return NotAvailable
coming_op_link = Link(
'//a[contains(text(), "Opérations à venir")]',
default=NotAvailable
......@@ -157,6 +161,10 @@ class item_account_generic(ItemElement):
return NotAvailable
details_page = self.page.browser.open(Field('url')(self)).page
if not details_page:
# Details page might not always be available
return NotAvailable
rib_link = Link('//a[abbr[contains(text(), "RIB")]]', default=NotAvailable)(details_page.doc)
if rib_link:
response = self.page.browser.open(rib_link)
......@@ -516,7 +524,12 @@ class AccountRIB(LoggedPage, RawPage):
iban_regexp = r'[A-Z]{2}\d{12}[0-9A-Z]{11}\d{2}'
def get_iban(self):
m = re.search(self.iban_regexp, extract_text(self.data))
content = extract_text(self.data)
if not content:
# This can happen if there's an error on the site while rendering the PDF (no RIB is shown)
return NotAvailable
m = re.search(self.iban_regexp, content)
if m:
return unicode(m.group(0))
return None
......
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