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

Subscribers

People subscribed via source and target branches

to all changes: