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.
Files changed (113) hide show
  1. EGG-INFO/PKG-INFO +176 -0
  2. EGG-INFO/SOURCES.txt +91 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/not-zip-safe +1 -0
  5. EGG-INFO/requires.txt +17 -0
  6. EGG-INFO/top_level.txt +2 -0
  7. pyramid_fullauth/__init__.py +105 -0
  8. pyramid_fullauth/__init__.pyc +0 -0
  9. pyramid_fullauth/auth.py +66 -0
  10. pyramid_fullauth/auth.pyc +0 -0
  11. pyramid_fullauth/events.py +267 -0
  12. pyramid_fullauth/events.pyc +0 -0
  13. pyramid_fullauth/exceptions.py +47 -0
  14. pyramid_fullauth/exceptions.pyc +0 -0
  15. pyramid_fullauth/models/__init__.py +189 -0
  16. pyramid_fullauth/models/__init__.pyc +0 -0
  17. pyramid_fullauth/models/mixins/__init__.py +9 -0
  18. pyramid_fullauth/models/mixins/__init__.pyc +0 -0
  19. pyramid_fullauth/models/mixins/email.py +81 -0
  20. pyramid_fullauth/models/mixins/email.pyc +0 -0
  21. pyramid_fullauth/models/mixins/password.py +141 -0
  22. pyramid_fullauth/models/mixins/password.pyc +0 -0
  23. pyramid_fullauth/request.py +69 -0
  24. pyramid_fullauth/request.pyc +0 -0
  25. pyramid_fullauth/resources/helpers/social.mako +17 -0
  26. pyramid_fullauth/resources/locale/pyramid_fullauth.pot +216 -0
  27. pyramid_fullauth/resources/templates/403.mako +11 -0
  28. pyramid_fullauth/resources/templates/_form.login.mako +44 -0
  29. pyramid_fullauth/resources/templates/_form.register.mako +47 -0
  30. pyramid_fullauth/resources/templates/_social.login.mako +17 -0
  31. pyramid_fullauth/resources/templates/activate.mako +14 -0
  32. pyramid_fullauth/resources/templates/email_change.mako +33 -0
  33. pyramid_fullauth/resources/templates/layout.mako +13 -0
  34. pyramid_fullauth/resources/templates/login.mako +14 -0
  35. pyramid_fullauth/resources/templates/register.mako +22 -0
  36. pyramid_fullauth/resources/templates/reset.mako +34 -0
  37. pyramid_fullauth/resources/templates/reset.proceed.mako +41 -0
  38. pyramid_fullauth/routing/__init__.py +5 -0
  39. pyramid_fullauth/routing/__init__.pyc +0 -0
  40. pyramid_fullauth/routing/predicates.py +86 -0
  41. pyramid_fullauth/routing/predicates.pyc +0 -0
  42. pyramid_fullauth/tools.py +66 -0
  43. pyramid_fullauth/tools.pyc +0 -0
  44. pyramid_fullauth/views/__init__.py +15 -0
  45. pyramid_fullauth/views/__init__.pyc +0 -0
  46. pyramid_fullauth/views/basic/__init__.py +5 -0
  47. pyramid_fullauth/views/basic/__init__.pyc +0 -0
  48. pyramid_fullauth/views/basic/activate.py +44 -0
  49. pyramid_fullauth/views/basic/activate.pyc +0 -0
  50. pyramid_fullauth/views/basic/forbidden.py +47 -0
  51. pyramid_fullauth/views/basic/forbidden.pyc +0 -0
  52. pyramid_fullauth/views/basic/login.py +128 -0
  53. pyramid_fullauth/views/basic/login.pyc +0 -0
  54. pyramid_fullauth/views/basic/logout.py +28 -0
  55. pyramid_fullauth/views/basic/logout.pyc +0 -0
  56. pyramid_fullauth/views/basic/profile/__init__.py +5 -0
  57. pyramid_fullauth/views/basic/profile/__init__.pyc +0 -0
  58. pyramid_fullauth/views/basic/profile/email.py +107 -0
  59. pyramid_fullauth/views/basic/profile/email.pyc +0 -0
  60. pyramid_fullauth/views/basic/profile/password.py +128 -0
  61. pyramid_fullauth/views/basic/profile/password.pyc +0 -0
  62. pyramid_fullauth/views/basic/register.py +110 -0
  63. pyramid_fullauth/views/basic/register.pyc +0 -0
  64. pyramid_fullauth/views/social.py +218 -0
  65. pyramid_fullauth/views/social.pyc +0 -0
  66. tests/__init__.py +1 -0
  67. tests/__init__.pyc +0 -0
  68. tests/conftest.py +190 -0
  69. tests/conftest.pyc +0 -0
  70. tests/tools.py +54 -0
  71. tests/tools.pyc +0 -0
  72. tests/unit/test_default_settings.py +15 -0
  73. tests/unit/test_default_settings.pyc +0 -0
  74. tests/unit/test_groupfinder.py +20 -0
  75. tests/unit/test_groupfinder.pyc +0 -0
  76. tests/unit/test_social_view.py +65 -0
  77. tests/unit/test_social_view.pyc +0 -0
  78. tests/unit/test_tools.py +24 -0
  79. tests/unit/test_tools.pyc +0 -0
  80. tests/unit/test_user_active.py +31 -0
  81. tests/unit/test_user_active.pyc +0 -0
  82. tests/unit/test_user_admin.py +61 -0
  83. tests/unit/test_user_admin.pyc +0 -0
  84. tests/unit/test_user_email.py +37 -0
  85. tests/unit/test_user_email.pyc +0 -0
  86. tests/unit/test_user_password.py +52 -0
  87. tests/unit/test_user_password.pyc +0 -0
  88. tests/unit/test_user_providers.py +24 -0
  89. tests/unit/test_user_providers.pyc +0 -0
  90. tests/unit/test_user_repr.py +29 -0
  91. tests/unit/test_user_repr.pyc +0 -0
  92. tests/unit/test_validators.py +44 -0
  93. tests/unit/test_validators.pyc +0 -0
  94. tests/views/__init__.py +1 -0
  95. tests/views/__init__.pyc +0 -0
  96. tests/views/conftest.py +15 -0
  97. tests/views/conftest.pyc +0 -0
  98. tests/views/test_activation.py +83 -0
  99. tests/views/test_activation.pyc +0 -0
  100. tests/views/test_email.py +175 -0
  101. tests/views/test_email.pyc +0 -0
  102. tests/views/test_events.py +546 -0
  103. tests/views/test_events.pyc +0 -0
  104. tests/views/test_login.py +151 -0
  105. tests/views/test_login.pyc +0 -0
  106. tests/views/test_login_social.py +254 -0
  107. tests/views/test_login_social.pyc +0 -0
  108. tests/views/test_logout.py +42 -0
  109. tests/views/test_logout.pyc +0 -0
  110. tests/views/test_register.py +134 -0
  111. tests/views/test_register.pyc +0 -0
  112. tests/views/test_reset.py +100 -0
  113. 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