Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #292: Added support for Python 3.12 #296

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ docs/build/*
.flake8
.pytest_cache/*
.vscode
.coverage
.python-version

### Emacs template
# -*- mode: gitignore; -*-
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

Unreleased
----------
- Added support for Python 3.12
- Added support for Flask 3.x
- Dropped support for Flask 1.x
- Switched from Flask-Mail to Flask-Mailman


v1.5.0 - 2023-11-38
-------------------
Expand Down
17 changes: 9 additions & 8 deletions flask_praetorian/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import uuid
import warnings

from flask_mail import Message
from flask_mailman import EmailMessage

from passlib.context import CryptContext

Expand Down Expand Up @@ -911,7 +911,7 @@ def send_token_email(
}

PraetorianError.require_condition(
"mail" in flask.current_app.extensions,
"mailman" in flask.current_app.extensions,
"Your app must have a mail extension enabled to register by email",
)

Expand All @@ -929,15 +929,16 @@ def send_token_email(
jinja_tmpl = jinja2.Template(template)
notification["message"] = jinja_tmpl.render(notification).strip()

msg = Message(
html=notification["message"],
sender=action_sender,
subject=notification["subject"],
recipients=[notification["email"]],
msg = EmailMessage(
notification["subject"],
notification["message"],
action_sender,
[notification["email"]],
)

flask.current_app.logger.debug("Sending email to {}".format(email))
flask.current_app.extensions['mail'].send(msg)
msg.content_subtype = "html"
msg.send(msg)

return notification

Expand Down
404 changes: 304 additions & 100 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ repository = "https://github.com/dusktreader/flask-praetorian"
[tool.poetry.dependencies]
python = "^3.8"
pyjwt = "^2.0"
pendulum = "^2.1"
pendulum = "^3.0"
passlib = "^1.7"
flask-buzz = "^3.1"
flask-mail = "^0.9.1"
flask = ">=2.0, <4.0"
flask-mailman = "^1.0.0"

[tool.poetry.group.dev.dependencies]
flask-sqlalchemy = "^3.1"
flask-cors = "^3.0"
pytest = "^6.2.5"
pytest = "^7"
pytest-flask = "^1.0"
sphinx = "^1.8"
sphinx-view = "^0.2.0"
Expand All @@ -31,6 +31,19 @@ ipdb = "^0.12.0"
toml = "^0.10.0"
plummet = {version = "^1.2.1", extras = ["time-machine"]}
ruff = "^0.1.6"
pytest-random-order = "^1.1.1"
pytest-cov = "^4.1.0"

[tool.pytest.ini_options]
minversion = "7.0"
addopts = [
"--random-order",
"--cov=flask_praetorian",
]

[tool.coverage.report]
fail_under = 90
show_missing = true

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_praetorian import Praetorian
from flask_mail import Mail
from flask_mailman import Mail


_db = SQLAlchemy()
Expand Down Expand Up @@ -215,7 +215,7 @@ def default_guard():
@pytest.fixture(scope="session")
def mail():
"""
This fixture simply fetches the db instance to be used in testing
This fixture simply fetches the mail instance to be used in testing
"""
return _mail

Expand Down
55 changes: 26 additions & 29 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def test_pack_header_for_user(self, app, user_class):
assert token_data["el_duderino"] == "not brief"

def test_send_token_email__renders_an_email_template_and_sends_the_message_with_the_token(
self, app, db, user_class, default_guard,
self, app, db, user_class, default_guard, mail,
):
# create our default test user
the_dude = user_class(username='TheDude')
Expand All @@ -950,21 +950,20 @@ def test_send_token_email__renders_an_email_template_and_sends_the_message_with_
</body>
</html>
"""
with app.mail.record_messages() as outbox:
notify = default_guard.send_token_email(
email='[email protected]',
template=template,
action_sender='[email protected]',
action_uri="action.mystery.com",
subject="Have it your way, Dude",
custom_token="sasparilla",
)
notify = default_guard.send_token_email(
email='[email protected]',
template=template,
action_sender='[email protected]',
action_uri="action.mystery.com",
subject="Have it your way, Dude",
custom_token="sasparilla",
)

token = notify['token']
token = notify['token']

# test our own interpretation and what we got back from flask_mail
assert token in notify['message']
assert notify['message'] == outbox[0].html
# test our own interpretation and what we got back from flask_mailman
assert token in notify['message']
assert notify['message'] == app.extensions['mailman'].outbox[0].body

def test_send_token_email__raises_exception_if_action_sender_is_not_defined(
self, app, user_class, default_guard,
Expand Down Expand Up @@ -1006,13 +1005,12 @@ def test_reset_email(self, app, user_class, db, tmpdir, default_guard):
db.session.add(the_dude)
db.session.commit()

with app.mail.record_messages() as outbox:
notify = default_guard.send_reset_email("[email protected]", the_dude)
token = notify['token']
notify = default_guard.send_reset_email("[email protected]", the_dude)
token = notify['token']

# test our own interpretation and what we got back from flask_mail
assert token in notify["message"]
assert notify["message"] == outbox[0].html
# test our own interpretation and what we got back from flask_mailman
assert token in notify["message"]
assert notify['message'] == app.extensions['mailman'].outbox[0].body

# test our token is good
jwt_data = default_guard.extract_jwt_token(
Expand Down Expand Up @@ -1057,16 +1055,15 @@ def test_registration_email(
db.session.add(the_dude)
db.session.commit()

with app.mail.record_messages() as outbox:
notify = default_guard.send_registration_email(
'[email protected]',
the_dude,
)
token = notify['token']
notify = default_guard.send_registration_email(
'[email protected]',
the_dude,
)
token = notify['token']

# test our own interpretation and what we got back from flask_mail
assert token in notify["message"]
assert notify["message"] == outbox[0].html
# test our own interpretation and what we got back from flask_mailman
assert token in notify["message"]
assert notify['message'] == app.extensions['mailman'].outbox[0].body

# test our token is good
jwt_data = default_guard.extract_jwt_token(
Expand Down
Loading