Commit 499e2cb1 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Romain Bignon

[cragr] support adding recipients by faking a transfer

The recipients list page often has a "add recipient" link, but not
always. When it's missing, we can still add a recipient by faking a
transfer on the new recipient, we just have to quit before confirming
the transfer.

Closes: 567914@redmine
parent 10c6602a
......@@ -111,7 +111,9 @@ class Cragr(LoginBrowser, StatesMixin):
recipient_misc = URL(r'/stb/collecteNI\?fwkaid=([\d_]+)&fwkpid=([\d_]+)$', RecipientMiscPage)
recipientlist = URL(r'/stb/collecteNI\?.*&act=Vilistedestinataires.*', RecipientListPage)
recipient_page = URL(r'/stb/collecteNI\?.*fwkaction=Ajouter.*', RecipientPage)
recipient_page = URL(r'/stb/collecteNI\?.*fwkaction=Ajouter.*',
r'/stb/collecteNI.*&IDENT=LI_VIR_RIB1&VIR_VIR1_FR3_LE=0&T3SEF_MTT_EURO=&T3SEF_MTT_CENT=&VICrt_REFERENCE=$',
RecipientPage)
unavailable_page = URL(r'/stb/collecteNI\?fwkaid=([\d_]+)&fwkpid=([\d_]+)$', UnavailablePage)
......@@ -658,7 +660,22 @@ class Cragr(LoginBrowser, StatesMixin):
raise AddRecipientError('SMS verification code is invalid')
self.transfer_init_page.go(sag=self.sag)
assert self.transfer_init_page.is_here()
self.location(self.page.url_list_recipients())
# there are 2 pages from where we can add a new recipient:
# - RecipientListPage, but the link is sometimes missing
# - TransferPage, start making a transfer with a new recipient but don't complete the transfer
# but it seems dangerous since we have to set an amount, etc.
# so we implement it in 2 ways with a preference for RecipientListPage
if self.page.url_add_recipient():
self.logger.debug('good, we can add a recipient from the recipient list')
else:
# in this case, the link was missing
self.logger.warning('cannot add a recipient from the recipient list page, pretending to make a transfer in order to add it')
self.transfer_init_page.go(sag=self.sag)
assert self.transfer_init_page.is_here()
self.location(self.page.url_add_recipient())
if not ('sms_code' in params and self.page.can_send_code()):
......@@ -676,6 +693,11 @@ class Cragr(LoginBrowser, StatesMixin):
self.page.submit_recipient(recipient.label, recipient.iban)
self.page.confirm_recipient()
self.page.check_recipient_error()
if self.transfer_page.is_here():
# in this case, we were pretending to make a transfer, just to add the recipient
# go back to transfer page to abort the transfer and see the new recipient
self.transfer_init_page.go(sag=self.sag)
assert self.transfer_init_page.is_here()
res = self.page.find_recipient(recipient.iban)
if res is None:
......
......@@ -1193,13 +1193,32 @@ class TransferInit(MyLoggedPage, BasePage):
def url_list_recipients(self):
return CleanText(u'(//a[contains(text(),"Liste des bénéficiaires")])[1]/@href')(self.doc)
def url_add_recipient(self):
link = Link('//a[text()="+ Saisir un autre compte bénéficiaire"]')(self.doc)
return link + '&IDENT=LI_VIR_RIB1&VIR_VIR1_FR3_LE=0&T3SEF_MTT_EURO=&T3SEF_MTT_CENT=&VICrt_REFERENCE='
class RecipientListPage(MyLoggedPage, BasePage):
def url_add_recipient(self):
return CleanText(u'//a[contains(text(),"Ajouter un compte destinataire")]/@href')(self.doc)
class TransferPage(CollectePageMixin, MyLoggedPage, BasePage):
class RecipientAddingMixin(object):
def submit_recipient(self, label, iban):
try:
form = self.get_form(name='frm_fwk')
except FormNotFound:
raise AddRecipientError('An error occurred before sending recipient')
form['NOM_BENEF'] = label
for i in range(9):
form['CIBAN%d' % (i + 1)] = iban[i * 4:(i + 1) * 4]
form['fwkaction'] = 'VerifCodeIBAN'
form['fwkcodeaction'] = 'Executer'
form.submit()
class TransferPage(RecipientAddingMixin, CollectePageMixin, MyLoggedPage, BasePage):
IS_HERE_TEXT = 'Virement'
### for transfers
......@@ -1283,8 +1302,26 @@ class TransferPage(CollectePageMixin, MyLoggedPage, BasePage):
if err:
raise TransferBankError(message=err)
### add a recipient by faking a transfer
def confirm_recipient(self):
# pretend to make a transfer
form = self.get_form(name='frm_fwk')
form['AJOUT_BENEF_CHECK'] = 'on'
form['fwkcodeaction'] = 'Executer'
form['fwkaction'] = 'Suite'
form['T3SEF_MTT_EURO'] = '1'
form['DEVISE'] = 'EUR'
form.submit()
def check_recipient_error(self):
# this is a copy-paste from RecipientMiscPage, i can't test if it works on this page...
msg = CleanText('//tr[@bgcolor="#C74545"]', default='')(self.doc) # there is no id, class or anything...
if msg:
raise AddRecipientError(message=msg)
class RecipientMiscPage(CollectePageMixin, MyLoggedPage, BasePage):
class RecipientMiscPage(RecipientAddingMixin, CollectePageMixin, MyLoggedPage, BasePage):
IS_HERE_TEXT = 'Liste des comptes bénéficiaires'
### for adding recipients
......@@ -1299,19 +1336,6 @@ class RecipientMiscPage(CollectePageMixin, MyLoggedPage, BasePage):
def get_sms_error(self):
return CleanText('//div[@class="blc-choix-wrap-erreur"]')(self.doc)
def submit_recipient(self, label, iban):
try:
form = self.get_form(name='frm_fwk')
except FormNotFound:
raise AddRecipientError('An error occurred before sending recipient')
form['NOM_BENEF'] = label
for i in range(9):
form['CIBAN%d' % (i + 1)] = iban[i * 4:(i + 1) * 4]
form['fwkaction'] = 'VerifCodeIBAN'
form['fwkcodeaction'] = 'Executer'
form.submit()
def confirm_recipient(self):
try:
form = self.get_form(name='frm_fwk')
......
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