This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
/
browser_id.py
71 lines (56 loc) · 2.36 KB
/
browser_id.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import urllib2
import json
import selenium
class BrowserID(object):
VERIFY_URL_REGEX = 'https?:\/\/(\S+)\/verify_email_address\?token=(.{48})'
CONFIRM_URL_REGEX = 'https?:\/\/(\S+)\/confirm\?token=(.{48})'
RESET_URL_REGEX = 'https?:\/\/(\S+)\/reset_password\?token=(.{48})'
INCLUDE_URL_REGEX = '(https?:\/\/(\S+))\/include\.js'
def __init__(self, selenium, timeout=60):
self.selenium = selenium
self.timeout = timeout
def sign_in(self, email, password):
"""Signs in using the specified email address and password."""
from pages.sign_in import SignIn
sign_in = SignIn(self.selenium, timeout=self.timeout, expect='new')
sign_in.sign_in(email, password)
def persona_test_user(self, verified=True, env='prod'):
'''
Create a test user.
::Args::
- verified - boolean True/False should the user be verified
- env - string dev/stage/prod instance of persona.org used by
the system under test(default prod)
::Returns::
A dictionary that combines the values returned by the personatestuser API
and the values returned by browserid.mocks.MockUser.
{
'email': 'lopez401@personatestuser.org'
'primary_email': 'lopez401@personatestuser.org',
'pass': 'SOaUo9qJqYyBl1sN',
'password': 'SOaUo9qJqYyBl1sN',
'expires': '1346445745',
'verifier': 'https://verifier.dev.anosrep.org',
'browserid': 'https://login.dev.anosrep.org',
'token': 'U6bFrRZJrZggwkJ0gkpvC9tuNNaIXpvEZM11gzLnw9l4o4UK', # for verified=False only
'env': 'dev',
}
'''
command = ''
if verified:
command = 'email'
else:
command = 'unverified_email'
response = urllib2.urlopen(
'http://personatestuser.org/%s/%s' %
(command, env), timeout=self.timeout)
user = json.loads(response.read())
user['password'] = user['pass']
user['primary_email'] = user['email']
user.pop('events')
print user
return user