CrAgr: revisited the way login() and home() methods work. Also added extra debug statements. Fixes #697.
This commit is contained in:
parent
fc70069943
commit
67aac80c00
1 changed files with 47 additions and 11 deletions
|
|
@ -56,16 +56,29 @@ class Cragr(BaseBrowser):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
return self.page and self.page.is_logged() or self.is_logging
|
logged = self.page and self.page.is_logged() or self.is_logging
|
||||||
|
self.logger.debug('logged: %s' % (logged and 'yes' or 'no'))
|
||||||
|
return logged
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
|
"""
|
||||||
|
Attempt to log in.
|
||||||
|
Note: this method does nothing if we are already logged in.
|
||||||
|
"""
|
||||||
assert isinstance(self.username, basestring)
|
assert isinstance(self.username, basestring)
|
||||||
assert isinstance(self.password, basestring)
|
assert isinstance(self.password, basestring)
|
||||||
|
|
||||||
self.is_logging = True
|
# Do we really need to login?
|
||||||
if not self.is_on_page(pages.LoginPage):
|
if self.is_logged():
|
||||||
self.home()
|
self.logger.debug('already logged in')
|
||||||
|
return
|
||||||
|
|
||||||
|
self.is_logging = True
|
||||||
|
# Are we on the good page?
|
||||||
|
if not self.is_on_page(pages.LoginPage):
|
||||||
|
self.logger.debug('going to login page')
|
||||||
|
BaseBrowser.home(self)
|
||||||
|
self.logger.debug('attempting to log in')
|
||||||
self.page.login(self.username, self.password)
|
self.page.login(self.username, self.password)
|
||||||
self.is_logging = False
|
self.is_logging = False
|
||||||
|
|
||||||
|
|
@ -73,17 +86,39 @@ class Cragr(BaseBrowser):
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
def get_accounts_list(self):
|
def get_accounts_list(self):
|
||||||
# FIXME we call the login() method that will redirect to the accounts list page.
|
self.logger.debug('accounts list required')
|
||||||
# However, if we are already logged, using the "Comptes" link would be a better approach.
|
self.home()
|
||||||
# Something like //img[contains(@alt, "Comptes")] may be generic enough.
|
|
||||||
# Note the same hack is used in the do_transfer method.
|
|
||||||
self.login()
|
|
||||||
return self.page.get_list()
|
return self.page.get_list()
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
|
"""
|
||||||
|
Ensure we are both logged and on the accounts list.
|
||||||
|
"""
|
||||||
|
self.logger.debug('accounts list page required')
|
||||||
|
if self.is_on_page(pages.AccountsList) and self.page.is_accounts_list():
|
||||||
|
self.logger.debug('already on accounts list')
|
||||||
|
return
|
||||||
|
|
||||||
|
# simply go to http(s)://the.doma.in/
|
||||||
BaseBrowser.home(self)
|
BaseBrowser.home(self)
|
||||||
if self.is_on_page(pages.LoginPage) and self.is_logged():
|
|
||||||
self.location('%s://%s/accounting/listAccounts' % (self.PROTOCOL, self.DOMAIN))
|
if self.is_on_page(pages.LoginPage):
|
||||||
|
if not self.is_logged():
|
||||||
|
# So, we are not logged on the login page -- what about logging ourselves?
|
||||||
|
self.login()
|
||||||
|
# we assume we are logged in
|
||||||
|
# for some regions, we may stay on the login page once we're
|
||||||
|
# logged in, without being redirected...
|
||||||
|
if self.is_on_page(pages.LoginPage):
|
||||||
|
# ... so we have to move by ourselves
|
||||||
|
self.move_to_accounts_list()
|
||||||
|
|
||||||
|
def move_to_accounts_list(self):
|
||||||
|
"""
|
||||||
|
For regions where you can stay on http(s)://the.doma.in/ while you are
|
||||||
|
logged in, move to the accounts list
|
||||||
|
"""
|
||||||
|
self.location('%s://%s/accounting/listAccounts' % (self.PROTOCOL, self.DOMAIN))
|
||||||
|
|
||||||
def get_account(self, id):
|
def get_account(self, id):
|
||||||
assert isinstance(id, basestring)
|
assert isinstance(id, basestring)
|
||||||
|
|
@ -100,6 +135,7 @@ class Cragr(BaseBrowser):
|
||||||
operations_count = 0
|
operations_count = 0
|
||||||
while (page_url):
|
while (page_url):
|
||||||
# 1st, go on the account page
|
# 1st, go on the account page
|
||||||
|
self.logger.debug('going on: %s' % page_url)
|
||||||
self.location('https://%s%s' % (self.DOMAIN, page_url))
|
self.location('https://%s%s' % (self.DOMAIN, page_url))
|
||||||
|
|
||||||
# then, expand all history
|
# then, expand all history
|
||||||
|
|
@ -133,7 +169,7 @@ class Cragr(BaseBrowser):
|
||||||
"""
|
"""
|
||||||
# access the transfer page
|
# access the transfer page
|
||||||
transfer_page_unreachable_message = u'Could not reach the transfer page.'
|
transfer_page_unreachable_message = u'Could not reach the transfer page.'
|
||||||
self.login()
|
self.home()
|
||||||
if not self.page.is_accounts_list():
|
if not self.page.is_accounts_list():
|
||||||
raise TransferError(transfer_page_unreachable_message)
|
raise TransferError(transfer_page_unreachable_message)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue