Commit 6e50faae authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Romain Bignon

[binck] Factorized get_token() method

To avoid multiple classes with th det_token() method, I created a class
(BinckPage) with this method and the three Pages requiring get_token
inherit from it.
parent 7e35b017
......@@ -47,6 +47,13 @@ class QuestionPage(HTMLPage):
form.submit()
class BinckPage(LoggedPage, HTMLPage):
# Used to factorize the get_token() method
def get_token(self):
return [{Attr('.', 'name')(input): Attr('.', 'value')(input)}
for input in self.doc.xpath('//input[contains(@name, "Token")]')][0]
class ViewPage(LoggedPage, HTMLPage):
# We automatically skip the new website tutorial
def on_load(self):
......@@ -75,16 +82,12 @@ class ChangePassPage(LoggedPage, HTMLPage):
raise BrowserPasswordExpired(message)
class HandlePasswordsPage(LoggedPage, HTMLPage):
class HandlePasswordsPage(BinckPage):
def on_load(self):
token = self.get_token()
self.browser.postpone_passwords.go(headers=token, method='POST')
self.browser.home_page.go()
def get_token(self):
return [{Attr('.', 'name')(input): Attr('.', 'value')(input)}
for input in self.doc.xpath('//input[contains(@name, "Token")]')][0]
class PostponePasswords(LoggedPage, HTMLPage):
pass
......@@ -105,7 +108,7 @@ class LoginPage(HTMLPage):
return CleanText('//div[contains(@class, "errors")]')(self.doc)
class AccountsPage(LoggedPage, HTMLPage):
class AccountsPage(BinckPage):
TYPES = {'L': Account.TYPE_SAVINGS,
'CT': Account.TYPE_MARKET,
'PEA': Account.TYPE_PEA,
......@@ -117,10 +120,6 @@ class AccountsPage(LoggedPage, HTMLPage):
def has_accounts_table(self):
return self.doc.xpath('//table[contains(@class, "accountoverview-table")]')
def get_token(self):
return [{Attr('.', 'name')(input): Attr('.', 'value')(input)}
for input in self.doc.xpath('//input[contains(@name, "Token")]')][0]
@method
class iter_accounts(ListElement):
# Tables have no headers so we must use ListElement.
......@@ -149,7 +148,7 @@ class AccountsPage(LoggedPage, HTMLPage):
return Account.get_currency(CleanText('.//div[contains(text(), "Total des avoirs")]/following::strong[1]')(self))
class OldAccountsPage(LoggedPage, HTMLPage):
class OldAccountsPage(BinckPage):
'''
Old website accounts page. We can get rid of this
class when all users have access to the new website.
......@@ -168,10 +167,6 @@ class OldAccountsPage(LoggedPage, HTMLPage):
def get_iban(self):
return CleanText('//div[@class="iban"]/text()', replace=[(' ', '')], default=NotAvailable)(self.doc)
def get_token(self):
return [{Attr('.', 'name')(input): Attr('.', 'value')(input)}
for input in self.doc.xpath('//input[contains(@name, "Token")]')][0]
def is_investment(self):
# warning: the link can be present even in case of non-investement account
return CleanText('//a[contains(@href, "Portfolio")]', default=False)(self.doc)
......
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