fixes on fortuneo module

browser.py:
        added condition on login page
        test in home removed
    pages/accounts_list.py
        code  refactor
        BrokenPageError is thrown if the <tr> table is void
        cosmetic changes
        added a TODO for FrenchTransaction implementation
        not needed code lines deleted
        list concatenation in a smarter way
    pages/login.py
        BrowserUnavailable() implemented to throw an exception when the site is in maintenance
        smarter list concatenation
    test.py
        working test (was not really implemented)
This commit is contained in:
sputnick 2012-04-21 19:01:42 +02:00 committed by Romain Bignon
commit cd5f29a0f9
4 changed files with 27 additions and 24 deletions

View file

@ -45,8 +45,7 @@ class Fortuneo(BaseBrowser):
def home(self):
"""main page (login)"""
if not self.is_on_page(AccountHistoryPage):
self.location('/fr/prive/identification.jsp')
self.location('/fr/prive/identification.jsp')
def is_logged(self):
"""Return True if we are logged on website"""

View file

@ -23,7 +23,8 @@ import datetime
from weboob.capabilities.bank import Account
from weboob.tools.capabilities.bank.transactions import Transaction
from weboob.tools.browser import BasePage #, BrokenPageError
from weboob.tools.browser import BasePage, BrokenPageError
from weboob.capabilities import NotAvailable
__all__ = ['AccountsList', 'AccountHistoryPage']
@ -31,22 +32,24 @@ class AccountHistoryPage(BasePage):
def get_operations(self, _id):
"""history, see http://docs.weboob.org/api/capabilities/bank.html?highlight=transaction#weboob.capabilities.bank.Transaction"""
# TODO need to rewrite that with FrenchTransaction class http://tinyurl.com/6lq4r9t
operations = []
tables = self.document.findall(".//*[@id='tabHistoriqueOperations']/tbody/tr")
if len(tables) == 0:
raise BrokenPageError
for i in range(len(tables)):
operation = Transaction(len(operations))
date_oper = tables[i].xpath("./td[2]/text()")[0]
date_val = tables[i].xpath("./td[3]/text()")[0]
label = tables[i].xpath("./td[4]/text()")[0]
label = label.strip()
operation.label = label.strip()
amount = tables[i].xpath("./td[5]/text() | ./td[6]/text()")
operation.date = datetime.datetime.strptime(date_val, "%d/%m/%Y")
operation.rdate = datetime.datetime.strptime(date_oper,"%d/%m/%Y")
operation.type = 0
operation.raw = label
operation.label = u""+label
if amount[1] == u'\xa0':
amount = amount[0].replace(u"\xa0", "").replace(",", ".").strip()
@ -54,9 +57,7 @@ class AccountHistoryPage(BasePage):
amount = amount[1].replace(u"\xa0", "").replace(",", ".").strip()
operation.amount = Decimal(amount)
operation.category = u" " # blank category
operation.origin = u" " # blank origin
operation.recipient = u" " # blank rcpt
operation.category = NotAvailable
operations.append(operation)
@ -71,14 +72,13 @@ class AccountsList(BasePage):
# account.id
account.id = cpt.xpath("./td[1]/a/text()")[0]
account.id = str(account.id)
# account balance
account.balance = Decimal(cpt.xpath("./td[3]/text()")[0].replace("EUR", "").replace("\n", "").replace("\t", "").replace(u"\xa0", ""))
# account coming
mycomingval = cpt.xpath("./td[4]/text()")[0].replace("EUR", "").replace("\n", "").replace("\t", "")
if mycomingval == '-':
account.coming = float(0)
else:
@ -87,15 +87,13 @@ class AccountsList(BasePage):
# account._link_id
url_to_parse = cpt.xpath('./td[1]/a/@href')[0] # link
compte_id_re = re.compile(r'.*COMPTE_ACTIF=([^\&]+)\&.*')
account._link_id = '/fr/prive/mes-comptes/livret/consulter-situation/consulter-solde.jsp?COMPTE_ACTIF='+compte_id_re.search(str(url_to_parse)).groups()[0]
account._link_id = str(account._link_id)
account._link_id = '/fr/prive/mes-comptes/livret/consulter-situation/consulter-solde.jsp?COMPTE_ACTIF='+ \
compte_id_re.search(url_to_parse).groups()[0]
account._link_id = account._link_id
# account.label
tpl = cpt.xpath("./td[2]/a/text()")[0].split(' ')
account.label = tpl[0] + u" " + tpl[1]
account.label = str(u""+account.label)
account.raw = str(u""+account.label)
account.label = ' '.join(tpl[:2])
l.append(account)

View file

@ -20,16 +20,25 @@
#from logging import error
from weboob.tools.browser import BasePage #, BrowserUnavailable
from weboob.tools.browser import BasePage, BrowserUnavailable
__all__ = ['LoginPage']
class LoginPage(BasePage):
def login(self, login, passwd):
def login(self, login, passwd):
msgb = self.document.xpath(".//*[@id='message_client']/text()")
msga = ''.join(msgb)
msg = msga.strip("\n")
if "maintenance" in msg:
print "Fortuneo: "+msg
raise BrowserUnavailable(msg)
self.browser.select_form(nr=3)
self.browser['login'] = login
self.browser['passwd'] = passwd
self.browser.submit()
# vim:ts=4:sw=4

View file

@ -29,6 +29,3 @@ class FortuneoTest(BackendTest):
a = l[0]
list(self.backend.iter_coming(a))
list(self.backend.iter_history(a))
# vim:ts=4:sw=4