pyramid-fullauth 0.3.2__py2.7.egg → 0.5.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 (82) hide show
  1. EGG-INFO/PKG-INFO +41 -10
  2. EGG-INFO/SOURCES.txt +2 -0
  3. EGG-INFO/requires.txt +4 -6
  4. pyramid_fullauth/__init__.py +3 -3
  5. pyramid_fullauth/__init__.pyc +0 -0
  6. pyramid_fullauth/auth.py +2 -1
  7. pyramid_fullauth/auth.pyc +0 -0
  8. pyramid_fullauth/compat.py +18 -0
  9. pyramid_fullauth/compat.pyc +0 -0
  10. pyramid_fullauth/events.py +0 -1
  11. pyramid_fullauth/events.pyc +0 -0
  12. pyramid_fullauth/exceptions.pyc +0 -0
  13. pyramid_fullauth/models/__init__.py +5 -4
  14. pyramid_fullauth/models/__init__.pyc +0 -0
  15. pyramid_fullauth/models/extensions/__init__.py +39 -0
  16. pyramid_fullauth/models/extensions/__init__.pyc +0 -0
  17. pyramid_fullauth/models/mixins/__init__.pyc +0 -0
  18. pyramid_fullauth/models/mixins/email.py +53 -6
  19. pyramid_fullauth/models/mixins/email.pyc +0 -0
  20. pyramid_fullauth/models/mixins/password.pyc +0 -0
  21. pyramid_fullauth/request.py +5 -4
  22. pyramid_fullauth/request.pyc +0 -0
  23. pyramid_fullauth/resources/helpers/social.mako +3 -3
  24. pyramid_fullauth/resources/locale/pyramid_fullauth.pot +23 -23
  25. pyramid_fullauth/routing/__init__.pyc +0 -0
  26. pyramid_fullauth/routing/predicates.pyc +0 -0
  27. pyramid_fullauth/tools.py +6 -3
  28. pyramid_fullauth/tools.pyc +0 -0
  29. pyramid_fullauth/views/__init__.pyc +0 -0
  30. pyramid_fullauth/views/basic/__init__.pyc +0 -0
  31. pyramid_fullauth/views/basic/activate.pyc +0 -0
  32. pyramid_fullauth/views/basic/forbidden.py +2 -3
  33. pyramid_fullauth/views/basic/forbidden.pyc +0 -0
  34. pyramid_fullauth/views/basic/login.py +7 -7
  35. pyramid_fullauth/views/basic/login.pyc +0 -0
  36. pyramid_fullauth/views/basic/logout.pyc +0 -0
  37. pyramid_fullauth/views/basic/profile/__init__.pyc +0 -0
  38. pyramid_fullauth/views/basic/profile/email.py +2 -1
  39. pyramid_fullauth/views/basic/profile/email.pyc +0 -0
  40. pyramid_fullauth/views/basic/profile/password.py +5 -4
  41. pyramid_fullauth/views/basic/profile/password.pyc +0 -0
  42. pyramid_fullauth/views/basic/register.py +7 -6
  43. pyramid_fullauth/views/basic/register.pyc +0 -0
  44. pyramid_fullauth/views/social.py +6 -3
  45. pyramid_fullauth/views/social.pyc +0 -0
  46. tests/__init__.pyc +0 -0
  47. tests/conftest.py +2 -1
  48. tests/conftest.pyc +0 -0
  49. tests/tools.pyc +0 -0
  50. tests/unit/test_default_settings.pyc +0 -0
  51. tests/unit/test_groupfinder.pyc +0 -0
  52. tests/unit/test_social_view.py +28 -26
  53. tests/unit/test_social_view.pyc +0 -0
  54. tests/unit/test_tools.pyc +0 -0
  55. tests/unit/test_user_active.pyc +0 -0
  56. tests/unit/test_user_admin.pyc +0 -0
  57. tests/unit/test_user_email.pyc +0 -0
  58. tests/unit/test_user_password.py +1 -1
  59. tests/unit/test_user_password.pyc +0 -0
  60. tests/unit/test_user_providers.pyc +0 -0
  61. tests/unit/test_user_repr.py +2 -2
  62. tests/unit/test_user_repr.pyc +0 -0
  63. tests/unit/test_validators.py +1 -1
  64. tests/unit/test_validators.pyc +0 -0
  65. tests/views/__init__.pyc +0 -0
  66. tests/views/conftest.py +5 -0
  67. tests/views/conftest.pyc +0 -0
  68. tests/views/test_activation.py +13 -6
  69. tests/views/test_activation.pyc +0 -0
  70. tests/views/test_email.py +2 -2
  71. tests/views/test_email.pyc +0 -0
  72. tests/views/test_events.py +36 -33
  73. tests/views/test_events.pyc +0 -0
  74. tests/views/test_login.py +23 -2
  75. tests/views/test_login.pyc +0 -0
  76. tests/views/test_login_social.py +97 -69
  77. tests/views/test_login_social.pyc +0 -0
  78. tests/views/test_logout.pyc +0 -0
  79. tests/views/test_register.py +9 -5
  80. tests/views/test_register.pyc +0 -0
  81. tests/views/test_reset.py +9 -4
  82. tests/views/test_reset.pyc +0 -0
