Commit 24d1deb0 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by ntome

[cragr/api] Handle perimeters without a main account

Some perimeters seem to have no main account (or no account at all) so
we must check this before calling get_main_account().

Closes: 11808@zendesk
parent af6202d0
......@@ -228,30 +228,32 @@ class CragrAPI(LoginBrowser):
for contract in range(total_spaces):
if not self.check_space_connection(contract):
self.logger.warning('Server returned error 500 twice when trying to access space %s, this space will be skipped' % contract)
self.logger.warning('Server returned error 500 twice when trying to access space %s, this space will be skipped', contract)
continue
# The main account is not located at the same place in the JSON.
main_account = self.page.get_main_account()
if main_account.balance == NotAvailable:
self.check_space_connection(contract)
# Some spaces have no main account
if self.page.has_main_account():
# The main account is not located at the same place in the JSON.
main_account = self.page.get_main_account()
if main_account.balance == NotAvailable:
self.logger.warning('Could not fetch the balance for main account %s.' % main_account.id)
# Get cards for the main account
if self.page.has_main_cards():
for card in self.page.iter_main_cards():
card.parent = main_account
card.currency = card.parent.currency
card.owner_type = card.parent.owner_type
card._category = card.parent._category
card._contract = contract
deferred_cards[card.id] = card
main_account.owner_type = self.page.get_owner_type()
main_account._contract = contract
space_type = self.page.get_space_type()
self.check_space_connection(contract)
main_account = self.page.get_main_account()
if main_account.balance == NotAvailable:
self.logger.warning('Could not fetch the balance for main account %s.', main_account.id)
# Get cards for the main account
if self.page.has_main_cards():
for card in self.page.iter_main_cards():
card.parent = main_account
card.currency = card.parent.currency
card.owner_type = card.parent.owner_type
card._category = card.parent._category
card._contract = contract
deferred_cards[card.id] = card
main_account.owner_type = self.page.get_owner_type()
main_account._contract = contract
space_type = self.page.get_space_type()
accounts_list = list(self.page.iter_accounts())
for account in accounts_list:
account._contract = contract
......
......@@ -232,6 +232,9 @@ class AccountsPage(LoggedPage, JsonPage):
)(self.html_doc)
return connection_id
def has_main_account(self):
return Dict('comptePrincipal', default=None)(self.doc)
@method
class get_main_account(ItemElement):
klass = Account
......
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