pyramid-fullauth 0.3.2__py2.7.egg → 0.6.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 (104) hide show
  1. EGG-INFO/PKG-INFO +53 -11
  2. EGG-INFO/SOURCES.txt +4 -0
  3. EGG-INFO/requires.txt +11 -10
  4. pyramid_fullauth/__init__.py +4 -4
  5. pyramid_fullauth/__init__.pyc +0 -0
  6. pyramid_fullauth/auth.py +5 -4
  7. pyramid_fullauth/auth.pyc +0 -0
  8. pyramid_fullauth/compat.py +20 -0
  9. pyramid_fullauth/compat.pyc +0 -0
  10. pyramid_fullauth/config/default.yaml +1 -1
  11. pyramid_fullauth/events.py +1 -20
  12. pyramid_fullauth/events.pyc +0 -0
  13. pyramid_fullauth/exceptions.py +1 -7
  14. pyramid_fullauth/exceptions.pyc +0 -0
  15. pyramid_fullauth/models/__init__.py +7 -8
  16. pyramid_fullauth/models/__init__.pyc +0 -0
  17. pyramid_fullauth/models/extensions/__init__.py +38 -0
  18. pyramid_fullauth/models/extensions/__init__.pyc +0 -0
  19. pyramid_fullauth/models/mixins/__init__.py +3 -2
  20. pyramid_fullauth/models/mixins/__init__.pyc +0 -0
  21. pyramid_fullauth/models/mixins/email.py +58 -10
  22. pyramid_fullauth/models/mixins/email.pyc +0 -0
  23. pyramid_fullauth/models/mixins/password.py +5 -11
  24. pyramid_fullauth/models/mixins/password.pyc +0 -0
  25. pyramid_fullauth/request.py +6 -5
  26. pyramid_fullauth/request.pyc +0 -0
  27. pyramid_fullauth/resources/helpers/social.mako +3 -3
  28. pyramid_fullauth/resources/locale/pyramid_fullauth.pot +23 -23
  29. pyramid_fullauth/resources/templates/403.mako +1 -1
  30. pyramid_fullauth/resources/templates/_form.login.mako +1 -1
  31. pyramid_fullauth/resources/templates/_form.register.mako +1 -1
  32. pyramid_fullauth/resources/templates/_social.login.mako +1 -1
  33. pyramid_fullauth/resources/templates/activate.mako +1 -1
  34. pyramid_fullauth/resources/templates/email_change.mako +1 -1
  35. pyramid_fullauth/resources/templates/layout.mako +1 -1
  36. pyramid_fullauth/resources/templates/login.mako +1 -1
  37. pyramid_fullauth/resources/templates/register.mako +1 -1
  38. pyramid_fullauth/resources/templates/reset.mako +1 -1
  39. pyramid_fullauth/resources/templates/reset.proceed.mako +1 -1
  40. pyramid_fullauth/routing/__init__.py +1 -1
  41. pyramid_fullauth/routing/__init__.pyc +0 -0
  42. pyramid_fullauth/routing/predicates.py +4 -3
  43. pyramid_fullauth/routing/predicates.pyc +0 -0
  44. pyramid_fullauth/tools.py +7 -4
  45. pyramid_fullauth/tools.pyc +0 -0
  46. pyramid_fullauth/views/__init__.py +2 -3
  47. pyramid_fullauth/views/__init__.pyc +0 -0
  48. pyramid_fullauth/views/basic/__init__.py +1 -1
  49. pyramid_fullauth/views/basic/__init__.pyc +0 -0
  50. pyramid_fullauth/views/basic/activate.py +1 -2
  51. pyramid_fullauth/views/basic/activate.pyc +0 -0
  52. pyramid_fullauth/views/basic/forbidden.py +3 -5
  53. pyramid_fullauth/views/basic/forbidden.pyc +0 -0
  54. pyramid_fullauth/views/basic/login.py +28 -34
  55. pyramid_fullauth/views/basic/login.pyc +0 -0
  56. pyramid_fullauth/views/basic/logout.py +1 -2
  57. pyramid_fullauth/views/basic/logout.pyc +0 -0
  58. pyramid_fullauth/views/basic/profile/__init__.py +1 -1
  59. pyramid_fullauth/views/basic/profile/__init__.pyc +0 -0
  60. pyramid_fullauth/views/basic/profile/email.py +44 -37
  61. pyramid_fullauth/views/basic/profile/email.pyc +0 -0
  62. pyramid_fullauth/views/basic/profile/password.py +6 -7
  63. pyramid_fullauth/views/basic/profile/password.pyc +0 -0
  64. pyramid_fullauth/views/basic/register.py +53 -27
  65. pyramid_fullauth/views/basic/register.pyc +0 -0
  66. pyramid_fullauth/views/social.py +7 -5
  67. pyramid_fullauth/views/social.pyc +0 -0
  68. tests/__init__.pyc +0 -0
  69. tests/conftest.py +23 -10
  70. tests/conftest.pyc +0 -0
  71. tests/tools.pyc +0 -0
  72. tests/unit/test_default_settings.pyc +0 -0
  73. tests/unit/test_groupfinder.pyc +0 -0
  74. tests/unit/test_social_view.py +28 -26
  75. tests/unit/test_social_view.pyc +0 -0
  76. tests/unit/test_tools.pyc +0 -0
  77. tests/unit/test_user_active.pyc +0 -0
  78. tests/unit/test_user_admin.pyc +0 -0
  79. tests/unit/test_user_email.pyc +0 -0
  80. tests/unit/test_user_password.py +1 -1
  81. tests/unit/test_user_password.pyc +0 -0
  82. tests/unit/test_user_providers.pyc +0 -0
  83. tests/unit/test_user_repr.py +4 -4
  84. tests/unit/test_user_repr.pyc +0 -0
  85. tests/unit/test_validators.py +1 -1
  86. tests/unit/test_validators.pyc +0 -0
  87. tests/views/__init__.pyc +0 -0
  88. tests/views/conftest.py +5 -0
  89. tests/views/conftest.pyc +0 -0
  90. tests/views/test_activation.py +13 -6
  91. tests/views/test_activation.pyc +0 -0
  92. tests/views/test_email.py +2 -2
  93. tests/views/test_email.pyc +0 -0
  94. tests/views/test_events.py +107 -49
  95. tests/views/test_events.pyc +0 -0
  96. tests/views/test_login.py +23 -2
  97. tests/views/test_login.pyc +0 -0
  98. tests/views/test_login_social.py +97 -69
  99. tests/views/test_login_social.pyc +0 -0
  100. tests/views/test_logout.pyc +0 -0
  101. tests/views/test_register.py +9 -5
  102. tests/views/test_register.pyc +0 -0
  103. tests/views/test_reset.py +9 -4
  104. tests/views/test_reset.pyc +0 -0
