Merge lp:~elopio/osqa-sst-helpers/mail into lp:~online-services-qa/osqa-sst-helpers/canonical-identity-provider

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 17
Merged at revision: 17
Proposed branch: lp:~elopio/osqa-sst-helpers/mail
Merge into: lp:~online-services-qa/osqa-sst-helpers/canonical-identity-provider
Diff against target: 54 lines (+50/-0)
1 file modified
sso_sst_helpers/utils/mail.py (+50/-0)
To merge this branch: bzr merge lp:~elopio/osqa-sst-helpers/mail
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+125058@code.launchpad.net

Commit message

Added get_verification_code_from_email functions from sso acceptance tests.

Description of the change

Added get_verification_code_from_email functions from sso acceptance tests.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

This was proposed by bloodearnest and reviewed by me, but in the wrong branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'sso_sst_helpers/utils/mail.py'
--- sso_sst_helpers/utils/mail.py 1970-01-01 00:00:00 +0000
+++ sso_sst_helpers/utils/mail.py 2012-09-18 21:38:18 +0000
@@ -0,0 +1,50 @@
1import quopri
2import re
3
4from canonical.isd.tests.sst import mail
5
6
7def _get_verification_data_for_address(email_address):
8 """A private helper for public helpers below.
9
10 Note: We have two different public helpers here for verification
11 code and link so that functional tests don't need to deal with
12 idioms like:
13 vcode, ignored = get_verification_for_address(email_address).
14 """
15 email_msg = mail.get_latest_email_sent_to(email_address)
16 vcode = link = None
17 if email_msg:
18 # The body is encoded as quoted-printable. This affects any
19 # line longer than a certain length. Decode now to not have
20 # to worry about it in the regexen.
21 body = quopri.decodestring(email_msg.get_payload())
22 match = re.search(
23 'Here is your confirmation code:(.*)(Enter|If you made)',
24 body, re.S)
25 if match:
26 vcode = match.group(1).strip()
27 else:
28 raise AssertionError("No verification code found in email.")
29 match = re.search(
30 'confirm your (?:account|email address|reset):(.*)If',
31 body, re.S)
32 if match:
33 link = match.group(1).strip()
34 else:
35 raise AssertionError("No verification link found in email.")
36 return vcode, link
37
38
39def get_verification_code_for_address(email_address):
40 print("Retrieving verification code for %s." % email_address)
41 vcode, link = _get_verification_data_for_address(email_address)
42 print("Verification code retrieved: %s." % vcode)
43 return vcode
44
45
46def get_verification_link_for_address(email_address):
47 print("Retrieving verification link for %s." % email_address)
48 vcode, link = _get_verification_data_for_address(email_address)
49 print("Verification link retrieved: %s." % link)
50 return link

Subscribers

People subscribed via source and target branches

to all changes: