Commit a7b5177e authored by Jerome Berthier's avatar Jerome Berthier Committed by ntome

[banquepopulaire] factorize the back action

parent 1c7e9b0b
......@@ -193,6 +193,20 @@ class BanquePopulaire(LoginBrowser):
no_login = 0
def follow_back_button_if_any(self, params=None, actions=None):
"""
Look for a Retour button and follow it using a POST
:param params: Optional form params to use (default: call self.page.get_params())
:param actions: Optional actions to use (default: call self.page.get_button_actions())
:return: None
"""
if not self.page:
return
data = self.page.get_back_button_params(params=params, actions=actions)
if data:
self.location('/cyber/internet/ContinueTask.do', data=data)
@no_need_login
def do_login(self):
self.location(self.BASEURL)
......@@ -232,13 +246,7 @@ class BanquePopulaire(LoginBrowser):
form.submit()
# In case of prevAction maybe we have reached an expanded accounts list page, need to go back
btn = self.page.doc.xpath('.//button[span[text()="Retour"]]')
if len(btn):
_data = self.page.get_params()
actions = self.page.get_button_actions()
_data.update(actions[btn[0].attrib['id']])
_data['token'] = self.page.build_token(_data['token'])
self.location('/cyber/internet/ContinueTask.do', data=_data)
self.follow_back_button_if_any()
@retry(LoggedOut)
@need_login
......@@ -310,13 +318,7 @@ class BanquePopulaire(LoginBrowser):
transaction.raw = '%s %s' % (transaction.raw, ref)
# Needed to preserve navigation.
btn = self.page.doc.xpath('.//button[span[text()="Retour"]]')
if len(btn):
_data = self.page.get_params()
actions = self.page.get_button_actions()
_data.update(actions[btn[0].attrib['id']])
_data['token'] = self.page.build_token(_data['token'])
self.location('/cyber/internet/ContinueTask.do', data=_data)
self.follow_back_button_if_any()
@retry(LoggedOut)
@need_login
......
......@@ -164,6 +164,19 @@ class BasePage(object):
}
return actions
def get_back_button_params(self, params=None, actions=None):
btn = self.doc.xpath('.//button[span[text()="Retour"]]')
if not btn:
return
params = params or self.get_params()
actions = actions or self.get_button_actions()
key = btn[0].attrib['id']
assert actions.get(key), "Key %s not found in actions %s" % (key, actions) # Currently it never happens
params.update(actions[key])
params['token'] = self.build_token(params['token'])
return params
class MyHTMLPage(BasePage, HTMLPage):
def build_doc(self, data, *args, **kwargs):
......@@ -649,11 +662,7 @@ class AccountsPage(LoggedPage, MyHTMLPage):
yield account
# Needed to preserve navigation.
btn = self.doc.xpath('.//button[span[text()="Retour"]]')
if len(btn) > 0:
_params = params.copy()
_params.update(actions[btn[0].attrib['id']])
self.browser.open('/cyber/internet/ContinueTask.do', data=_params)
self.browser.follow_back_button_if_any(params=params.copy(), actions=actions)
class AccountsFullPage(AccountsPage):
......@@ -750,12 +759,7 @@ class CardsPage(LoggedPage, MyHTMLPage):
yield account
# Needed to preserve navigation.
btn = self.doc.xpath('.//button[span[text()="Retour"]]')
if len(btn) > 0:
actions = self.get_button_actions()
_params = params.copy()
_params.update(actions[btn[0].attrib['id']])
self.browser.open('/cyber/internet/ContinueTask.do', data=_params)
self.browser.follow_back_button_if_any(params=params.copy())
class Transaction(FrenchTransaction):
......
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