Commit ad92e7fb authored by Jérome Perrin's avatar Jérome Perrin

credential: be a bit more explicit in "I forgot my username" test

person reference contained the username, so test was also passing, but what we
really want to test is that the username is in the mail body.
parent 8c8c1e58
Pipeline #14611 running with stage
...@@ -569,6 +569,7 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -569,6 +569,7 @@ class TestERP5Credential(ERP5TypeTestCase):
""" """
default_email_text = "bart@duff.com" default_email_text = "bart@duff.com"
person_list = [] person_list = []
username_list = []
for reference in ['userX', 'bart', 'homer']: for reference in ['userX', 'bart', 'homer']:
portal = self.getPortalObject() portal = self.getPortalObject()
# create a person with 'secret' as password # create a person with 'secret' as password
...@@ -581,16 +582,19 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -581,16 +582,19 @@ class TestERP5Credential(ERP5TypeTestCase):
assignment = person.newContent(portal_type='Assignment', assignment = person.newContent(portal_type='Assignment',
function='member') function='member')
assignment.open() assignment.open()
username = person.getReference() + '-login'
# create a login # create a login
login = person.newContent( login = person.newContent(
portal_type='ERP5 Login', portal_type='ERP5 Login',
reference=person.getReference() + '-login', reference=username,
password='secret', password='secret',
) )
login.validate() login.validate()
person_list.append(person) person_list.append(person)
username_list.append(username)
sequence.edit(person_list=person_list, sequence.edit(person_list=person_list,
username_list=username_list,
default_email_text=default_email_text) default_email_text=default_email_text)
def stepCreateCredentialRecovery(self, sequence=None, sequence_list=None, def stepCreateCredentialRecovery(self, sequence=None, sequence_list=None,
...@@ -738,28 +742,21 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -738,28 +742,21 @@ class TestERP5Credential(ERP5TypeTestCase):
def stepCheckEmailIsSentForUsername(self, sequence=None, sequence_list=None, **kw): def stepCheckEmailIsSentForUsername(self, sequence=None, sequence_list=None, **kw):
''' '''
Check an email containing the usernames list as been sent Check an email containing the usernames as been sent
''' '''
person_list = sequence.get('person_list') # after accept, only one email is send containing the user names
email_text = sequence.get('default_email_text')
# after accept, only one email is send containing the reset link
previous_message = self.portal.MailHost._previous_message previous_message = self.portal.MailHost._previous_message
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
if len(previous_message): if len(previous_message):
self.assertNotEqual(previous_message[2], last_message[2]) self.assertNotEqual(previous_message[2], last_message[2])
decoded_message = self.decode_email(last_message[2]) decoded_message = self.decode_email(last_message[2])
body_message = decoded_message['body'] body_message = decoded_message['body']
for username in sequence['username_list']:
for person in person_list: self.assertIn(username, body_message)
match_obj = None
reference = person.getReference()
match_obj = re.search(reference, body_message)
# check the reset password link is in the mail
self.assertNotEquals(match_obj, None)
# check the mail is sent to the requester : # check the mail is sent to the requester :
send_to = decoded_message['headers']['to'] send_to = decoded_message['headers']['to']
self.assertEqual(email_text, send_to) self.assertEqual(send_to, sequence['default_email_text'])
def stepCheckPasswordChange(self, sequence=None, sequence_list=None, **kw): def stepCheckPasswordChange(self, sequence=None, sequence_list=None, **kw):
""" """
......
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