Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Apr 24, 2022
2 parents a03719b + 2ec1193 commit cb4f742
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ Version 2.2.0
Unreleased


Version 2.1.2
-------------

Unreleased

- Fix type annotation for ``json.loads``, it accepts str or bytes.
:issue:`4519`
- The ``--cert`` and ``--key`` options on ``flask run`` can be given
in either order. :issue:`4459`


Version 2.1.1
-------------

Expand Down
6 changes: 3 additions & 3 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ use ``pathlib.Path`` to get files relative to the current test file.
def test_edit_user(client):
response = client.post("/user/2/edit", data={
name="Flask",
theme="dark",
picture=(resources / "picture.png").open("rb"),
"name": "Flask",
"theme": "dark",
"picture": (resources / "picture.png").open("rb"),
})
assert response.status_code == 200
Expand Down
5 changes: 4 additions & 1 deletion src/flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,10 @@ def convert(self, value, param, ctx):
@click.option("--host", "-h", default="127.0.0.1", help="The interface to bind to.")
@click.option("--port", "-p", default=5000, help="The port to bind to.")
@click.option(
"--cert", type=CertParamType(), help="Specify a certificate file to use HTTPS."
"--cert",
type=CertParamType(),
help="Specify a certificate file to use HTTPS.",
is_eager=True,
)
@click.option(
"--key",
Expand Down
6 changes: 5 additions & 1 deletion src/flask/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def dump(
_json.dump(obj, fp, **kwargs)


def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
def loads(
s: t.Union[str, bytes],
app: t.Optional["Flask"] = None,
**kwargs: t.Any,
) -> t.Any:
"""Deserialize an object from a string of JSON.
Takes the same arguments as the built-in :func:`json.loads`, with
Expand Down
15 changes: 5 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import types
from functools import partial
from pathlib import Path
from unittest.mock import patch

import click
import pytest
Expand All @@ -25,7 +24,6 @@
from flask.cli import get_version
from flask.cli import load_dotenv
from flask.cli import locate_app
from flask.cli import main as cli_main
from flask.cli import NoAppException
from flask.cli import prepare_import
from flask.cli import run_command
Expand Down Expand Up @@ -555,9 +553,14 @@ def test_run_cert_path():
with pytest.raises(click.BadParameter):
run_command.make_context("run", ["--key", __file__])

# cert specified first
ctx = run_command.make_context("run", ["--cert", __file__, "--key", __file__])
assert ctx.params["cert"] == (__file__, __file__)

# key specified first
ctx = run_command.make_context("run", ["--key", __file__, "--cert", __file__])
assert ctx.params["cert"] == (__file__, __file__)


def test_run_cert_adhoc(monkeypatch):
monkeypatch.setitem(sys.modules, "cryptography", None)
Expand Down Expand Up @@ -654,11 +657,3 @@ def test_cli_empty(app):

result = app.test_cli_runner().invoke(args=["blue", "--help"])
assert result.exit_code == 2, f"Unexpected success:\n\n{result.output}"


def test_click_7_deprecated():
with patch("flask.cli.cli"):
if int(click.__version__[0]) < 8:
pytest.deprecated_call(cli_main, match=".* Click 7 is deprecated")
else:
cli_main()

0 comments on commit cb4f742

Please sign in to comment.