From 153dcbd6ce3a9b3c02324fd6ee5403dee569ae5c Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Tue, 2 Jun 2020 12:38:19 +0200 Subject: [PATCH] [caissedepargne] Handle error message when user has no 2fa method enabled When the user has no 2fa method enabled, there is a specific error message that needs to be caught. --- modules/caissedepargne/browser.py | 9 +++++++++ modules/caissedepargne/pages.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 23a75577b4..25298febf7 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -35,6 +35,7 @@ from weboob.browser.url import URL from weboob.capabilities.bank import ( Account, AddRecipientStep, Recipient, TransferBankError, Transaction, TransferStep, + AddRecipientBankError, ) from weboob.capabilities.base import NotAvailable, find_object from weboob.capabilities.bill import Subscription @@ -1480,6 +1481,14 @@ def new_recipient(self, recipient, **params): self.page.handle_error() assert False, 'We should not be on this page.' + if self.home.is_here(): + # If we land here it might be because the user has no 2fa method + # enabled, and therefore cannot add a recipient. + unavailable_2fa = self.page.get_unavailable_2fa_message() + if unavailable_2fa: + raise AddRecipientBankError(message=unavailable_2fa) + raise AssertionError('Should not be on home page after sending sms when adding new recipient.') + if self.validation_option.is_here(): self.get_auth_mechanisms_validation_info() diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index 9a90b0bdd5..153f78dc76 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -1135,6 +1135,14 @@ def get_trusted_device_url(self): default=None, )(self.doc) + def get_unavailable_2fa_message(self): + # The message might be too long, so we retrieve only the first part. + return CleanText( + '''//div[@class="MessageErreur"] + //li[contains(text(), "vous devez disposer d’un moyen d’authentification renforcée")] + /br/preceding-sibling::text()''' + )(self.doc) + class TransactionPopupPage(LoggedPage, HTMLPage): def is_here(self): -- GitLab