@@ -1,7 +1,7 @@
1
1
  """Unittest for social login view."""
2
2
  import pytest
3
3
  import mock
4
- from velruse import AuthenticationComplete
4
+ from pyramid.compat import text_type
5
5
 
6
6
  from pyramid_fullauth.views.social import SocialLoginViews
7
7
 
@@ -9,57 +9,59 @@ from pyramid_fullauth.views.social import SocialLoginViews
9
9
  @pytest.mark.parametrize('profile, email', [
10
10
  (
11
11
  {
12
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
13
- 'displayName': u'teddy',
14
- 'verifiedEmail': 'verified@email.co.uk',
15
- 'preferredUsername': u'teddy',
16
- 'emails': [{'value': u'aasd@bwwqwe.pl'}],
17
- 'name': u'ted'
12
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
13
+ 'displayName': text_type('teddy'),
14
+ 'verifiedEmail': text_type('verified@email.co.uk'),
15
+ 'preferredUsername': text_type('teddy'),
16
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
17
+ 'name': text_type('ted')
18
18
  },
19
19
  'verified@email.co.uk'
20
20
  ), (
21
21
  {
22
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
23
- 'displayName': u'teddy',
24
- 'preferredUsername': u'teddy',
25
- 'emails': [{'value': u'aasd@bwwqwe.pl'}],
26
- 'name': u'ted'
22
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
23
+ 'displayName': text_type('teddy'),
24
+ 'preferredUsername': text_type('teddy'),
25
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
26
+ 'name': text_type('ted')
27
27
  },
28
28
  'aasd@bwwqwe.pl'
29
29
  ), (
30
30
  {
31
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
32
- 'displayName': u'teddy',
33
- 'preferredUsername': u'teddy',
31
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
32
+ 'displayName': text_type('teddy'),
33
+ 'preferredUsername': text_type('teddy'),
34
34
  'emails': [{}],
35
- 'name': u'ted'
35
+ 'name': text_type('ted')
36
36
  },
37
37
  '2343@facebook.com'
38
38
  ), (
39
39
  {
40
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
41
- 'displayName': u'teddy',
42
- 'preferredUsername': u'teddy',
40
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
41
+ 'displayName': text_type('teddy'),
42
+ 'preferredUsername': text_type('teddy'),
43
43
  'emails': [],
44
- 'name': u'ted'
44
+ 'name': text_type('ted')
45
45
  },
46
46
  '2343@facebook.com'
47
47
  ), (
48
48
  {
49
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
50
- 'displayName': u'teddy',
51
- 'preferredUsername': u'teddy',
52
- 'name': u'ted'
49
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
50
+ 'displayName': text_type('teddy'),
51
+ 'preferredUsername': text_type('teddy'),
52
+ 'name': text_type('ted')
53
53
  },
54
54
  '2343@facebook.com'
55
55
  ),
56
56
  ])
