From 3ee11a8fe48605ed9ad6b379e11f37154440e694 Mon Sep 17 00:00:00 2001 From: Christophe Francois Date: Wed, 20 May 2020 11:26:11 +0200 Subject: [PATCH] [cmso] Handle new page in login There is a call at login to choose which space to consult (particulier, pro, association). If we don't do it, there is a redirection during the fetching of investments that fails. --- modules/cmso/par/browser.py | 16 +++++++++++++++- modules/cmso/par/pages.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/cmso/par/browser.py b/modules/cmso/par/browser.py index bf0ea2f461..9e6eba230f 100644 --- a/modules/cmso/par/browser.py +++ b/modules/cmso/par/browser.py @@ -37,7 +37,8 @@ from .pages import ( LogoutPage, AccountsPage, HistoryPage, LifeinsurancePage, MarketPage, - AdvisorPage, LoginPage, ProfilePage, RedirectInsurancePage, + AdvisorPage, LoginPage, ProfilePage, RedirectInsurancePage, SpacesPage, + ChangeSpacePage, ) from .transfer_pages import TransferInfoPage, RecipientsListPage, TransferPage, AllowedRecipientsPage @@ -96,6 +97,10 @@ class CmsoParBrowser(TwoFactorBrowser): r'https://.*/auth/errorauthn', LogoutPage ) + + spaces = URL(r'/domiapi/oauth/json/accesAbonnement', SpacesPage) + change_space = URL(r'/securityapi/changeSpace', ChangeSpacePage) + accounts = URL(r'/domiapi/oauth/json/accounts/synthese(?P.*)', AccountsPage) history = URL(r'/domiapi/oauth/json/accounts/(?P.*)', HistoryPage) loans = URL(r'/creditapi/rest/oauth/v1/synthese', AccountsPage) @@ -249,6 +254,15 @@ def iter_accounts(self): # to know if account can do transfer accounts_eligibilite_debit = self.page.get_eligibilite_debit() + self.spaces.go(json={'includePart': True}) + self.change_space.go(json={ + 'clientIdSource': self.arkea_client_id, + 'espaceDestination': 'PART', + 'fromMobile': False, + 'numContractDestination': self.page.get_part_space(), + }) + self.session.headers['Authorization'] = 'Bearer %s' % self.page.get_access_token() + # First get all checking accounts... self.accounts.go(json={'typeListeCompte': 'COMPTE_SOLDE_COMPTES_CHEQUES'}, type='comptes') self.page.check_response() diff --git a/modules/cmso/par/pages.py b/modules/cmso/par/pages.py index e15084b1a8..33048638ff 100644 --- a/modules/cmso/par/pages.py +++ b/modules/cmso/par/pages.py @@ -58,6 +58,18 @@ class LogoutPage(RawPage): pass +class SpacesPage(LoggedPage, JsonPage): + def get_part_space(self): + for abo in Dict('listAbonnement')(self.doc): + if Dict('espaceProxy')(abo) == 'PART': + return Dict('numContratBAD')(abo) + + +class ChangeSpacePage(LoggedPage, JsonPage): + def get_access_token(self): + return Dict('accessToken')(self.doc) + + class AccountsPage(LoggedPage, JsonPage): TYPES = OrderedDict([ ('courant', Account.TYPE_CHECKING), -- GitLab