From d04c7823d8974238e81609a84e8c73525fac131f Mon Sep 17 00:00:00 2001 From: Maxime Gasselin Date: Fri, 1 Feb 2019 10:17:25 +0100 Subject: [PATCH] [bp] Fix revolving credit navigation The main way to reach revolving credit spaces is not reachable. Nevertheless we can reach it with other navigation. --- modules/bp/browser.py | 19 ++++++++++++++----- modules/bp/pages/accountlist.py | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/modules/bp/browser.py b/modules/bp/browser.py index fdcbdda680..31d34876b0 100644 --- a/modules/bp/browser.py +++ b/modules/bp/browser.py @@ -74,7 +74,10 @@ class BPBrowser(LoginBrowser, StatesMixin): '/voscomptes/canalXHTML/pret/encours/detaillerOffrePretConsoListe-encoursPrets.ea', '/voscomptes/canalXHTML/pret/creditRenouvelable/init-consulterCreditRenouvelable.ea', '/voscomptes/canalXHTML/pret/encours/rechercherPret-encoursPrets.ea', + '/voscomptes/canalXHTML/sso/commun/init-integration.ea\?partenaire', + '/voscomptes/canalXHTML/sso/lbpf/souscriptionCristalFormAutoPost.jsp', AccountList) + par_accounts_revolving = URL('https://espaceclientcreditconso.labanquepostale.fr/sav/accueil.do', AccountList) accounts_rib = URL(r'.*voscomptes/canalXHTML/comptesCommun/imprimerRIB/init-imprimer_rib.ea.*', '/voscomptes/canalXHTML/comptesCommun/imprimerRIB/init-selection_rib.ea', AccountRIB) @@ -219,6 +222,10 @@ def do_login(self): @need_login def get_accounts_list(self): + if self.session.cookies.get('indicateur'): + # Malformed cookie to delete to reach other spaces + del self.session.cookies['indicateur'] + if self.accounts is None: accounts = [] to_check = [] @@ -238,7 +245,7 @@ def get_accounts_list(self): for account in self.page.iter_accounts(): if account.type == Account.TYPE_LOAN: self.location(account.url) - if 'CreditRenouvelable' not in account.url: + if 'initSSO' not in account.url: for loan in self.page.iter_loans(): loan.currency = account.currency accounts.append(loan) @@ -249,9 +256,11 @@ def get_accounts_list(self): student_loan.currency = account.currency accounts.append(student_loan) else: - for loan in self.page.iter_revolving_loans(): - loan.currency = account.currency - accounts.append(loan) + # The main revolving page is not accessible, we can reach it by this new way + self.location(self.absurl('/voscomptes/canalXHTML/sso/lbpf/souscriptionCristalFormAutoPost.jsp')) + self.page.go_revolving() + revolving_loan = self.page.get_revolving_attributes(account) + accounts.append(revolving_loan) page.go() elif account.type == Account.TYPE_PERP: @@ -309,7 +318,7 @@ def get_history(self, account): self.go_linebourse(account) return self.linebourse.iter_history(account.id) - if account.type == Account.TYPE_LOAN: + if account.type in (Account.TYPE_LOAN, Account.TYPE_REVOLVING_CREDIT): return [] if account.type == Account.TYPE_CARD: diff --git a/modules/bp/pages/accountlist.py b/modules/bp/pages/accountlist.py index f2874f910c..aa63d305e1 100644 --- a/modules/bp/pages/accountlist.py +++ b/modules/bp/pages/accountlist.py @@ -58,6 +58,8 @@ def condition(self): def obj_url(self): url = Link(u'./a', default=NotAvailable)(self) if url: + if 'CreditRenouvelable' in url: + url = Link(u'.//a[contains(text(), "espace de gestion crédit renouvelable")]')(self.el) return urljoin(self.page.url, url) return url @@ -138,6 +140,10 @@ def on_load(self): raise BrowserUnavailable() + def go_revolving(self): + form = self.get_form() + form.submit() + @property def no_accounts(self): return len(self.doc.xpath('//iframe[contains(@src, "/comptes_contrats/sans_")] |\ @@ -157,6 +163,22 @@ class item_account(item_account_generic): def condition(self): return item_account_generic.condition(self) + + def get_revolving_attributes(self, account): + loan = Loan() + loan.id = account.id + loan.label = '%s - %s' %(account.label, account.id) + loan.currency = account.currency + loan.url = account.url + + loan.available_amount = CleanDecimal('//tr[td[contains(text(), "Montant Maximum Autorisé") or contains(text(), "Montant autorisé")]]/td[2]')(self.doc) + loan.used_amount = loan.used_amount = CleanDecimal('//tr[td[contains(text(), "Montant Utilisé") or contains(text(), "Montant utilisé")]]/td[2]')(self.doc) + loan.available_amount = CleanDecimal(Regexp(CleanText('//tr[td[contains(text(), "Montant Disponible") or contains(text(), "Montant disponible")]]/td[2]'), r'(.*) au'))(self.doc) + loan._has_cards = False + loan.type = Account.TYPE_REVOLVING_CREDIT + return loan + + @method class iter_revolving_loans(ListElement): item_xpath = '//div[@class="bloc Tmargin"]//dl' -- GitLab