57
57
  def test_email_from_context(profile, email):
58
58
  """Test email_from_context email getting method."""
59
+ from velruse import AuthenticationComplete
59
60
  context = AuthenticationComplete(
60
61
  profile,
61
62
  {'oauthAccessToken': '7897048593434'},
62
- u'facebook',
63
- u'facebook')
63
+ text_type('facebook'),
64
+ text_type('facebook')
65
+ )
64
66
  view = SocialLoginViews(mock.MagicMock())
65
67
  assert view._email_from_context(context) == email
Binary file
tests/unit/test_tools.pyc CHANGED
Binary file
Binary file
Binary file
Binary file
@@ -45,7 +45,7 @@ def test_password_empty(db_session, user):
45
45
 
46
46
 
47
47
  def test_set_reset(db_session, user):
48
- """User.set_reset - generates reset key for those who forgot their password. """
48
+ """User.set_reset - generates reset key for those who forgot their password."""
49
49
  user = db_session.merge(user)
50
50
  assert not user.reset_key
51
51
  user.set_reset()
Binary file
Binary file
@@ -5,7 +5,7 @@ from pyramid_fullauth.models import User
5
5
 
6
6
 
7
7
  def test_introduce_email():
8
- """user gets introduced by e-mail only."""
8
+ """User gets introduced by e-mail only."""
9
9
  user = User()
10
10
  user.email = text_type('test@test.pl')
11
11
  # To string should return concatenated email
@@ -13,7 +13,7 @@ def test_introduce_email():
13
13
 
14
14
 
15
15
  def test_introduce_username():
16
- """user gets introduced by username."""
16
+ """User gets introduced by username."""
17
17
  user = User()
18
18
  # 'User not saved should be represented by \'None\'')
19
19
  assert str(user) == 'None'
@@ -25,5 +25,5 @@ def test_introduce_username():
25
25
  user.username = text_type('testowy')
26
26
  # To string should return username
27
27
  assert str(user) == 'testowy'
28
- # User should be represented by "<User (\'1\', \'testowy\')>"
29
- assert user.__repr__() == "<User ('1', 'testowy')>"
28
+ # User should be represented by "<User (\'1\')>"
29
+ assert user.__repr__() == "<User ('1')>"
Binary file
@@ -41,4 +41,4 @@ def test_email_invalid_formats(db_session, user, invalid_email):
41
41
 
42
42
  with pytest.raises(EmailValidationError):
43
43
  user.email = invalid_email
44
- db_session.commit()
44
+ transaction.commit()
Binary file
tests/views/__init__.pyc CHANGED
Binary file
tests/views/conftest.py CHANGED
@@ -5,6 +5,11 @@ import transaction
5
5
  from pyramid_fullauth.models import AuthenticationProvider
6
6
 
7
7
 
8
+ def mock_translate(msg, *args, **kwargs):
9
+ """Mock translate function (simply returns message)."""
10
+ return msg
11
+
12
+
8
13
  @pytest.fixture
9
14
  def facebook_user(active_user, db_session):
10
15
  """Facebook user."""
