diff --git a/modules/afer/browser.py b/modules/afer/browser.py index 3a705d95e87d1574825d453a437ba4c3977dee9e..57be7188a7a97c00fef67a9ff9178d704def8946 100644 --- a/modules/afer/browser.py +++ b/modules/afer/browser.py @@ -25,27 +25,24 @@ from weboob.tools.compat import basestring from .pages import ( - LoginPage, IndexPage, BadLogin, AccountDetailPage, AccountHistoryPage, MigrationPage + LoginPage, IndexPage, WrongPasswordPage, WrongWebsitePage, + AccountDetailPage, AccountHistoryPage, MigrationPage, ) class AferBrowser(LoginBrowser): BASEURL = 'https://adherent.gie-afer.fr' - login = URL(r'/espaceadherent/MonCompte/Connexion', LoginPage) + login = URL(r'/espaceadherent/MonCompte/Connexion$', LoginPage) + wrong_password = URL(r'/espaceadherent/MonCompte/Connexion\?err=6001', WrongPasswordPage) + wrong_website = URL(r'/espaceadherent/MonCompte/Connexion\?err=6008', WrongWebsitePage) migration = URL(r'/espaceadherent/MonCompte/Migration', MigrationPage) - # TODO check all following urls once users have migrated to new credentials - bad_login = URL('/names.nsf\?Login', BadLogin) index = URL('/web/ega.nsf/listeAdhesions\?OpenForm', IndexPage) account_detail = URL('/web/ega.nsf/soldeEpargne\?openForm', AccountDetailPage) account_history = URL('/web/ega.nsf/generationSearchModule\?OpenAgent', AccountHistoryPage) history_detail = URL('/web/ega.nsf/WOpendetailOperation\?OpenAgent', AccountHistoryPage) def do_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.password, basestring) self.login.go() @@ -58,13 +55,11 @@ def do_login(self): if self.migration.is_here(): raise BrowserPasswordExpired(self.page.get_error()) - if self.bad_login.is_here(): + if self.wrong_password.is_here(): error = self.page.get_error() - if "La saisie de l’identifiant ou du code confidentiel est incorrecte" in error or \ - "Veuillez-vous identifier" in error: + if error: raise BrowserIncorrectPassword(error) - else: - assert False, "Message d'erreur inconnu: %s" % error + assert False, 'We landed on WrongPasswordPage but no error message was fetched.' @need_login diff --git a/modules/afer/pages.py b/modules/afer/pages.py index f4fe1255f3c03a8376a45afcf58fcc67275e991d..890fee0872e1a3a3d71ffb2265bc84dbeed9eb71 100644 --- a/modules/afer/pages.py +++ b/modules/afer/pages.py @@ -39,15 +39,27 @@ def login(self, login, passwd): form.submit() -class BadLogin(HTMLPage): +class WrongPasswordPage(HTMLPage): def get_error(self): - return CleanText('//div[@id="idDivErrorLogin"]')(self.doc) + return CleanText('//p[contains(text(), "Votre saisie est erronée")]')(self.doc) + + +class WrongWebsitePage(HTMLPage): + # We land on this page when the website indicates that + # an account is already created on the 'Aviva et moi' space, + # So we check the message and raise ActionNeeded with it + def on_load(self): + message = CleanText('//p[contains(text(), "Vous êtes déjà inscrit")]')(self.doc) + if message: + raise ActionNeeded(message) + assert False, 'We landed on WrongWebsitePage but no message was fetched.' class MigrationPage(HTMLPage): def get_error(self): return CleanText('//h1[contains(text(), "Votre nouvel identifiant et mot de passe")]')(self.doc) + class IndexPage(LoggedPage, HTMLPage): def on_load(self): HTMLPage.on_load(self)