From 1dfa6b258a13d35f7a60fb9e1bbbc7b3e6aa19cd Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Thu, 28 Feb 2019 15:16:56 +0100 Subject: [PATCH] [caissedepargne] Handle inactive accounts Inactive accounts have no link and if we try to click for history or investments, it returns a BrowserUnavailable. So we must verify if they are inactive before trying requests. --- modules/caissedepargne/browser.py | 6 ++++++ modules/caissedepargne/pages.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 7adad3ec87..e296359c71 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -536,6 +536,9 @@ def _get_history_invests(self, account): self.page.go_history(account._info) if account.type in (Account.TYPE_LIFE_INSURANCE, Account.TYPE_PERP): + if self.page.is_account_inactive(account.id): + self.logger.warning('Account %s %s is inactive.' % (account.label, account.id)) + return iter([]) if "MILLEVIE" in account.label: self.page.go_life_insurance(account) label = account.label.split()[-1] @@ -627,6 +630,9 @@ def get_investment(self, account): return elif account.type in (Account.TYPE_LIFE_INSURANCE, Account.TYPE_CAPITALISATION): + if self.page.is_account_inactive(account.id): + self.logger.warning('Account %s %s is inactive.' % (account.label, account.id)) + return if "MILLEVIE" in account.label: self.page.go_life_insurance(account) label = account.label.split()[-1] diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index f55085ca53..e8443d2cec 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -281,6 +281,9 @@ def _get_account_info(self, a, accounts): info['acc_type'] = Account.TYPE_MARKET return info + def is_account_inactive(self, account_id): + return self.doc.xpath('//tr[td[contains(text(), $id)]][@class="Inactive"]', id=account_id) + def _add_account(self, accounts, link, label, account_type, balance): info = self._get_account_info(link, accounts) if info is None: -- GitLab