several fixes to run successfully tests

This commit is contained in:
Romain Bignon 2012-01-17 17:46:13 +01:00
commit abb24b9954
9 changed files with 80 additions and 76 deletions

View file

@ -23,7 +23,10 @@ from logging import warning
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from weboob.capabilities.bank import TransferError, Transfer from weboob.capabilities.bank import TransferError, Transfer
from bnporc import pages from .pages import AccountsList, AccountHistory, ChangePasswordPage, \
AccountComing, AccountPrelevement, TransferPage, \
TransferConfirmPage, TransferCompletePage, \
LoginPage, ConfirmPage
from .errors import PasswordExpired from .errors import PasswordExpired
@ -34,18 +37,18 @@ class BNPorc(BaseBrowser):
DOMAIN = 'www.secure.bnpparibas.net' DOMAIN = 'www.secure.bnpparibas.net'
PROTOCOL = 'https' PROTOCOL = 'https'
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = {'.*identifiant=DOSSIER_Releves_D_Operation.*': pages.AccountsList, PAGES = {'.*identifiant=DOSSIER_Releves_D_Operation.*': AccountsList,
'.*SAF_ROP.*': pages.AccountHistory, '.*SAF_ROP.*': AccountHistory,
'.*Action=SAF_CHM.*': pages.ChangePasswordPage, '.*Action=SAF_CHM.*': ChangePasswordPage,
'.*NS_AVEDT.*': pages.AccountComing, '.*NS_AVEDT.*': AccountComing,
'.*NS_AVEDP.*': pages.AccountPrelevement, '.*NS_AVEDP.*': AccountPrelevement,
'.*NS_VIRDF.*': pages.TransferPage, '.*NS_VIRDF.*': TransferPage,
'.*NS_VIRDC.*': pages.TransferConfirmPage, '.*NS_VIRDC.*': TransferConfirmPage,
'.*/NS_VIRDA\?stp=(?P<id>\d+).*': pages.TransferCompletePage, '.*/NS_VIRDA\?stp=(?P<id>\d+).*': TransferCompletePage,
'.*Action=DSP_VGLOBALE.*': pages.LoginPage, '.*Action=DSP_VGLOBALE.*': LoginPage,
'.*type=homeconnex.*': pages.LoginPage, '.*type=homeconnex.*': LoginPage,
'.*layout=HomeConnexion.*': pages.ConfirmPage, '.*layout=HomeConnexion.*': ConfirmPage,
'.*SAF_CHM_VALID.*': pages.ConfirmPage, '.*SAF_CHM_VALID.*': ConfirmPage,
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -57,31 +60,31 @@ class BNPorc(BaseBrowser):
self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex') self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex')
def is_logged(self): def is_logged(self):
return not self.is_on_page(pages.LoginPage) return not self.is_on_page(LoginPage)
def login(self): def login(self):
assert isinstance(self.username, basestring) assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring) assert isinstance(self.password, basestring)
assert self.password.isdigit() assert self.password.isdigit()
if not self.is_on_page(pages.LoginPage): if not self.is_on_page(LoginPage):
self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex') self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex')
self.page.login(self.username, self.password) self.page.login(self.username, self.password)
self.location('/NSFR?Action=DSP_VGLOBALE', no_login=True) self.location('/NSFR?Action=DSP_VGLOBALE', no_login=True)
if self.is_on_page(pages.LoginPage): if self.is_on_page(LoginPage):
raise BrowserIncorrectPassword() raise BrowserIncorrectPassword()
def change_password(self, new_password): def change_password(self, new_password):
assert new_password.isdigit() and len(new_password) == 6 assert new_password.isdigit() and len(new_password) == 6
self.location('https://www.secure.bnpparibas.net/SAF_CHM?Action=SAF_CHM') self.location('https://www.secure.bnpparibas.net/SAF_CHM?Action=SAF_CHM')
assert self.is_on_page(pages.ChangePasswordPage) assert self.is_on_page(ChangePasswordPage)
self.page.change_password(self.password, new_password) self.page.change_password(self.password, new_password)
if not self.is_on_page(pages.ConfirmPage): if not self.is_on_page(ConfirmPage):
self.logger.error('Oops, unable to change password') self.logger.error('Oops, unable to change password')
return return
@ -105,7 +108,7 @@ class BNPorc(BaseBrowser):
@check_expired_password @check_expired_password
def get_accounts_list(self): def get_accounts_list(self):
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/NSFR?Action=DSP_VGLOBALE') self.location('/NSFR?Action=DSP_VGLOBALE')
return self.page.get_list() return self.page.get_list()
@ -113,7 +116,7 @@ class BNPorc(BaseBrowser):
def get_account(self, id): def get_account(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/NSFR?Action=DSP_VGLOBALE') self.location('/NSFR?Action=DSP_VGLOBALE')
l = self.page.get_list() l = self.page.get_list()
@ -124,30 +127,30 @@ class BNPorc(BaseBrowser):
return None return None
def get_history(self, account): def get_history(self, account):
if not self.is_on_page(pages.AccountHistory) or self.page.account.id != account.id: if not self.is_on_page(AccountHistory) or self.page.account.id != account.id:
self.location('/SAF_ROP?ch4=%s' % account.link_id) self.location('/SAF_ROP?ch4=%s' % account.link_id)
return self.page.get_operations() return self.page.get_operations()
def get_coming_operations(self, account): def get_coming_operations(self, account):
if not self.is_on_page(pages.AccountComing) or self.page.account.id != account.id: if not self.is_on_page(AccountComing) or self.page.account.id != account.id:
self.location('/NS_AVEDT?ch4=%s' % account.link_id) self.location('/NS_AVEDT?ch4=%s' % account.link_id)
return self.page.get_operations() return self.page.get_operations()
def get_transfer_accounts(self): def get_transfer_accounts(self):
if not self.is_on_page(pages.TransferPage): if not self.is_on_page(TransferPage):
self.location('/NS_VIRDF') self.location('/NS_VIRDF')
assert self.is_on_page(pages.TransferPage) assert self.is_on_page(TransferPage)
return self.page.get_accounts() return self.page.get_accounts()
def transfer(self, from_id, to_id, amount, reason=None): def transfer(self, from_id, to_id, amount, reason=None):
if not self.is_on_page(pages.TransferPage): if not self.is_on_page(TransferPage):
self.location('/NS_VIRDF') self.location('/NS_VIRDF')
accounts = self.page.get_accounts() accounts = self.page.get_accounts()
self.page.transfer(from_id, to_id, amount, reason) self.page.transfer(from_id, to_id, amount, reason)
if not self.is_on_page(pages.TransferCompletePage): if not self.is_on_page(TransferCompletePage):
raise TransferError('An error occured during transfer') raise TransferError('An error occured during transfer')
transfer = Transfer(self.page.get_id()) transfer = Transfer(self.page.get_id())

View file

@ -20,7 +20,7 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from boursorama import pages from .pages import LoginPage, AccountsList, AccountHistory
from datetime import date from datetime import date
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
@ -34,9 +34,9 @@ class Boursorama(BaseBrowser):
PROTOCOL = 'https' PROTOCOL = 'https'
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = { PAGES = {
'.*connexion.phtml.*': pages.LoginPage, '.*connexion.phtml.*': LoginPage,
'.*/comptes/synthese.phtml': pages.AccountsList, '.*/comptes/synthese.phtml': AccountsList,
'.*/comptes/banque/detail/mouvements.phtml.*': pages.AccountHistory, '.*/comptes/banque/detail/mouvements.phtml.*': AccountHistory,
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -46,23 +46,23 @@ class Boursorama(BaseBrowser):
self.location('https://' + self.DOMAIN + '/connexion.phtml') self.location('https://' + self.DOMAIN + '/connexion.phtml')
def is_logged(self): def is_logged(self):
return not self.is_on_page(pages.LoginPage) return not self.is_on_page(LoginPage)
def login(self): def login(self):
assert isinstance(self.username, basestring) assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring) assert isinstance(self.password, basestring)
assert self.password.isdigit() assert self.password.isdigit()
if not self.is_on_page(pages.LoginPage): if not self.is_on_page(LoginPage):
self.location('https://' + self.DOMAIN + '/connexion.phtml') self.location('https://' + self.DOMAIN + '/connexion.phtml')
self.page.login(self.username, self.password) self.page.login(self.username, self.password)
if self.is_on_page(pages.LoginPage): if self.is_on_page(LoginPage):
raise BrowserIncorrectPassword() raise BrowserIncorrectPassword()
def get_accounts_list(self): def get_accounts_list(self):
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/comptes/synthese.phtml') self.location('/comptes/synthese.phtml')
return self.page.get_list() return self.page.get_list()
@ -70,7 +70,7 @@ class Boursorama(BaseBrowser):
def get_account(self, id): def get_account(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/comptes/synthese.phtml') self.location('/comptes/synthese.phtml')
l = self.page.get_list() l = self.page.get_list()

View file

@ -20,7 +20,7 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from weboob.capabilities.bank import Transfer, TransferError from weboob.capabilities.bank import Transfer, TransferError
from cragr import pages from .pages import LoginPage, AccountsList
import mechanize import mechanize
from datetime import datetime from datetime import datetime
import re import re
@ -36,13 +36,13 @@ class Cragr(BaseBrowser):
def __init__(self, website, *args, **kwargs): def __init__(self, website, *args, **kwargs):
self.DOMAIN = website self.DOMAIN = website
self.PAGES = {'https://[^/]+/': pages.LoginPage, self.PAGES = {'https://[^/]+/': LoginPage,
'https://[^/]+/.*\.c.*': pages.AccountsList, 'https://[^/]+/.*\.c.*': AccountsList,
'https://[^/]+/login/process%s' % self.SESSION_REGEXP: pages.AccountsList, 'https://[^/]+/login/process%s' % self.SESSION_REGEXP: AccountsList,
'https://[^/]+/accounting/listAccounts': pages.AccountsList, 'https://[^/]+/accounting/listAccounts': AccountsList,
'https://[^/]+/accounting/listOperations': pages.AccountsList, 'https://[^/]+/accounting/listOperations': AccountsList,
'https://[^/]+/accounting/showAccountDetail.+': pages.AccountsList, 'https://[^/]+/accounting/showAccountDetail.+': AccountsList,
'https://[^/]+/accounting/showMoreAccountOperations.*': pages.AccountsList, 'https://[^/]+/accounting/showMoreAccountOperations.*': AccountsList,
} }
BaseBrowser.__init__(self, *args, **kwargs) BaseBrowser.__init__(self, *args, **kwargs)
@ -75,7 +75,7 @@ class Cragr(BaseBrowser):
self.is_logging = True self.is_logging = True
# Are we on the good page? # Are we on the good page?
if not self.is_on_page(pages.LoginPage): if not self.is_on_page(LoginPage):
self.logger.debug('going to login page') self.logger.debug('going to login page')
BaseBrowser.home(self) BaseBrowser.home(self)
self.logger.debug('attempting to log in') self.logger.debug('attempting to log in')
@ -95,21 +95,21 @@ class Cragr(BaseBrowser):
Ensure we are both logged and on the accounts list. Ensure we are both logged and on the accounts list.
""" """
self.logger.debug('accounts list page required') self.logger.debug('accounts list page required')
if self.is_on_page(pages.AccountsList) and self.page.is_accounts_list(): if self.is_on_page(AccountsList) and self.page.is_accounts_list():
self.logger.debug('already on accounts list') self.logger.debug('already on accounts list')
return return
# simply go to http(s)://the.doma.in/ # simply go to http(s)://the.doma.in/
BaseBrowser.home(self) BaseBrowser.home(self)
if self.is_on_page(pages.LoginPage): if self.is_on_page(LoginPage):
if not self.is_logged(): if not self.is_logged():
# So, we are not logged on the login page -- what about logging ourselves? # So, we are not logged on the login page -- what about logging ourselves?
self.login() self.login()
# we assume we are logged in # we assume we are logged in
# for some regions, we may stay on the login page once we're # for some regions, we may stay on the login page once we're
# logged in, without being redirected... # logged in, without being redirected...
if self.is_on_page(pages.LoginPage): if self.is_on_page(LoginPage):
# ... so we have to move by ourselves # ... so we have to move by ourselves
self.move_to_accounts_list() self.move_to_accounts_list()
@ -254,6 +254,6 @@ class Cragr(BaseBrowser):
return transfer return transfer
#def get_coming_operations(self, account): #def get_coming_operations(self, account):
# if not self.is_on_page(pages.AccountComing) or self.page.account.id != account.id: # if not self.is_on_page(AccountComing) or self.page.account.id != account.id:
# self.location('/NS_AVEEC?ch4=%s' % account.link_id) # self.location('/NS_AVEEC?ch4=%s' % account.link_id)
# return self.page.get_operations() # return self.page.get_operations()

View file

@ -22,7 +22,7 @@ from datetime import datetime
from weboob.tools.browser import BrokenPageError from weboob.tools.browser import BrokenPageError
from weboob.tools.misc import local2utc from weboob.tools.misc import local2utc
from dlfp.tools import url2id from ..tools import url2id
from .index import DLFPPage from .index import DLFPPage

View file

@ -21,7 +21,7 @@
from datetime import datetime from datetime import datetime
from weboob.tools.test import BackendTest from weboob.tools.test import BackendTest
from dlfp.browser import DLFP from .browser import DLFP
__all__ = ['DLFPTest'] __all__ = ['DLFPTest']

View file

@ -19,7 +19,8 @@
from weboob.tools.browser import BaseBrowser from weboob.tools.browser import BaseBrowser
from ing import pages from .pages import AccountsList, LoginPage, LoginPage2, \
AccountHistoryCC, AccountHistoryLA
__all__ = ['Ing'] __all__ = ['Ing']
@ -29,11 +30,11 @@ class Ing(BaseBrowser):
DOMAIN = 'secure.ingdirect.fr' DOMAIN = 'secure.ingdirect.fr'
PROTOCOL = 'https' PROTOCOL = 'https'
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = {'.*displayTRAccountSummary.*': pages.AccountsList, PAGES = {'.*displayTRAccountSummary.*': AccountsList,
'.*displayLogin.jsf': pages.LoginPage, '.*displayLogin.jsf': LoginPage,
'.*displayLogin.jsf.*': pages.LoginPage2, '.*displayLogin.jsf.*': LoginPage2,
'.*accountDetail.jsf.*': pages.AccountHistoryCC, '.*accountDetail.jsf.*': AccountHistoryCC,
'.*displayTRHistoriqueLA.*': pages.AccountHistoryLA '.*displayTRHistoriqueLA.*': AccountHistoryLA
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -44,7 +45,7 @@ class Ing(BaseBrowser):
self.location('https://secure.ingdirect.fr/public/displayLogin.jsf') self.location('https://secure.ingdirect.fr/public/displayLogin.jsf')
def is_logged(self): def is_logged(self):
return not self.is_on_page(pages.LoginPage) return not self.is_on_page(LoginPage)
def login(self): def login(self):
assert isinstance(self.username, basestring) assert isinstance(self.username, basestring)
@ -53,14 +54,14 @@ class Ing(BaseBrowser):
assert self.password.isdigit() assert self.password.isdigit()
assert self.birthday.isdigit() assert self.birthday.isdigit()
if not self.is_on_page(pages.LoginPage): if not self.is_on_page(LoginPage):
self.location('https://secure.ingdirect.fr/public/displayLogin.jsf') self.location('https://secure.ingdirect.fr/public/displayLogin.jsf')
self.page.prelogin(self.username, self.birthday) self.page.prelogin(self.username, self.birthday)
self.page.login(self.password) self.page.login(self.password)
def get_accounts_list(self): def get_accounts_list(self):
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/general?command=displayTRAccountSummary') self.location('/general?command=displayTRAccountSummary')
return self.page.get_list() return self.page.get_list()
@ -68,7 +69,7 @@ class Ing(BaseBrowser):
def get_account(self, id): def get_account(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/general?command=displayTRAccountSummary') self.location('/general?command=displayTRAccountSummary')
l = self.page.get_list() l = self.page.get_list()

View file

@ -19,7 +19,7 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from societegenerale import pages from .pages import LoginPage, AccountsList
__all__ = ['SocieteGenerale'] __all__ = ['SocieteGenerale']
@ -31,9 +31,9 @@ class SocieteGenerale(BaseBrowser):
PROTOCOL = 'https' PROTOCOL = 'https'
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = { PAGES = {
'https://particuliers.societegenerale.fr/.*': pages.LoginPage, 'https://particuliers.societegenerale.fr/.*': LoginPage,
'.*restitution/cns_listeprestation.html': pages.AccountsList, '.*restitution/cns_listeprestation.html': AccountsList,
# '.*restitution/cns_detailCav.html.*': pages.AccountHistory, # '.*restitution/cns_detailCav.html.*': AccountHistory,
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -43,23 +43,23 @@ class SocieteGenerale(BaseBrowser):
self.location('https://' + self.DOMAIN_LOGIN + '/index.html') self.location('https://' + self.DOMAIN_LOGIN + '/index.html')
def is_logged(self): def is_logged(self):
return not self.is_on_page(pages.LoginPage) return not self.is_on_page(LoginPage)
def login(self): def login(self):
assert isinstance(self.username, basestring) assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring) assert isinstance(self.password, basestring)
assert self.password.isdigit() assert self.password.isdigit()
if not self.is_on_page(pages.LoginPage): if not self.is_on_page(LoginPage):
self.location('https://' + self.DOMAIN_LOGIN + '/index.html') self.location('https://' + self.DOMAIN_LOGIN + '/index.html')
self.page.login(self.username, self.password) self.page.login(self.username, self.password)
if self.is_on_page(pages.LoginPage): if self.is_on_page(LoginPage):
raise BrowserIncorrectPassword() raise BrowserIncorrectPassword()
def get_accounts_list(self): def get_accounts_list(self):
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/restitution/cns_listeprestation.html') self.location('/restitution/cns_listeprestation.html')
return self.page.get_list() return self.page.get_list()
@ -67,7 +67,7 @@ class SocieteGenerale(BaseBrowser):
def get_account(self, id): def get_account(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)
if not self.is_on_page(pages.AccountsList): if not self.is_on_page(AccountsList):
self.location('/restitution/cns_listeprestation.html') self.location('/restitution/cns_listeprestation.html')
l = self.page.get_list() l = self.page.get_list()
@ -80,7 +80,7 @@ class SocieteGenerale(BaseBrowser):
def get_history(self, account): def get_history(self, account):
raise NotImplementedError() raise NotImplementedError()
if not self.is_on_page(pages.AccountHistory) or self.page.account.id != account.id: if not self.is_on_page(AccountHistory) or self.page.account.id != account.id:
self.location(account.link_id) self.location(account.link_id)
return self.page.get_operations() return self.page.get_operations()

View file

@ -21,7 +21,7 @@
from logging import error from logging import error
from weboob.tools.browser import BasePage, BrowserUnavailable from weboob.tools.browser import BasePage, BrowserUnavailable
from societegenerale.captcha import Captcha, TileError from ..captcha import Captcha, TileError
from lxml import etree from lxml import etree

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
nosetests -sv $(dirname $0)/../weboob/backends/$1 nosetests -sv $(dirname $0)/../modules/$1
else else
find $(dirname $0)/../weboob -name test.py | xargs nosetests -sv find $(dirname $0)/../weboob $(dirname $0)/../modules -name test.py | xargs nosetests -sv
fi fi