def __init__(self, request): self.request = request if request.feature('activity_pages'): email_schema = schemas.EmailChangeSchema().bind(request=request) else: email_schema = schemas.LegacyEmailChangeSchema().bind( request=request) password_schema = schemas.PasswordChangeSchema().bind(request=request) # Ensure deform generates unique field IDs for each field in this # multiple-form page. counter = itertools.count() self.forms = { 'email': request.create_form(email_schema, buttons=(_('Change email address'), ), formid='email', counter=counter), 'password': request.create_form(password_schema, buttons=(_('Change password'), ), formid='password', counter=counter), }
def test_it_is_invalid_if_emails_dont_match(self, pyramid_csrf_request, user_model): user = Mock() pyramid_csrf_request.authenticated_user = user schema = schemas.LegacyEmailChangeSchema().bind( request=pyramid_csrf_request) # The email isn't taken user_model.get_by_email.return_value = None with pytest.raises(colander.Invalid) as exc: schema.deserialize({'email': '*****@*****.**', 'email_confirm': '*****@*****.**', 'password': '******'}) assert 'email_confirm' in exc.value.asdict()
def __init__(self, request): self.request = request if request.feature('activity_pages'): email_schema = schemas.EmailChangeSchema().bind(request=request) else: email_schema = schemas.LegacyEmailChangeSchema().bind(request=request) password_schema = schemas.PasswordChangeSchema().bind(request=request) self.forms = { 'email': request.create_form(email_schema, buttons=(_('Change email address'),), formid='email'), 'password': request.create_form(password_schema, buttons=(_('Change password'),), formid='password'), }
def test_it_is_invalid_if_password_wrong(self, pyramid_csrf_request, user_model): user = Mock() pyramid_csrf_request.authenticated_user = user schema = schemas.LegacyEmailChangeSchema().bind( request=pyramid_csrf_request) # The email isn't taken user_model.get_by_email.return_value = None # The password does not check out user.check_password.return_value = False with pytest.raises(colander.Invalid) as exc: schema.deserialize({'email': '*****@*****.**', 'email_confirm': '*****@*****.**', 'password': '******'}) user.check_password.assert_called_once_with('flibble') assert 'password' in exc.value.asdict()