def test_invalid_with_bad_csrf(self, pyramid_request, user_service): schema = LoginSchema().bind(request=pyramid_request) with pytest.raises(BadCSRFToken): schema.deserialize({ 'username': '******', 'password': '******', })
def test_it_returns_user_when_valid( self, factories, pyramid_csrf_request, user_service ): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) result = schema.deserialize({"username": "******", "password": "******"}) assert result["user"] is user
def test_invalid_with_unknown_user(self, pyramid_csrf_request, user_service): schema = LoginSchema().bind(request=pyramid_csrf_request) user_service.fetch_for_login.return_value = None with pytest.raises(colander.Invalid) as exc: schema.deserialize({"username": "******", "password": "******"}) errors = exc.value.asdict() assert "username" in errors assert "does not exist" in errors["username"]
def test_invalid_with_inactive_user(self, pyramid_csrf_request, user_service): schema = LoginSchema().bind(request=pyramid_csrf_request) user_service.fetch_for_login.side_effect = UserNotActivated() with pytest.raises(colander.Invalid) as exc: schema.deserialize({"username": "******", "password": "******"}) errors = exc.value.asdict() assert "username" in errors assert "activate your account" in errors["username"]
def test_passes_password_to_user_password_service( self, factories, pyramid_csrf_request, user_service, user_password_service ): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) schema.deserialize({"username": "******", "password": "******"}) user_password_service.check_password.assert_called_once_with(user, "cake")
def test_passes_username_to_user_service(self, factories, pyramid_csrf_request, user_service): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) schema.deserialize({"username": "******", "password": "******"}) user_service.fetch_for_login.assert_called_once_with( username_or_email="jeannie")
def test_it_returns_user_when_valid(self, factories, pyramid_csrf_request, user_service): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) result = schema.deserialize({ "username": "******", "password": "******" }) assert result["user"] is user
def test_it_returns_user_when_valid(self, factories, pyramid_csrf_request, user_service): user = factories.User.build(username='******') user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) result = schema.deserialize({ 'username': '******', 'password': '******', }) assert result['user'] is user
def test_invalid_with_bad_password(self, factories, pyramid_csrf_request, user_service, user_password_service): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user user_password_service.check_password.return_value = False schema = LoginSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({"username": "******", "password": "******"}) errors = exc.value.asdict() assert "password" in errors assert "Wrong password" in errors["password"]
def test_invalid_with_unknown_user(self, pyramid_csrf_request, user_service): schema = LoginSchema().bind(request=pyramid_csrf_request) user_service.fetch_for_login.return_value = None with pytest.raises(colander.Invalid) as exc: schema.deserialize({ 'username': '******', 'password': '******', }) errors = exc.value.asdict() assert 'username' in errors assert 'does not exist' in errors['username']
def test_invalid_with_inactive_user(self, pyramid_csrf_request, user_service): schema = LoginSchema().bind(request=pyramid_csrf_request) user_service.fetch_for_login.side_effect = UserNotActivated() with pytest.raises(colander.Invalid) as exc: schema.deserialize({ 'username': '******', 'password': '******', }) errors = exc.value.asdict() assert 'username' in errors assert 'activate your account' in errors['username']
def test_invalid_with_bad_password( self, factories, pyramid_csrf_request, user_service, user_password_service ): user = factories.User.build(username="******") user_service.fetch_for_login.return_value = user user_password_service.check_password.return_value = False schema = LoginSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({"username": "******", "password": "******"}) errors = exc.value.asdict() assert "password" in errors assert "Wrong password" in errors["password"]
def test_passes_password_to_user_password_service(self, factories, pyramid_csrf_request, user_service, user_password_service): user = factories.User.build(username='******') user_service.fetch_for_login.return_value = user schema = LoginSchema().bind(request=pyramid_csrf_request) schema.deserialize({ 'username': '******', 'password': '******', }) user_password_service.check_password.assert_called_once_with( user, 'cake')
def get(self): """Render the login page, including the login form.""" self._redirect_if_logged_in() return { "form": self.form.render(LoginSchema.default_values(self.request)) }
def __init__(self, request): form_footer = '<a class="link" href="{href}">{text}</a>'.format( href=request.route_path('forgot_password'), text=_('Forgot your password?')) self.request = request self.schema = LoginSchema().bind(request=self.request) show_cancel_button = bool(request.params.get('for_oauth', False)) self.form = request.create_form(self.schema, buttons=(_('Log in'),), footer=form_footer, show_cancel_button=show_cancel_button) self.logout_redirect = self.request.route_url('index')
def __init__(self, request): form_footer = '<a class="link" href="{href}">{text}</a>'.format( # pylint: disable=consider-using-f-string href=request.route_path("forgot_password"), text=_("Forgot your password?")) self.request = request self.schema = LoginSchema().bind(request=self.request) show_cancel_button = bool(request.params.get("for_oauth", False)) self.form = request.create_form( self.schema, buttons=(_("Log in"), ), footer=form_footer, show_cancel_button=show_cancel_button, ) self.logout_redirect = self.request.route_url("index")
def test_invalid_with_bad_csrf(self, pyramid_request, user_service): schema = LoginSchema().bind(request=pyramid_request) with pytest.raises(BadCSRFToken): schema.deserialize({"username": "******", "password": "******"})
def test_default_values_prefills_username_from_username_query_param( self, pyramid_request, params, value): pyramid_request.params = params assert LoginSchema.default_values(pyramid_request)["username"] == value