From 36db06689bf1307764e42b71df17ffd80dfb2b8c Mon Sep 17 00:00:00 2001 From: Sylvie Ye Date: Thu, 4 Apr 2019 15:43:18 +0200 Subject: [PATCH] [societegenerale] handle case of old history websiteunavailable page * Some life insurance don't have history, return empty list * raise BrowserUnavailable with error message --- modules/societegenerale/browser.py | 11 ++++++-- .../societegenerale/pages/accounts_list.py | 25 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/societegenerale/browser.py b/modules/societegenerale/browser.py index f856d6ce70..a906def3b8 100644 --- a/modules/societegenerale/browser.py +++ b/modules/societegenerale/browser.py @@ -240,8 +240,15 @@ def iter_history(self, account): )): self.account_details_page.go(params={'idprest': account._prestation_id}) history_url = self.page.get_history_url() - assert history_url - self.location(self.absurl(history_url)) + + # history_url return NotAvailable when history page doesn't exist + # it return None when we don't know if history page exist + if history_url is None: + error_msg = self.page.get_error_msg() + assert error_msg, 'There should have error or history url' + raise BrowserUnavailable(error_msg) + elif history_url: + self.location(self.absurl(history_url)) for tr in self.page.iter_history(): yield tr diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 5c900ef86d..207d35df8c 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -532,6 +532,11 @@ def get_history_url(self): if history_link: return history_link.group(1) + def get_error_msg(self): + # to be consistent with other iter_history from old website + # not encounter yet + pass + class CreditHistoryPage(LoggedPage, HTMLPage): def build_doc(self, content): @@ -587,6 +592,10 @@ class item(ItemElement): obj_amount = CleanDecimal(TableCell('amount')) obj_date = Date(CleanText(TableCell('date')), dayfirst=True) + def get_error_msg(self): + assert self.doc.xpath('//div[@class="error_content"]'), 'There should have link to history page.' + return CleanText('//div[@class="error_content"]//span[@class="error_msg"]')(self.doc) + class LifeInsurance(LoggedPage, HTMLPage): def on_load(self): @@ -606,8 +615,12 @@ def has_link(self): return Link('//a[@href="asvcns20a.html"]', default=NotAvailable)(self.doc) def get_history_url(self): - history_url = Link('//a[img[@alt="Suivi des opérations"]]', default=NotAvailable)(self.doc) - return history_url + return Link('//a[img[@alt="Suivi des opérations"]]', default=None)(self.doc) + + def get_error_msg(self): + # to be consistent with other iter_history from old website + # not encounter yet + pass def get_pages(self): pages = CleanText('//div[@class="net2g_asv_tableau_pager"]')(self.doc) @@ -665,6 +678,14 @@ def obj_code_type(self): class LifeInsuranceInvest2(LifeInsuranceInvest): + def get_history_url(self): + return NotAvailable + + def iter_history(self): + # on SG website, there are no transactions for this type of account + # there no trace on any space for the history on this page + return [] + @method class iter_investment(TableElement): item_xpath = '//table/tbody/tr[starts-with(@class, "net2g_asv_tableau_ligne_")]' -- GitLab