@@ -7,10 +7,10 @@
7
7
  from pyramid.view import view_config
8
8
  from pyramid.view import view_defaults
9
9
  from pyramid.httpexceptions import HTTPSeeOther, HTTPRedirection
10
- from pyramid.security import authenticated_userid
11
10
  from pyramid.security import NO_PERMISSION_REQUIRED
12
11
 
13
12
  from sqlalchemy.orm.exc import NoResultFound
13
+ from pyramid.compat import text_type
14
14
  import pyramid_basemodel
15
15
 
16
16
  from pyramid_fullauth.views import BaseView
@@ -43,8 +43,8 @@ class BaseLoginView(BaseView):
43
43
  redirect = HTTPSeeOther(location=self.response['after'])
44
44
  try:
45
45
  self.request.registry.notify(AlreadyLoggedIn(self.request))
46
- except HTTPRedirection as redirect:
47
- pass
46
+ except HTTPRedirection as e_redirect:
47
+ redirect = e_redirect
48
48
 
49
49
  if self.request.is_xhr:
50
50
  self.response['status'] = True
@@ -64,7 +64,7 @@ class LoginView(BaseLoginView):
64
64
 
65
65
  def __call__(self):
66
66
  """Display login page."""
67
- if authenticated_userid(self.request):
67
+ if self.request.authenticated_userid:
68
68
  return self._redirect_authenticated_user()
69
69
 
70
70
  self.request.registry.notify(BeforeLogIn(self.request, None))
@@ -82,7 +82,7 @@ class LoginViewPost(BaseLoginView):
82
82
 
83
83
  def __call__(self):
84
84
  """Login action."""
85
- if authenticated_userid(self.request):
85
+ if self.request.authenticated_userid:
86
86
  return self._redirect_authenticated_user()
87
87
 
88
88
  email = self.request.POST.get('email', '')
@@ -99,7 +99,7 @@ class LoginViewPost(BaseLoginView):
99
99
  try:
100
100
  self.request.registry.notify(BeforeLogIn(self.request, user))
101
101
  except AttributeError as e:
102
- self.response['msg'] = str(e)
102
+ self.response['msg'] = text_type(e)
103
103
  return self.response
104
104
 
105
105
  if user.check_password(password):
@@ -109,7 +109,7 @@ class LoginViewPost(BaseLoginView):
109
109
  # if remember in POST set cookie timeout to one month
110
110
  self.request.registry.notify(AfterLogIn(self.request, user))
111
111
  except AttributeError as e:
112
- self.response['msg'] = str(e)
112
+ self.response['msg'] = text_type(e)
113
113
  return self.response
114
114
  except HTTPRedirection as redirect:
115
115
  login_kwargs['location'] = redirect.location
