pyramid-fullauth 0.3.0__py2.7.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +176 -0
- EGG-INFO/SOURCES.txt +91 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +17 -0
- EGG-INFO/top_level.txt +2 -0
- pyramid_fullauth/__init__.py +105 -0
- pyramid_fullauth/__init__.pyc +0 -0
- pyramid_fullauth/auth.py +66 -0
- pyramid_fullauth/auth.pyc +0 -0
- pyramid_fullauth/events.py +267 -0
- pyramid_fullauth/events.pyc +0 -0
- pyramid_fullauth/exceptions.py +47 -0
- pyramid_fullauth/exceptions.pyc +0 -0
- pyramid_fullauth/models/__init__.py +189 -0
- pyramid_fullauth/models/__init__.pyc +0 -0
- pyramid_fullauth/models/mixins/__init__.py +9 -0
- pyramid_fullauth/models/mixins/__init__.pyc +0 -0
- pyramid_fullauth/models/mixins/email.py +81 -0
- pyramid_fullauth/models/mixins/email.pyc +0 -0
- pyramid_fullauth/models/mixins/password.py +141 -0
- pyramid_fullauth/models/mixins/password.pyc +0 -0
- pyramid_fullauth/request.py +69 -0
- pyramid_fullauth/request.pyc +0 -0
- pyramid_fullauth/resources/helpers/social.mako +17 -0
- pyramid_fullauth/resources/locale/pyramid_fullauth.pot +216 -0
- pyramid_fullauth/resources/templates/403.mako +11 -0
- pyramid_fullauth/resources/templates/_form.login.mako +44 -0
- pyramid_fullauth/resources/templates/_form.register.mako +47 -0
- pyramid_fullauth/resources/templates/_social.login.mako +17 -0
- pyramid_fullauth/resources/templates/activate.mako +14 -0
- pyramid_fullauth/resources/templates/email_change.mako +33 -0
- pyramid_fullauth/resources/templates/layout.mako +13 -0
- pyramid_fullauth/resources/templates/login.mako +14 -0
- pyramid_fullauth/resources/templates/register.mako +22 -0
- pyramid_fullauth/resources/templates/reset.mako +34 -0
- pyramid_fullauth/resources/templates/reset.proceed.mako +41 -0
- pyramid_fullauth/routing/__init__.py +5 -0
- pyramid_fullauth/routing/__init__.pyc +0 -0
- pyramid_fullauth/routing/predicates.py +86 -0
- pyramid_fullauth/routing/predicates.pyc +0 -0
- pyramid_fullauth/tools.py +66 -0
- pyramid_fullauth/tools.pyc +0 -0
- pyramid_fullauth/views/__init__.py +15 -0
- pyramid_fullauth/views/__init__.pyc +0 -0
- pyramid_fullauth/views/basic/__init__.py +5 -0
- pyramid_fullauth/views/basic/__init__.pyc +0 -0
- pyramid_fullauth/views/basic/activate.py +44 -0
- pyramid_fullauth/views/basic/activate.pyc +0 -0
- pyramid_fullauth/views/basic/forbidden.py +47 -0
- pyramid_fullauth/views/basic/forbidden.pyc +0 -0
- pyramid_fullauth/views/basic/login.py +128 -0
- pyramid_fullauth/views/basic/login.pyc +0 -0
- pyramid_fullauth/views/basic/logout.py +28 -0
- pyramid_fullauth/views/basic/logout.pyc +0 -0
- pyramid_fullauth/views/basic/profile/__init__.py +5 -0
- pyramid_fullauth/views/basic/profile/__init__.pyc +0 -0
- pyramid_fullauth/views/basic/profile/email.py +107 -0
- pyramid_fullauth/views/basic/profile/email.pyc +0 -0
- pyramid_fullauth/views/basic/profile/password.py +128 -0
- pyramid_fullauth/views/basic/profile/password.pyc +0 -0
- pyramid_fullauth/views/basic/register.py +110 -0
- pyramid_fullauth/views/basic/register.pyc +0 -0
- pyramid_fullauth/views/social.py +218 -0
- pyramid_fullauth/views/social.pyc +0 -0
- tests/__init__.py +1 -0
- tests/__init__.pyc +0 -0
- tests/conftest.py +190 -0
- tests/conftest.pyc +0 -0
- tests/tools.py +54 -0
- tests/tools.pyc +0 -0
- tests/unit/test_default_settings.py +15 -0
- tests/unit/test_default_settings.pyc +0 -0
- tests/unit/test_groupfinder.py +20 -0
- tests/unit/test_groupfinder.pyc +0 -0
- tests/unit/test_social_view.py +65 -0
- tests/unit/test_social_view.pyc +0 -0
- tests/unit/test_tools.py +24 -0
- tests/unit/test_tools.pyc +0 -0
- tests/unit/test_user_active.py +31 -0
- tests/unit/test_user_active.pyc +0 -0
- tests/unit/test_user_admin.py +61 -0
- tests/unit/test_user_admin.pyc +0 -0
- tests/unit/test_user_email.py +37 -0
- tests/unit/test_user_email.pyc +0 -0
- tests/unit/test_user_password.py +52 -0
- tests/unit/test_user_password.pyc +0 -0
- tests/unit/test_user_providers.py +24 -0
- tests/unit/test_user_providers.pyc +0 -0
- tests/unit/test_user_repr.py +29 -0
- tests/unit/test_user_repr.pyc +0 -0
- tests/unit/test_validators.py +44 -0
- tests/unit/test_validators.pyc +0 -0
- tests/views/__init__.py +1 -0
- tests/views/__init__.pyc +0 -0
- tests/views/conftest.py +15 -0
- tests/views/conftest.pyc +0 -0
- tests/views/test_activation.py +83 -0
- tests/views/test_activation.pyc +0 -0
- tests/views/test_email.py +175 -0
- tests/views/test_email.pyc +0 -0
- tests/views/test_events.py +546 -0
- tests/views/test_events.pyc +0 -0
- tests/views/test_login.py +151 -0
- tests/views/test_login.pyc +0 -0
- tests/views/test_login_social.py +254 -0
- tests/views/test_login_social.pyc +0 -0
- tests/views/test_logout.py +42 -0
- tests/views/test_logout.pyc +0 -0
- tests/views/test_register.py +134 -0
- tests/views/test_register.pyc +0 -0
- tests/views/test_reset.py +100 -0
- tests/views/test_reset.pyc +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Email change views."""
|
|
2
|
+
import pytest
|
|
3
|
+
import transaction
|
|
4
|
+
|
|
5
|
+
from sqlalchemy.orm.exc import NoResultFound
|
|
6
|
+
from pyramid.compat import text_type
|
|
7
|
+
from pyramid_fullauth.models import User
|
|
8
|
+
|
|
9
|
+
from tests.tools import authenticate, DEFAULT_USER
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_email_view_not_logged(default_app):
|
|
13
|
+
"""Try to access email change view anonymously."""
|
|
14
|
+
app = default_app
|
|
15
|
+
res = app.get('/email/change')
|
|
16
|
+
assert res.status_code == 302
|
|
17
|
+
assert res.location == 'http://localhost/login?after=%2Femail%2Fchange'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_email_view_logged(db_session, active_user, default_app):
|
|
21
|
+
"""Simple get for change email view."""
|
|
22
|
+
app = default_app
|
|
23
|
+
db_session.close()
|
|
24
|
+
# Session are de-syncronised
|
|
25
|
+
|
|
26
|
+
# login user
|
|
27
|
+
authenticate(app)
|
|
28
|
+
|
|
29
|
+
res = app.get('/email/change')
|
|
30
|
+
assert res.status_code == 200
|
|
31
|
+
assert res.form
|
|
32
|
+
assert res.form['email']
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_email_valid(db_session, active_user, default_app):
|
|
36
|
+
"""Change email with valid data."""
|
|
37
|
+
app = default_app
|
|
38
|
+
|
|
39
|
+
authenticate(app)
|
|
40
|
+
email = DEFAULT_USER['email']
|
|
41
|
+
new_email = 'email@email.com'
|
|
42
|
+
|
|
43
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
44
|
+
|
|
45
|
+
res = app.get('/email/change')
|
|
46
|
+
form = res.form
|
|
47
|
+
form['email'] = new_email
|
|
48
|
+
res = form.submit()
|
|
49
|
+
assert res
|
|
50
|
+
|
|
51
|
+
transaction.commit()
|
|
52
|
+
|
|
53
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
54
|
+
assert user.new_email == new_email
|
|
55
|
+
assert user.email == email
|
|
56
|
+
assert user.email_change_key is not None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_email_valid_xhr(db_session, active_user, default_app):
|
|
60
|
+
"""Change email with valid data."""
|
|
61
|
+
app = default_app
|
|
62
|
+
|
|
63
|
+
authenticate(app)
|
|
64
|
+
email = DEFAULT_USER['email']
|
|
65
|
+
new_email = 'email@email.com'
|
|
66
|
+
|
|
67
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
68
|
+
|
|
69
|
+
res = app.get('/email/change')
|
|
70
|
+
res = app.post(
|
|
71
|
+
'/email/change',
|
|
72
|
+
{
|
|
73
|
+
'csrf_token': res.form['csrf_token'].value,
|
|
74
|
+
'email': new_email},
|
|
75
|
+
xhr=True)
|
|
76
|
+
assert res.json['status'] is True
|
|
77
|
+
|
|
78
|
+
transaction.commit()
|
|
79
|
+
|
|
80
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
81
|
+
assert user.new_email == new_email
|
|
82
|
+
assert user.email == email
|
|
83
|
+
assert user.email_change_key is not None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_wrong_email(db_session, active_user, default_app, invalid_email):
|
|
87
|
+
"""Change email with incorrect email."""
|
|
88
|
+
app = default_app
|
|
89
|
+
# login user
|
|
90
|
+
authenticate(app)
|
|
91
|
+
|
|
92
|
+
res = app.get('/email/change')
|
|
93
|
+
form = res.form
|
|
94
|
+
form['email'] = invalid_email
|
|
95
|
+
res = form.submit()
|
|
96
|
+
assert 'Error! Incorrect e-mail format' in res
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_empty_email(db_session, active_user, default_app):
|
|
100
|
+
"""Try to change email with empty value."""
|
|
101
|
+
app = default_app
|
|
102
|
+
# login user
|
|
103
|
+
authenticate(app)
|
|
104
|
+
|
|
105
|
+
res = app.get('/email/change')
|
|
106
|
+
form = res.form
|
|
107
|
+
form['email'] = ''
|
|
108
|
+
res = form.submit()
|
|
109
|
+
assert 'Error! E-mail is empty' in res
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_existing_email(db_session, active_user, default_app):
|
|
113
|
+
"""Try to change email to existing one email."""
|
|
114
|
+
# add other user
|
|
115
|
+
existing_email = text_type("existing@email.eg")
|
|
116
|
+
db_session.add(
|
|
117
|
+
User(
|
|
118
|
+
email=existing_email,
|
|
119
|
+
password=text_type("somepassword"),
|
|
120
|
+
address_ip=DEFAULT_USER['address_ip']
|
|
121
|
+
))
|
|
122
|
+
transaction.commit()
|
|
123
|
+
# login user
|
|
124
|
+
authenticate(default_app)
|
|
125
|
+
|
|
126
|
+
# submit request!
|
|
127
|
+
res = default_app.get('/email/change')
|
|
128
|
+
form = res.form
|
|
129
|
+
form['email'] = existing_email
|
|
130
|
+
res = form.submit()
|
|
131
|
+
assert 'Error! User with this email exists' in res
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_email_proceed(db_session, active_user, default_app):
|
|
135
|
+
"""Confirm email change view."""
|
|
136
|
+
app = default_app
|
|
137
|
+
# login user
|
|
138
|
+
authenticate(app)
|
|
139
|
+
|
|
140
|
+
email = DEFAULT_USER['email']
|
|
141
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
142
|
+
|
|
143
|
+
new_email = u'email2@email.com'
|
|
144
|
+
user.set_new_email(new_email)
|
|
145
|
+
transaction.commit()
|
|
146
|
+
|
|
147
|
+
user = db_session.merge(user)
|
|
148
|
+
res = app.get('/email/change/' + user.email_change_key)
|
|
149
|
+
assert res.status_code == 302
|
|
150
|
+
|
|
151
|
+
with pytest.raises(NoResultFound):
|
|
152
|
+
# there is no user with old email
|
|
153
|
+
db_session.query(User).filter(User.email == email).one()
|
|
154
|
+
|
|
155
|
+
user = db_session.query(User).filter(User.email == new_email).one()
|
|
156
|
+
assert not user.email_change_key
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_email_proceed_wrong_key(db_session, active_user, default_app):
|
|
160
|
+
"""Try to confirm email change view with wrong key."""
|
|
161
|
+
app = default_app
|
|
162
|
+
# login user
|
|
163
|
+
authenticate(app)
|
|
164
|
+
|
|
165
|
+
email = DEFAULT_USER['email']
|
|
166
|
+
user = db_session.query(User).filter(User.email == email).one()
|
|
167
|
+
|
|
168
|
+
new_email = u'email2@email.com'
|
|
169
|
+
user.set_new_email(new_email)
|
|
170
|
+
transaction.commit()
|
|
171
|
+
|
|
172
|
+
user = db_session.merge(user)
|
|
173
|
+
res = app.get(
|
|
174
|
+
'/email/change/' + user.email_change_key + 'randomchars', status=404)
|
|
175
|
+
assert res.status_code == 404
|
|
Binary file
|