tests/views/conftest.pyc CHANGED
Binary file
@@ -1,6 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Account activation related tests."""
3
- from urllib import quote
3
+ try:
4
+ from urllib import quote
5
+ # python3
6
+ except ImportError:
7
+ from urllib.parse import quote
4
8
 
5
9
  import transaction
6
10
 
@@ -31,7 +35,7 @@ def test_account_activation_wrong_key(user, db_session, default_app):
31
35
  res = default_app.get('/register/activate/' + activate_key[:-5], status=200)
32
36
  transaction.commit()
33
37
 
34
- assert 'Invalid activation code' in res.body
38
+ assert 'Invalid activation code' in res.body.decode('unicode_escape')
35
39
 
36
40
  user = db_session.query(User).filter(User.email == user.email).one()
37
41
  assert user.activate_key == activate_key
@@ -46,13 +50,16 @@ def test_account_activation_key_with_trash_chars(user, db_session, default_app):
46
50
  user = db_session.merge(user)
47
51
 
48
52
  activate_key = user.activate_key
49
- res = default_app.get('/register/activate/' + quote(
50
- u'ąśðłĸęł¶→łęóħó³→←śðđ[]}³½ĸżćŋðń→↓ŧ¶ħ→ĸł¼²³↓←ħ@ĸđśðĸ@ł¼ęłśħđó[³²½łðśđħ'.encode('utf-8')),
53
+ res = default_app.get(
54
+ '/register/activate/' + quote(
55
+ # ąśðłĸęł¶→łęóħó³→←śðđ[]}³½ĸżćŋðń→↓ŧ¶ħ→ĸł¼²³↓←ħ@ĸđśðĸ@ł¼ęłśħđó[³²½łðśđħ - already decoded
56
+ '\xc4\x85\xc5\x9b\xc3\xb0\xc5\x82\xc4\xb8\xc4\x99\xc5\x82\xc2\xb6\xe2\x86\x92\xc5\x82\xc4\x99\xc3\xb3\xc4\xa7\xc3\xb3\xc2\xb3\xe2\x86\x92\xe2\x86\x90\xc5\x9b\xc3\xb0\xc4\x91[]}\xc2\xb3\xc2\xbd\xc4\xb8\xc5\xbc\xc4\x87\xc5\x8b\xc3\xb0\xc5\x84\xe2\x86\x92\xe2\x86\x93\xc5\xa7\xc2\xb6\xc4\xa7\xe2\x86\x92\xc4\xb8\xc5\x82\xc2\xbc\xc2\xb2\xc2\xb3\xe2\x86\x93\xe2\x86\x90\xc4\xa7@\xc4\xb8\xc4\x91\xc5\x9b\xc3\xb0\xc4\xb8@\xc5\x82\xc2\xbc\xc4\x99\xc5\x82\xc5\x9b\xc4\xa7\xc4\x91\xc3\xb3[\xc2\xb3\xc2\xb2\xc2\xbd\xc5\x82\xc3\xb0\xc5\x9b\xc4\x91\xc4\xa7' #noqa
57
+ ),
51
58
  status=200
52
59
  )
53
60
  transaction.commit()
54
61
 
55
- assert 'Invalid activation code' in res.body
62
+ assert 'Invalid activation code' in res.body.decode('unicode_escape')
56
63
  user = db_session.query(User).filter(User.email == user.email).one()
57
64
 
58
65
  assert user.activate_key == activate_key
@@ -76,4 +83,4 @@ def test_account_activation_twice(user, db_session, default_app):
76
83
  assert user.activated_at
77
84
 
78
85
  res = default_app.get('/register/activate/' + activate_key, status=200)
79
- assert 'Invalid activation code' in res.body
86
+ assert 'Invalid activation code' in res.body.decode('unicode_escape')
Binary file
tests/views/test_email.py CHANGED
@@ -140,7 +140,7 @@ def test_email_proceed(db_session, active_user, default_app):
140
140
  email = DEFAULT_USER['email']
141
141
  user = db_session.query(User).filter(User.email == email).one()
142
142
 
143
- new_email = u'email2@email.com'
143
+ new_email = text_type('email2@email.com')
144
144
  user.set_new_email(new_email)
145
145
  transaction.commit()
146
146
 
@@ -165,7 +165,7 @@ def test_email_proceed_wrong_key(db_session, active_user, default_app):
165
165
  email = DEFAULT_USER['email']
166
166
  user = db_session.query(User).filter(User.email == email).one()
167
167
 
168
- new_email = u'email2@email.com'
168
+ new_email = text_type('email2@email.com')
169
169
  user.set_new_email(new_email)
170
170
  transaction.commit()
171
171
 
Binary file
@@ -3,11 +3,12 @@ import pytest
3
3
  import transaction
4
4
  from mock import MagicMock
5
5
  from pyramid import testing
6
+ from pyramid.compat import text_type
6
7
  from pyramid.view import view_config
7
8
  from pyramid.httpexceptions import HTTPFound
8
- from velruse import AuthenticationComplete
9
9
  from sqlalchemy.orm.exc import NoResultFound
10
10
  from pytest_pyramid import factories
11
+ from velruse import AuthenticationComplete
11
12
 
12
13
 
13
14
  from pyramid_fullauth.models import User
@@ -21,11 +22,20 @@ from pyramid_fullauth.events import (
21
22
  BeforeRegister, AfterRegister
22
23
  )
23
24
  from tests.tools import authenticate, is_user_logged, DEFAULT_USER
25
+ from tests.views.conftest import mock_translate
24
26
 
25
27
  EVENT_PATH = '/event?event={0.__name__}'
26
28
  EVENT_URL = 'http://localhost' + EVENT_PATH
27
29
 
28
30
 
31
+ def unregister_subscriber(config, event):
32
+ """Unregister subscribers from given events."""
33
+ for key in config.registry.adapters._subscribers[1].keys():
34
+ if key.implementedBy(event):
35
+ del config.registry.adapters._subscribers[1][key]
36
+ break
37
+
38
+
29
39
  evented_config = factories.pyramid_config({
30
40
  'yml.location': 'tests:config',
31
41
  'env': 'login',
@@ -42,7 +52,6 @@ def include_views(config):
42
52
  """Dummy pyramid plugin including events."""
43
53
  config.add_route('event', '/event')
44
54
  config.scan('tests.views.test_events')
45
- # config.add_subscriber(raise_attribute_error, BeforeLogIn)
46
55
 
47
56
 
48
57
  @view_config(route_name="event", renderer='json')
@@ -69,7 +78,10 @@ def raise_attribute_error(event):
69
78
  def alreadyloggedin_config(evented_config):
70
79
  """Add AlreadyLoggedIn event subscriber that redirects to event page."""
71
80
  evented_config.add_subscriber(redirect_to_secret, AlreadyLoggedIn)
72
- return evented_config
81
+ evented_config.commit()
82
+ yield evented_config
83
+ unregister_subscriber(evented_config, AlreadyLoggedIn)
84
+
73
85
 
74
86
  alreadyloggedin_app = factories.pyramid_app('alreadyloggedin_config')
75
87
 
@@ -85,7 +97,10 @@ def test_default_login_redirect_from_event(active_user, alreadyloggedin_app):
85
97
  def beforelogin_config(evented_config):
86
98
  """Add BeforeLogIn event that raises AttributeError with event class name."""
87
99
  evented_config.add_subscriber(raise_attribute_error, BeforeLogIn)
88
- return evented_config
100
+ evented_config.commit()
101
+ yield evented_config
102
+ unregister_subscriber(evented_config, BeforeLogIn)
103
+
89
104
 
90
105
  beforelogin_app = factories.pyramid_app('beforelogin_config')
91
106
 
@@ -107,7 +122,10 @@ def test_error_beforelogin(active_user, beforelogin_app):
107
122
  def afterlogin_config(evented_config):
108
123
  """Add AfterLogIn event subscriber that redirects to event page."""
109
124
  evented_config.add_subscriber(redirect_to_secret, AfterLogIn)
110
- return evented_config
125
+ evented_config.commit()
126
+ yield evented_config
127
+ unregister_subscriber(evented_config, AfterLogIn)
128
+
111
129
 
112
130
  afterlogin_app = factories.pyramid_app('afterlogin_config')
113
131
 
@@ -126,7 +144,10 @@ def test_login_redirect(active_user, afterlogin_app):
126
144
  def afterloginerror_config(evented_config):
127
145
  """Add AfterLogIn event subscriber that raises AttributeError."""
128
146
  evented_config.add_subscriber(raise_attribute_error, AfterLogIn)
129
- return evented_config
147
+ evented_config.commit()
148
+ yield evented_config
149
+ unregister_subscriber(evented_config, AfterLogIn)
150
+
130
151
 
131
152
  afterloginerror_app = factories.pyramid_app('afterloginerror_config')
132
153
 
@@ -150,7 +171,10 @@ def test_error_afterlogin(active_user, afterloginerror_app):
150
171
  def beforeemailchange_config(evented_config):
151
172
  """Add BeforeEmailChange event subscriber that raises AttributeError."""
152
173
  evented_config.add_subscriber(raise_attribute_error, BeforeEmailChange)
153
- return evented_config
174
+ evented_config.commit()
175
+ yield evented_config
176
+ unregister_subscriber(evented_config, BeforeEmailChange)
177
+
154
178
 
155
179
  beforeemailchange_app = factories.pyramid_app('beforeemailchange_config')
156
180
 
@@ -178,7 +202,11 @@ def afteremailchange_config(evented_config):
178
202
  """Add AfterEmailChange, AfterEmailChangeActivation event subscriber that redirects to event page."""
179
203
  evented_config.add_subscriber(redirect_to_secret, AfterEmailChange)
180
204
  evented_config.add_subscriber(redirect_to_secret, AfterEmailChangeActivation)
181
- return evented_config
205
+ evented_config.commit()
206
+ yield evented_config
207
+ unregister_subscriber(evented_config, AfterEmailChange)
208
+ unregister_subscriber(evented_config, AfterEmailChangeActivation)
209
+
182
210
 
183
211
  afteremailchange_app = factories.pyramid_app('afteremailchange_config')
184
212
 
@@ -244,7 +272,7 @@ def test_afteremailchangeactivation(db_session, active_user, afteremailchange_ap
244
272
  email = DEFAULT_USER['email']
245
273
  user = db_session.query(User).filter(User.email == email).one()
246
274
 
247
- new_email = u'email2@email.com'
275
+ new_email = text_type('email2@email.com')
248
276
  user.set_new_email(new_email)
249
277
  transaction.commit()
250
278
 
@@ -266,7 +294,11 @@ def afterreset_config(evented_config):
266
294
  """Add AfterReset, AfterResetRequest event subscriber that redirects to event page."""
267
295
  evented_config.add_subscriber(redirect_to_secret, AfterResetRequest)
268
296
  evented_config.add_subscriber(redirect_to_secret, AfterReset)
269
- return evented_config
297
+ evented_config.commit()
298
+ yield evented_config
299
+ unregister_subscriber(evented_config, AfterResetRequest)
300
+ unregister_subscriber(evented_config, AfterReset)
301
+
270
302
 
271
303
  afterreset_app = factories.pyramid_app('afterreset_config')
272
304
 
@@ -310,7 +342,10 @@ def test_afterreset(user, db_session, afterreset_app):
310
342
  def beforereset_config(evented_config):
311
343
  """Add BeforeReset event subscriber that raises AttributeError."""
312
344
  evented_config.add_subscriber(raise_attribute_error, BeforeReset)
313
- return evented_config
345
+ evented_config.commit()
346
+ yield evented_config
347
+ unregister_subscriber(evented_config, BeforeReset)
348
+
314
349
 
315
350
  beforereset_app = factories.pyramid_app('beforereset_config')
316
351
 
@@ -327,14 +362,17 @@ def test_beforereset(user, db_session, beforereset_app):
327
362
  res.form['password'] = 'YouShallPass'
328
363
  res.form['confirm_password'] = 'YouShallPass'
329
364
  res = res.form.submit()
330
- assert 'Error! BeforeReset' in res.body
365
+ assert 'Error! BeforeReset' in res.body.decode('unicode_escape')
331
366
 
332
367
 
333
368
  @pytest.fixture
334
369
  def aftersocialregister_config(evented_config):
335
370
  """Add AfterSocialRegister event subscriber that redirects to event page."""
336
371
  evented_config.add_subscriber(redirect_to_secret, AfterSocialRegister)
337
- return evented_config
372
+ evented_config.commit()
373
+ yield evented_config
374
+ unregister_subscriber(evented_config, AfterSocialRegister)
375
+
338
376
 
339
377
  aftersocialregister_app = factories.pyramid_app('aftersocialregister_config')
340
378
 
@@ -342,20 +380,20 @@ aftersocialregister_app = factories.pyramid_app('aftersocialregister_config')
342
380
  def test_aftersocialregister(aftersocialregister_config, aftersocialregister_app, db_session):
343
381
  """Register fresh user and logs him in and check response if redirect from AfterSocialRegister."""
344
382
  profile = {
345
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
346
- 'displayName': u'teddy',
347
- 'verifiedEmail': u'we@po.pl',
348
- 'preferredUsername': u'teddy',
349
- 'emails': [{'value': u'aasd@bwwqwe.pl'}],
350
- 'name': u'ted'
383
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
384
+ 'displayName': text_type('teddy'),
385
+ 'verifiedEmail': text_type('we@po.pl'),
386
+ 'preferredUsername': text_type('teddy'),
387
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
388
+ 'name': text_type('ted')
351
389
  }
352
390
  credentials = {'oauthAccessToken': '7897048593434'}
353
- provider_name = u'facebook'
354
- provider_type = u'facebook'
391
+ provider_name = text_type('facebook')
392
+ provider_type = text_type('facebook')
355
393
  request = testing.DummyRequest()
356
394
  request.user = None
357
395
  request.registry = aftersocialregister_config.registry
358
- request.remote_addr = u'127.0.0.123'
396
+ request.remote_addr = text_type('127.0.0.123')
359
397
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
360
398
 
361
399
  request.login_perform = MagicMock(name='login_perform')
@@ -375,7 +413,10 @@ def test_aftersocialregister(aftersocialregister_config, aftersocialregister_app
375
413
  def aftersociallogin_config(evented_config):
376
414
  """Add AfterSocialLogIn event subscriber that redirects to event page."""
377
415
  evented_config.add_subscriber(redirect_to_secret, AfterSocialLogIn)
378
- return evented_config
416
+ evented_config.commit()
417
+ yield evented_config
418
+ unregister_subscriber(evented_config, AfterSocialLogIn)
419
+
379
420
 
380
421
  aftersociallogin_app = factories.pyramid_app('aftersociallogin_config')
381
422
 
@@ -383,20 +424,20 @@ aftersociallogin_app = factories.pyramid_app('aftersociallogin_config')
383
424
  def test_aftersociallogin(aftersociallogin_config, aftersociallogin_app, db_session):
384
425
  """Register fresh user and logs him in and check response if redirect from AfterSocialLogIn."""
385
426
  profile = {
386
- 'accounts': [{'domain': u'facebook.com', 'userid': u'2343'}],
387
- 'displayName': u'teddy',
388
- 'verifiedEmail': u'we@po.pl',
389
- 'preferredUsername': u'teddy',
390
- 'emails': [{'value': u'aasd@bwwqwe.pl'}],
391
- 'name': u'ted'
427
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
428
+ 'displayName': text_type('teddy'),
429
+ 'verifiedEmail': text_type('we@po.pl'),
430
+ 'preferredUsername': text_type('teddy'),
431
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
432
+ 'name': text_type('ted')
392
433
  }
393
434
  credentials = {'oauthAccessToken': '7897048593434'}
394
- provider_name = u'facebook'
395
- provider_type = u'facebook'
435
+ provider_name = text_type('facebook')
436
+ provider_type = text_type('facebook')
396
437
  request = testing.DummyRequest()
397
438
  request.user = None
398
439
  request.registry = aftersociallogin_config.registry
399
- request.remote_addr = u'127.0.0.123'
440
+ request.remote_addr = text_type('127.0.0.123')
400
441
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
401
442
 
402
443
  def login_perform(*args, **kwargs):
@@ -417,18 +458,26 @@ def test_aftersociallogin(aftersociallogin_config, aftersociallogin_app, db_sess
417
458
  def alreadyconnected_config(evented_config):
418
459
  """Add SocialAccountAlreadyConnected event subscriber that redirects to event page."""
419
460
  evented_config.add_subscriber(redirect_to_secret, SocialAccountAlreadyConnected)
420
- return evented_config
461
+ evented_config.commit()
462
+ yield evented_config
463
+ unregister_subscriber(evented_config, SocialAccountAlreadyConnected)
464
+
421
465
 
422
466
  alreadyconnected_app = factories.pyramid_app('alreadyconnected_config')
423
467
 
424
468
 
425
469
  def test_alreadyconnected(alreadyconnected_config, alreadyconnected_app, facebook_user, db_session):
426
- """Try to connect facebook account to logged in user used by other user check redirect from SocialAccountAlreadyConnected."""
470
+ """
471
+ Try to connect facebook account to logged in user used by other users facebook account.
472
+
473
+ Check redirect from SocialAccountAlreadyConnected.
474
+ """
427
475
  # this user will be logged and trying to connect facebook's user account.
428
476
  fresh_user = User(
429
- email='new@user.pl',
430
- password='somepassword',
431
- address_ip='127.0.0.1')
477
+ email=text_type('new@user.pl'),
478
+ password=text_type('somepassword'),
479
+ address_ip=text_type('127.0.0.1')
480
+ )
432
481
  db_session.add(fresh_user)
433
482
  transaction.commit()
434
483
  user = db_session.merge(facebook_user)
@@ -436,21 +485,21 @@ def test_alreadyconnected(alreadyconnected_config, alreadyconnected_app, faceboo
436
485
 
437
486
  # mock request
438
487
  profile = {
439
- 'accounts': [{'domain': u'facebook.com', 'userid': user.provider_id('facebook')}],
440
- 'displayName': u'teddy',
441
- 'preferredUsername': u'teddy',
442
- 'emails': [{'value': u'aasd@basd.pl'}],
443
- 'name': u'ted'
488
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': user.provider_id('facebook')}],
489
+ 'displayName': text_type('teddy'),
490
+ 'preferredUsername': text_type('teddy'),
491
+ 'emails': [{'value': text_type('aasd@basd.pl')}],
492
+ 'name': text_type('ted')
444
493
  }
445
494
  credentials = {'oauthAccessToken': '7897048593434'}
446
- provider_name = u'facebook'
447
- provider_type = u'facebook'
495
+ provider_name = text_type('facebook')
496
+ provider_type = text_type('facebook')
448
497
  request = testing.DummyRequest()
449
498
  request.user = fresh_user
450
499
  request.registry = alreadyconnected_config.registry
451
- request.remote_addr = u'127.0.0.123'
500
+ request.remote_addr = text_type('127.0.0.123')
452
501
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
453
- request._ = lambda msg, *args, **kwargs: msg
502
+ request._ = mock_translate
454
503
 
455
504
  request.login_perform = MagicMock(name='login_perform')
456
505
  request.login_perform.return_value = {'status': True}
@@ -467,7 +516,10 @@ def test_alreadyconnected(alreadyconnected_config, alreadyconnected_app, faceboo
467
516
  def afteractivate_config(evented_config):
468
517
  """Add AfterActivate event subscriber that redirects to event page."""
469
518
  evented_config.add_subscriber(redirect_to_secret, AfterActivate)
470
- return evented_config
519
+ evented_config.commit()
520
+ yield evented_config
521
+ unregister_subscriber(evented_config, AfterActivate)
522
+
471
523
 
472
524
  afteractivate_app = factories.pyramid_app('afteractivate_config')
473
525
 
@@ -493,7 +545,10 @@ def test_afteractivate(user, db_session, afteractivate_app):
493
545
  def beforeregister_config(evented_config):
494
546
  """Add BeforeRegister event subscriber that raises AttributeError."""
495
547
  evented_config.add_subscriber(raise_attribute_error, BeforeRegister)
496
- return evented_config
548
+ evented_config.commit()
549
+ yield evented_config
550
+ unregister_subscriber(evented_config, BeforeRegister)
551
+
497
552
 
498
553
  beforeregister_app = factories.pyramid_app('beforeregister_config')
499
554
 
@@ -520,7 +575,10 @@ def test_beforeregister(db_session, beforeregister_app):
520
575
  def afterregister_config(evented_config):
521
576
  """Add AfterRegister event subscriber that redirects to event page."""
522
577
  evented_config.add_subscriber(redirect_to_secret, AfterRegister)
523
- return evented_config
578
+ evented_config.commit()
579
+ yield evented_config
580
+ unregister_subscriber(evented_config, AfterRegister)
581
+
524
582
 
525
583
  afteraregister_app = factories.pyramid_app('afterregister_config')
526
584
 
Binary file
tests/views/test_login.py CHANGED
@@ -1,5 +1,7 @@
1
1
  """Log in related test."""
2
2
  import pytest
3
+ import transaction
4
+
3
5
  from tests.tools import authenticate, is_user_logged, DEFAULT_USER
4
6
 
5
7
 
@@ -23,7 +25,11 @@ def test_login_view_secret(extended_app):
23
25
  assert 'email' in res.form.fields
24
26
 
25
27
 
26
- def test_login(active_user, extended_app):
28
+ @pytest.mark.parametrize('email', (
29
+ DEFAULT_USER['email'].lower(),
30
+ DEFAULT_USER['email'].upper()
31
+ ))
32
+ def test_login_ok(active_user, extended_app, email):
27
33
  """Actually log in test."""
28
34
  res = extended_app.get('/secret', status=302)
29
35
  res = res.follow()
@@ -31,7 +37,7 @@ def test_login(active_user, extended_app):
31
37
 
32
38
  assert is_user_logged(extended_app) is False
33
39
 
34
- res = authenticate(extended_app)
40
+ res = authenticate(extended_app, email=email)
35
41
  assert 'Max-Age=' not in str(res)
36
42
 
37
43
  assert is_user_logged(extended_app) is True
@@ -149,3 +155,18 @@ def test_default_login_redirectaway(active_user, authable_app):
149
155
  authenticate(authable_app)
150
156
  res = authable_app.get('/login', status=303)
151
157
  assert res.location == 'http://localhost/'
158
+
159
+
160
+ def test_login_invalid_cookie(db_session, active_user, extended_app):
161
+ """Test access login page by deleted user."""
162
+ res = authenticate(extended_app)
163
+ assert 'Max-Age=' not in str(res)
164
+
165
+ assert is_user_logged(extended_app) is True
166
+
167
+ db_session.delete(active_user)
168
+ transaction.commit()
169
+
170
+ # will rise Attribute error
171
+ res = extended_app.get('/login')
172
+ assert res.status_code == 200, "Should stay since user is no longer valid!"
Binary file