Binary file
Binary file
@@ -9,6 +9,7 @@ from pyramid.httpexceptions import HTTPRedirection, HTTPSeeOther
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
11
  from sqlalchemy.orm.exc import NoResultFound
12
+ from pyramid.compat import text_type
12
13
  import pyramid_basemodel
13
14
 
14
15
  from pyramid_fullauth.views import BaseView
@@ -51,7 +52,7 @@ class EmailChangeViews(BaseView):
51
52
  try:
52
53
  self.request.registry.notify(BeforeEmailChange(self.request, user))
53
54
  except AttributeError as e:
54
- return {'status': False, 'msg': e.message, 'csrf_token': csrf_token}
55
+ return {'status': False, 'msg': text_type(e), 'csrf_token': csrf_token}
55
56
 
56
57
  try:
57
58
  user.set_new_email(self.request.POST.get('email', ''))
@@ -9,6 +9,7 @@ from pyramid.httpexceptions import HTTPRedirection, HTTPSeeOther
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
11
  from sqlalchemy.orm.exc import NoResultFound
12
+ from pyramid.compat import text_type
12
13
  import pyramid_basemodel
13
14
 
14
15
  from pyramid_fullauth.views import BaseView
@@ -45,7 +46,7 @@ class PasswordResetView(BaseView):
45
46
  except NoResultFound:
46
47
  return {'status': False,
47
48
  'msg': self.request._('user-not-exists',
48
- default='User does not exists',
49
+ default='User does not exist',
49
50
  domain='pyramid_fullauth'),
50
51
  'csrf_token': csrf_token}
51
52
 
@@ -94,12 +95,12 @@ class PasswordResetContinueView(BaseView):
94
95
  try:
95
96
  pyramid_basemodel.Session.query(AuthenticationProvider).filter(
96
97
  AuthenticationProvider.user_id == user.id,
97
- AuthenticationProvider.provider == u'email'
98
+ AuthenticationProvider.provider == text_type('email')
98
99
  ).one()
99
100
  except NoResultFound:
100
101
  user.providers.append(
101
102
  AuthenticationProvider(
102
- provider=u'email',
103
+ provider=text_type('email'),
103
104
  provider_id=user.id
104
105
  )
105
106
  )
@@ -108,7 +109,7 @@ class PasswordResetContinueView(BaseView):
108
109
  except (ValidateError, AttributeError) as e:
109
110
  return {
110
111
  'status': False,
111
- 'msg': str(e),
112
+ 'msg': text_type(e),
112
113
  'csrf_token': self.request.session.get_csrf_token()
113
114
  }
114
115
 
@@ -8,6 +8,7 @@ from pyramid.view import view_config, view_defaults
8
8
  from pyramid.httpexceptions import HTTPRedirection
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
+ from pyramid.compat import text_type
11
12
  import pyramid_basemodel
12
13
 
13
14
  from pyramid_fullauth.views import BaseView
@@ -68,7 +69,7 @@ class RegisterView(BaseView):
68
69
  :returns: response
69
70
  :rtype: dict
70
71
  """
71
- email = self.request.POST.get('email', u'')
72
+ email = self.request.POST.get('email', text_type(''))
72
73
  # here if e-mail is already in database
73
74
 
74
75
  if pyramid_basemodel.Session.query(User).filter(User.email == email).count() != 0:
@@ -81,15 +82,15 @@ class RegisterView(BaseView):
81
82
  except ValidateError as e:
82
83
  # do not overwrite existing error
83
84
  if 'email' not in response['errors']:
84
- response['errors']['email'] = str(e)
85
+ response['errors']['email'] = text_type(e)
85
86
 
86
87
  if self.config.register.password.require:
87
88
  try:
88
89
  tools.validate_passsword(self.request,
89
- self.request.POST.get('password', u''),
90
+ self.request.POST.get('password', text_type('')),
90
91
  user)
91
92
  except ValidateError as e:
92
- response['errors']['password'] = e.message
93
+ response['errors']['password'] = text_type(e)
93
94
  else:
94
95
  user.password = tools.password_generator(
95
96
  self.config.register.password.length_min)
@@ -101,10 +102,10 @@ class RegisterView(BaseView):
101
102
 
102
103
  # lets add AuthenticationProvider as email!
103
104
  user.providers.append(
104
- AuthenticationProvider(provider=u'email', provider_id=user.id))
105
+ AuthenticationProvider(provider=text_type('email'), provider_id=user.id))
105
106
  else:
106
107
  return response
107
108
  except AttributeError as e:
108
- response['errors']['msg'] = str(e)
109
+ response['errors']['msg'] = text_type(e)
109
110
 
110
111
  return response
Binary file
@@ -11,6 +11,7 @@ from pyramid.security import NO_PERMISSION_REQUIRED
11
11
 
12
12
  from sqlalchemy.orm.exc import NoResultFound
13
13
  from sqlalchemy.exc import IntegrityError
14
+ from pyramid.compat import text_type
14
15
  import pyramid_basemodel
15
16
 
16
17
  from pyramid_fullauth.views import BaseView
@@ -212,7 +213,9 @@ class SocialLoginViews(BaseView):
212
213
  return context.profile['emails'][0]['value']
213
214
  # generating some random email address based on social userid and provider domain
214
215
  else:
215
- return u'{0}@{1}'.format(
216
- context.profile['accounts'][0]['userid'],
217
- context.profile['accounts'][0]['domain']
216
+ return text_type(
217
+ '{0}@{1}'.format(
218
+ context.profile['accounts'][0]['userid'],
219
+ context.profile['accounts'][0]['domain']
220
+ )
218
221
  )
Binary file
tests/__init__.pyc CHANGED
Binary file
tests/conftest.py CHANGED
@@ -51,7 +51,8 @@ def db_session(request):
51
51
 
52
52
  engine = create_engine(connection, echo=False, poolclass=NullPool)
53
53
  pyramid_basemodel.Session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
54
- pyramid_basemodel.bind_engine(engine, pyramid_basemodel.Session, should_drop=True)
54
+ pyramid_basemodel.bind_engine(
55
+ engine, pyramid_basemodel.Session, should_create=True, should_drop=True)
55
56
 
56
57
  def destroy():
57
58
  transaction.commit()
tests/conftest.pyc CHANGED
Binary file
tests/tools.pyc CHANGED
Binary file
Binary file
Binary file
@@ -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
@@ -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'
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,6 +22,7 @@ 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
@@ -244,7 +246,7 @@ def test_afteremailchangeactivation(db_session, active_user, afteremailchange_ap
244
246
  email = DEFAULT_USER['email']
245
247
  user = db_session.query(User).filter(User.email == email).one()
246
248
 
247
- new_email = u'email2@email.com'
249
+ new_email = text_type('email2@email.com')
248
250
  user.set_new_email(new_email)
249
251
  transaction.commit()
250
252
 
@@ -327,7 +329,7 @@ def test_beforereset(user, db_session, beforereset_app):
327
329
  res.form['password'] = 'YouShallPass'
328
330
  res.form['confirm_password'] = 'YouShallPass'
329
331
  res = res.form.submit()
330
- assert 'Error! BeforeReset' in res.body
332
+ assert 'Error! BeforeReset' in res.body.decode('unicode_escape')
331
333
 
332
334
 
333
335
  @pytest.fixture
@@ -342,20 +344,20 @@ aftersocialregister_app = factories.pyramid_app('aftersocialregister_config')
342
344
  def test_aftersocialregister(aftersocialregister_config, aftersocialregister_app, db_session):
343
345
  """Register fresh user and logs him in and check response if redirect from AfterSocialRegister."""
344
346
  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'
347
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
348
+ 'displayName': text_type('teddy'),
349
+ 'verifiedEmail': text_type('we@po.pl'),
350
+ 'preferredUsername': text_type('teddy'),
351
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
352
+ 'name': text_type('ted')
351
353
  }
352
354
  credentials = {'oauthAccessToken': '7897048593434'}
353
- provider_name = u'facebook'
354
- provider_type = u'facebook'
355
+ provider_name = text_type('facebook')
356
+ provider_type = text_type('facebook')
355
357
  request = testing.DummyRequest()
356
358
  request.user = None
357
359
  request.registry = aftersocialregister_config.registry
358
- request.remote_addr = u'127.0.0.123'
360
+ request.remote_addr = text_type('127.0.0.123')
359
361
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
360
362
 
361
363
  request.login_perform = MagicMock(name='login_perform')
@@ -383,20 +385,20 @@ aftersociallogin_app = factories.pyramid_app('aftersociallogin_config')
383
385
  def test_aftersociallogin(aftersociallogin_config, aftersociallogin_app, db_session):
384
386
  """Register fresh user and logs him in and check response if redirect from AfterSocialLogIn."""
385
387
  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'
388
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': text_type('2343')}],
389
+ 'displayName': text_type('teddy'),
390
+ 'verifiedEmail': text_type('we@po.pl'),
391
+ 'preferredUsername': text_type('teddy'),
392
+ 'emails': [{'value': text_type('aasd@bwwqwe.pl')}],
393
+ 'name': text_type('ted')
392
394
  }
393
395
  credentials = {'oauthAccessToken': '7897048593434'}
394
- provider_name = u'facebook'
395
- provider_type = u'facebook'
396
+ provider_name = text_type('facebook')
397
+ provider_type = text_type('facebook')
396
398
  request = testing.DummyRequest()
397
399
  request.user = None
398
400
  request.registry = aftersociallogin_config.registry
399
- request.remote_addr = u'127.0.0.123'
401
+ request.remote_addr = text_type('127.0.0.123')
400
402
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
401
403
 
402
404
  def login_perform(*args, **kwargs):
@@ -426,9 +428,10 @@ def test_alreadyconnected(alreadyconnected_config, alreadyconnected_app, faceboo
426
428
  """Try to connect facebook account to logged in user used by other user check redirect from SocialAccountAlreadyConnected."""
427
429
  # this user will be logged and trying to connect facebook's user account.
428
430
  fresh_user = User(
429
- email='new@user.pl',
430
- password='somepassword',
431
- address_ip='127.0.0.1')
431
+ email=text_type('new@user.pl'),
432
+ password=text_type('somepassword'),
433
+ address_ip=text_type('127.0.0.1')
434
+ )
432
435
  db_session.add(fresh_user)
433
436
  transaction.commit()
434
437
  user = db_session.merge(facebook_user)
@@ -436,21 +439,21 @@ def test_alreadyconnected(alreadyconnected_config, alreadyconnected_app, faceboo
436
439
 
437
440
  # mock request
438
441
  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'
442
+ 'accounts': [{'domain': text_type('facebook.com'), 'userid': user.provider_id('facebook')}],
443
+ 'displayName': text_type('teddy'),
444
+ 'preferredUsername': text_type('teddy'),
445
+ 'emails': [{'value': text_type('aasd@basd.pl')}],
446
+ 'name': text_type('ted')
444
447
  }
445
448
  credentials = {'oauthAccessToken': '7897048593434'}
446
- provider_name = u'facebook'
447
- provider_type = u'facebook'
449
+ provider_name = text_type('facebook')
450
+ provider_type = text_type('facebook')
448
451
  request = testing.DummyRequest()
449
452
  request.user = fresh_user
450
453
  request.registry = alreadyconnected_config.registry
451
- request.remote_addr = u'127.0.0.123'
454
+ request.remote_addr = text_type('127.0.0.123')
452
455
  request.context = AuthenticationComplete(profile, credentials, provider_name, provider_type)
453
- request._ = lambda msg, *args, **kwargs: msg
456
+ request._ = mock_translate
454
457
 
455
458
  request.login_perform = MagicMock(name='login_perform')
456
459
  request.login_perform.return_value = {'status': True}
Binary file