From 3d361e829bafa947c7ec84c5d3879374a01e8802 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Thu, 27 Aug 2020 15:02:04 +0200 Subject: [PATCH] [boursorama] Handle new recipients page Some users have a different page on which they need to go to have the list of their recipients. --- modules/boursorama/browser.py | 21 ++++++++++++-- modules/boursorama/pages.py | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/modules/boursorama/browser.py b/modules/boursorama/browser.py index e75804cd5a..ec060b5d7f 100644 --- a/modules/boursorama/browser.py +++ b/modules/boursorama/browser.py @@ -50,7 +50,8 @@ CardsNumberPage, CalendarPage, HomePage, PEPPage, TransferAccounts, TransferRecipients, TransferCharac, TransferConfirm, TransferSent, AddRecipientPage, StatusPage, CardHistoryPage, CardCalendarPage, CurrencyListPage, CurrencyConvertPage, - AccountsErrorPage, NoAccountPage, TransferMainPage, PasswordPage, + AccountsErrorPage, NoAccountPage, TransferMainPage, PasswordPage, NewTransferRecipients, + NewTransferAccounts, ) from .transfer_pages import TransferListPage, TransferInfoPage @@ -121,6 +122,15 @@ class BoursoramaBrowser(RetryLoginBrowser, TwoFactorBrowser): r'/compte/(?P[^/]+)/(?P\w+)/virements/nouveau/(?P\w+)/2', TransferRecipients ) + new_transfer_accounts = URL( + r'/compte/(?P[^/]+)/(?P\w+)/virements/immediat/nouveau/?$', + r'/compte/(?P[^/]+)/(?P\w+)/virements/immediat/nouveau/(?P\w+)/1', + NewTransferAccounts + ) + new_recipients_page = URL( + r'/compte/(?P[^/]+)/(?P\w+)/virements/immediat/nouveau/(?P\w+)/2', + NewTransferRecipients + ) transfer_charac = URL( r'/compte/(?P[^/]+)/(?P\w+)/virements/nouveau/(?P\w+)/3', TransferCharac @@ -560,6 +570,9 @@ def go_recipients_list(self, account_url, account_id): if self.transfer_accounts.is_here(): self.page.submit_account(account_id) # may raise AccountNotFound + elif self.transfer_main_page.is_here(): + self.new_transfer_accounts.go(acc_type=account_type, webid=account_webid) + self.page.submit_account(account_id) # may raise AccountNotFound @need_login def iter_transfer_recipients(self, account): @@ -572,7 +585,11 @@ def iter_transfer_recipients(self, account): except (BrowserHTTPNotFound, AccountNotFound): return [] - assert self.recipients_page.is_here() + assert ( + self.recipients_page.is_here() + or self.new_recipients_page.is_here() + ), 'Should be on recipients page' + return self.page.iter_recipients() def check_basic_transfer(self, transfer): diff --git a/modules/boursorama/pages.py b/modules/boursorama/pages.py index 11e1cbb744..eb32c967ca 100644 --- a/modules/boursorama/pages.py +++ b/modules/boursorama/pages.py @@ -1255,6 +1255,60 @@ def submit_recipient(self, tempid): form.submit() +class NewTransferRecipients(LoggedPage, HTMLPage): + @method + class iter_recipients(ListElement): + item_xpath = '//div[contains(@id, "panel-")]//div[contains(@class, "panel__body")]//label' + + class item(ItemElement): + klass = Recipient + + obj_id = CleanText( + './/span[contains(@class, "sub-label")]/span[not(contains(@class,"sub-label"))]', + replace=[(' ', '')], + ) + + obj_label = Regexp( + CleanText('.//span[contains(@class, "account-label")]'), + r'([^-]+)', + '\\1', + ) + + def obj_category(self): + text = CleanText( + './ancestor::div[contains(@class, "panel__body")]' + + '/preceding-sibling::div[contains(@class, "panel__header")]' + + '//span[contains(@class, "panel__title")]' + )(self).lower() + if 'mes comptes boursorama banque' in text: + return 'Interne' + elif any(exp in text for exp in ('comptes externes', 'comptes de tiers', 'mes bénéficiaires')): + return 'Externe' + + def obj_iban(self): + if Field('category')(self) == 'Externe': + return Field('id')(self) + return NotAvailable + + def obj_enabled_at(self): + return datetime.datetime.now().replace(microsecond=0) + + obj__tempid = Attr('./input', 'value') + + +class NewTransferAccounts(LoggedPage, HTMLPage): + def submit_account(self, account_id): + form = self.get_form() + debit_account = CleanText( + '//input[./following-sibling::div/span/span[contains(text(), "%s")]]/@value' % account_id + )(self.doc) + if not debit_account: + raise AccountNotFound() + + form['DebitAccount[debit]'] = debit_account + form.submit() + + class TransferCharac(LoggedPage, HTMLPage): def get_option(self, select, text): for opt in select.xpath('option'): -- GitLab