Commit e722331d authored by Damien Mat's avatar Damien Mat Committed by Vincent A

[societegenerale] Better detect logged out state

When reloading state and requesting the last page visited,
when that page is one of the one in,
we are usally logged out.
This is handled in AccountJsonPage with a special Logged property.
But it needs to be as well in the other pages.
We do that by introducing a LoggedDetectionMixin,
inherited by a SGPEJsonPage, common to all subsequent pages.
parent ebc13925
......@@ -26,7 +26,7 @@
import requests
from weboob.browser.pages import LoggedPage, JsonPage, pagination
from weboob.browser.pages import JsonPage, pagination
from weboob.browser.elements import ItemElement, method, DictElement
from weboob.browser.filters.standard import (
CleanDecimal, CleanText, Coalesce, Date, Format, BrowserURL, Env,
......@@ -51,7 +51,17 @@
from .pages import Transaction
class AccountsJsonPage(LoggedPage, JsonPage):
class LoggedDetectionMixin(object):
def logged(self):
return Dict('commun/raison', default=None)(self.doc) != "niv_auth_insuff"
class SGPEJsonPage(LoggedDetectionMixin, JsonPage):
class AccountsJsonPage(SGPEJsonPage):
ENCODING = 'utf-8'
......@@ -71,10 +81,6 @@ class AccountsJsonPage(LoggedPage, JsonPage):
'Prêt': Account.TYPE_LOAN,
def logged(self):
return Dict('commun/raison', default=None)(self.doc) != "niv_auth_insuff"
def on_load(self):
if self.doc['commun']['statut'].lower() == 'nok':
reason = self.doc['commun']['raison']
......@@ -142,12 +148,12 @@ def get_error(self):
return None
class CardsInformationPage(LoggedPage, JsonPage):
class CardsInformationPage(SGPEJsonPage):
def get_card_id(self):
return self.response.json()['donnees'][0].get('idPPouPM')
class CardsInformation2Page(LoggedPage, JsonPage):
class CardsInformation2Page(SGPEJsonPage):
def get_number(self):
return self.response.json().get('donnees')[0].get('numero')
......@@ -155,7 +161,7 @@ def get_due_date(self):
return self.response.json().get('donnees')[0].get('dateRegelement')
class DeferredCardJsonPage(LoggedPage, JsonPage):
class DeferredCardJsonPage(SGPEJsonPage):
def get_account_id(self):
return self.response.json().get('donnees')[0].get('idPrestationCompte')
......@@ -183,7 +189,7 @@ def condition(self):
obj_currency = CleanText(Dict('currentOutstandingAmount/currencyCode'))
class DeferredCardHistoryJsonPage(LoggedPage, JsonPage):
class DeferredCardHistoryJsonPage(SGPEJsonPage):
class iter_comings(DictElement):
item_xpath = 'donnees'
......@@ -200,7 +206,7 @@ def obj_amount(self):
return Decimal(Dict('montant/montant')(self)) / (10 ** Decimal(Dict('montant/nbrDecimales')(self)))
class BalancesJsonPage(LoggedPage, JsonPage):
class BalancesJsonPage(SGPEJsonPage):
def on_load(self):
if self.doc['commun']['statut'] == 'NOK':
reason = self.doc['commun']['raison']
......@@ -217,7 +223,7 @@ def populate_balances(self, accounts):
yield account
class HistoryJsonPage(LoggedPage, JsonPage):
class HistoryJsonPage(SGPEJsonPage):
def get_value(self):
if 'NOK' in self.doc['commun']['statut']:
......@@ -337,7 +343,7 @@ def parse(self, el):
self.env['rdate'], self.env['date'] = self.env['date'], self.env['rdate']
class ProfilePEPage(LoggedPage, JsonPage):
class ProfilePEPage(SGPEJsonPage):
class get_profile(ItemElement):
klass = Person
......@@ -365,7 +371,7 @@ class get_profile(ItemElement):
obj_company_name = Dict('donnees/raisonSocialeEntreprise', default=NotAvailable)
class BankStatementPage(LoggedPage, JsonPage):
class BankStatementPage(SGPEJsonPage):
def get_min_max_date(self):
min_date = Date(Dict('donnees/criteres/dateMin'), dayfirst=True, default=None)(self.doc)
max_date = Date(Dict('donnees/criteres/dateMax'), dayfirst=True, default=None)(self.doc)
......@@ -399,7 +405,7 @@ def iter_documents(self):
yield d
class MarketAccountPage(LoggedPage, JsonPage):
class MarketAccountPage(SGPEJsonPage):
class iter_market_accounts(DictElement):
item_xpath = 'donnees/comptesTitresByClasseur'
......@@ -425,7 +431,7 @@ class item(ItemElement):
obj_type = Account.TYPE_MARKET
class MarketInvestmentPage(LoggedPage, JsonPage):
class MarketInvestmentPage(SGPEJsonPage):
class iter_investment(DictElement):
item_xpath = 'donnees'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment