Skip to content

Commit

Permalink
Drop support for Python < 3.9
Browse files Browse the repository at this point in the history
And update dependencies.

Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed May 13, 2022
1 parent c0ac6f5 commit e059ee2
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 364 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ jobs:
strategy:
matrix:
tox_env:
- py36-unittest
- py37-unittest
- py38-unittest
- py39-unittest
- py310-unittest
runs-on: ubuntu-latest
9 changes: 0 additions & 9 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ queue_rules:
- status-success=Misc tests (licenses)
- status-success=Misc tests (security)
- status-success=Misc tests (docs)
- status-success=Unit tests (py36-unittest)
- status-success=Unit tests (py37-unittest)
- status-success=Unit tests (py38-unittest)
- status-success=Unit tests (py39-unittest)
- status-success=Unit tests (py310-unittest)

Expand All @@ -32,9 +29,6 @@ pull_request_rules:
- status-success=Misc tests (licenses)
- status-success=Misc tests (security)
- status-success=Misc tests (docs)
- status-success=Unit tests (py36-unittest)
- status-success=Unit tests (py37-unittest)
- status-success=Unit tests (py38-unittest)
- status-success=Unit tests (py39-unittest)
- status-success=Unit tests (py310-unittest)

Expand All @@ -56,8 +50,5 @@ pull_request_rules:
- status-success=Misc tests (licenses)
- status-success=Misc tests (security)
- status-success=Misc tests (docs)
- status-success=Unit tests (py36-unittest)
- status-success=Unit tests (py37-unittest)
- status-success=Unit tests (py38-unittest)
- status-success=Unit tests (py39-unittest)
- status-success=Unit tests (py310-unittest)
14 changes: 2 additions & 12 deletions fasjson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Set the version
try:
import importlib.metadata
import importlib.metadata

__version__ = importlib.metadata.version("fasjson")
except ImportError:
try:
import pkg_resources

try:
__version__ = pkg_resources.get_distribution("fasjson").version
except pkg_resources.DistributionNotFound:
__version__ = None
except ImportError:
__version__ = None
__version__ = importlib.metadata.version("fasjson")
33 changes: 33 additions & 0 deletions fasjson/tests/unit/test_web_resource_v1_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,36 @@ def get_user_api_output_private(name):
print(expected[0])
print(rv.get_json()["result"][0])
assert rv.get_json() == {"result": expected, "page": page}


def test_search_json_body(client, ldap_with_search_result):
ldap_with_search_result(
num=0, page_size=1, page_number=1, total_results=0
)
rv = client.get("/v1/search/users/", json={"username": "dummy"})

assert 200 == rv.status_code
page = {
"total_results": 0,
"page_size": 1,
"page_number": 1,
"total_pages": 0,
}
assert rv.get_json() == {"result": [], "page": page}


def test_search_bad_json_body(client, ldap_with_search_result):
# This should trigger the error handling in AnyJsonRequest
ldap_with_search_result(
num=0, page_size=1, page_number=1, total_results=0
)
rv = client.get(
"/v1/search/users/", data="bad-json", content_type="application/json"
)

assert 400 == rv.status_code
assert rv.get_json() == {
"message": (
"The browser (or proxy) sent a request that this server could not understand."
)
}
12 changes: 12 additions & 0 deletions fasjson/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from logging.config import dictConfig

from flask import Flask
from flask.wrappers import Request
from flask_healthz import healthz
from flask_mod_auth_gssapi import FlaskModAuthGSSAPI
from flask_restx import abort
Expand All @@ -21,11 +22,22 @@ class NameConverter(BaseConverter):
regex = "[a-zA-Z0-9][a-zA-Z0-9_.-]{0,63}"


# https://github.com/pallets/flask/issues/4552#issuecomment-1109785314
class AnyJsonRequest(Request):
def on_json_loading_failed(self, e):
if e is not None:
return super().on_json_loading_failed(e)


def create_app(config=None):
"""See https://flask.palletsprojects.com/en/1.1.x/patterns/appfactories/"""

app = Flask(__name__)

# Don't crash if content-type is not set to application/json.
# https://github.com/python-restx/flask-restx/issues/422
app.request_class = AnyJsonRequest

# Load default configuration
app.config.from_pyfile("defaults.cfg")

Expand Down
2 changes: 1 addition & 1 deletion fasjson/web/defaults.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This turns all 404 error messages into something that supposes you've mistyped the URL, while it's
# most often that the requested object does not exist. Turn it off.
ERROR_404_HELP = False
RESTX_ERROR_404_HELP = False

# Show all request parsing errors
# https://flask-restx.readthedocs.io/en/latest/parsing.html#error-handling
Expand Down
1 change: 1 addition & 0 deletions news/PR332.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for Python < 3.9
Loading

0 comments on commit e059ee2

Please sign in to comment.