push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
{
lib,
aniso8601,
blinker,
buildPythonPackage,
fetchPypi,
flask,
fetchpatch2,
mock,
pytest8_3CheckHook,
pythonOlder,
pytz,
six,
werkzeug,
}:
buildPythonPackage rec {
pname = "flask-restful";
version = "0.3.10";
format = "setuptools";
disabled = pythonOlder "3.7";
src = fetchPypi {
pname = "Flask-RESTful";
inherit version;
hash = "sha256-/kry7wAn34+bT3l6uiDFVmgBtq3plaxjtYir8aWc7Dc=";
};
# conditional so that overrides are easier for web applications
patches =
lib.optionals (lib.versionAtLeast werkzeug.version "2.1.0") [ ./werkzeug-2.1.0-compat.patch ]
++ lib.optionals (lib.versionAtLeast flask.version "3.0.0") [ ./flask-3.0-compat.patch ]
++ [
# replace use nose by pytest: https://github.com/flask-restful/flask-restful/pull/970
(fetchpatch2 {
url = "https://github.com/flask-restful/flask-restful/commit/6cc4b057e5450e0c84b3ee5f6f7a97e648a816d6.patch?full_index=1";
hash = "sha256-kIjrkyL0OfX+gjoiYfchU0QYTPHz4JMCQcHLFH9oEF4=";
})
./fix-test-inputs.patch
];
propagatedBuildInputs = [
aniso8601
flask
pytz
six
];
nativeCheckInputs = [
blinker
mock
pytest8_3CheckHook
];
disabledTests = [
# Broke in flask 2.2 upgrade
"test_exception_header_forwarded"
# Broke in werkzeug 2.3 upgrade
"test_media_types_method"
"test_media_types_q"
# time shenanigans
"test_iso8601_date_field_with_offset"
"test_rfc822_date_field_with_offset"
];
pythonImportsCheck = [ "flask_restful" ];
meta = with lib; {
description = "Framework for creating REST APIs";
homepage = "https://flask-restful.readthedocs.io";
longDescription = ''
Flask-RESTful provides the building blocks for creating a great
REST API.
'';
license = licenses.bsd3;
maintainers = [ ];
};
}

View File

@@ -0,0 +1,173 @@
diff --git a/tests/test_inputs.py b/tests/test_inputs.py
index 7c30d45..645b728 100644
--- a/tests/test_inputs.py
+++ b/tests/test_inputs.py
@@ -5,6 +5,7 @@ import re
#noinspection PyUnresolvedReferences
import six
+import pytest
from flask_restful import inputs
@@ -17,7 +18,7 @@ def test_reverse_rfc822_datetime():
]
for date_string, expected in dates:
- yield assert_equal, inputs.datetime_from_rfc822(date_string), expected
+ assert inputs.datetime_from_rfc822(date_string) == expected
def test_reverse_iso8601_datetime():
@@ -29,7 +30,7 @@ def test_reverse_iso8601_datetime():
]
for date_string, expected in dates:
- yield assert_equal, inputs.datetime_from_iso8601(date_string), expected
+ assert inputs.datetime_from_iso8601(date_string) == expected
def test_urls():
@@ -53,7 +54,7 @@ def test_urls():
]
for value in urls:
- yield assert_equal, inputs.url(value), value
+ assert inputs.url(value) == value
def check_bad_url_raises(value):
@@ -118,7 +119,8 @@ def test_regex_bad_input():
num_only = inputs.regex(r'^[0-9]+$')
for value in cases:
- yield assert_raises, ValueError, lambda: num_only(value)
+ with pytest.raises(ValueError):
+ num_only(value)
def test_regex_good_input():
@@ -131,12 +133,13 @@ def test_regex_good_input():
num_only = inputs.regex(r'^[0-9]+$')
for value in cases:
- yield assert_equal, num_only(value), value
+ assert num_only(value) == value
def test_regex_bad_pattern():
"""Regex error raised immediately when regex input parser is created."""
- assert_raises(re.error, inputs.regex, '[')
+ with pytest.raises(re.error):
+ inputs.regex('[')
def test_regex_flags_good_input():
@@ -149,7 +152,7 @@ def test_regex_flags_good_input():
case_insensitive = inputs.regex(r'^[A-Z]+$', re.IGNORECASE)
for value in cases:
- yield assert_equal, case_insensitive(value), value
+ assert case_insensitive(value) == value
def test_regex_flags_bad_input():
@@ -161,7 +164,8 @@ def test_regex_flags_bad_input():
case_sensitive = inputs.regex(r'^[A-Z]+$')
for value in cases:
- yield assert_raises, ValueError, lambda: case_sensitive(value)
+ with pytest.raises(ValueError):
+ case_sensitive(value)
class TypesTestCase(unittest.TestCase):
@@ -191,35 +195,41 @@ class TypesTestCase(unittest.TestCase):
assert inputs.boolean(False) == False
def test_bad_boolean(self):
- assert_raises(ValueError, lambda: inputs.boolean("blah"))
+ with pytest.raises(ValueError):
+ inputs.boolean("blah")
def test_date_later_than_1900(self):
assert inputs.date("1900-01-01") == datetime(1900, 1, 1)
def test_date_input_error(self):
- assert_raises(ValueError, lambda: inputs.date("2008-13-13"))
+ with pytest.raises(ValueError):
+ inputs.date("2008-13-13")
def test_date_input(self):
assert inputs.date("2008-08-01") == datetime(2008, 8, 1)
def test_natual_negative(self):
- assert_raises(ValueError, lambda: inputs.natural(-1))
+ with pytest.raises(ValueError):
+ inputs.natural(-1)
def test_natural(self):
assert 3 == inputs.natural(3)
def test_natual_string(self):
- assert_raises(ValueError, lambda: inputs.natural('foo'))
+ with pytest.raises(ValueError):
+ inputs.natural('foo')
def test_positive(self):
assert 1 == inputs.positive(1)
assert 10000 == inputs.positive(10000)
def test_positive_zero(self):
- assert_raises(ValueError, lambda: inputs.positive(0))
+ with pytest.raises(ValueError):
+ inputs.positive(0)
def test_positive_negative_input(self):
- assert_raises(ValueError, lambda: inputs.positive(-1))
+ with pytest.raises(ValueError):
+ inputs.positive(-1)
def test_int_range_good(self):
int_range = inputs.int_range(1, 5)
@@ -231,11 +241,13 @@ class TypesTestCase(unittest.TestCase):
def test_int_range_low(self):
int_range = inputs.int_range(0, 5)
- assert_raises(ValueError, lambda: int_range(-1))
+ with pytest.raises(ValueError):
+ int_range(-1)
def test_int_range_high(self):
int_range = inputs.int_range(0, 5)
- assert_raises(ValueError, lambda: int_range(6))
+ with pytest.raises(ValueError):
+ int_range(6)
def test_isointerval():
@@ -389,7 +401,7 @@ def test_isointerval():
]
for value, expected in intervals:
- yield assert_equal, inputs.iso8601interval(value), expected
+ assert inputs.iso8601interval(value) == expected
def test_invalid_isointerval_error():
@@ -413,12 +425,9 @@ def test_bad_isointervals():
]
for bad_interval in bad_intervals:
- yield (
- assert_raises,
- Exception,
- inputs.iso8601interval,
- bad_interval,
- )
+ with pytest.raises(Exception):
+ inputs.iso8601interval(bad_interval)
+
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,24 @@
diff --git a/tests/test_api.py b/tests/test_api.py
index 582ee5a..20db1f5 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -1,7 +1,7 @@
import unittest
import json
from flask import Flask, Blueprint, redirect, views, abort as flask_abort
-from flask.signals import got_request_exception, signals_available
+from flask.signals import got_request_exception
try:
from mock import Mock
except:
@@ -491,10 +491,6 @@ class APITestCase(unittest.TestCase):
self.assertEqual(api.default_mediatype, resp.headers['Content-Type'])
def test_handle_error_signal(self):
- if not signals_available:
- # This test requires the blinker lib to run.
- print("Can't test signals without signal support")
- return
app = Flask(__name__)
api = flask_restful.Api(app)

View File

@@ -0,0 +1,114 @@
Fixes compatibility with Werkzeug 2.1.0 ported over from flask-restx#423.
https://github.com/python-restx/flask-restx/pull/423
diff --git a/flask_restful/reqparse.py b/flask_restful/reqparse.py
index 9bb3099..5c59594 100644
--- a/flask_restful/reqparse.py
+++ b/flask_restful/reqparse.py
@@ -114,7 +114,10 @@ class Argument(object):
:param request: The flask request object to parse arguments from
"""
if isinstance(self.location, six.string_types):
- value = getattr(request, self.location, MultiDict())
+ if self.location in {"json", "get_json"}:
+ value = request.get_json(silent=True)
+ else:
+ value = getattr(request, self.location, MultiDict())
if callable(value):
value = value()
if value is not None:
@@ -122,7 +125,10 @@ class Argument(object):
else:
values = MultiDict()
for l in self.location:
- value = getattr(request, l, None)
+ if l in {"json", "get_json"}:
+ value = request.get_json(silent=True)
+ else:
+ value = getattr(request, l, None)
if callable(value):
value = value()
if value is not None:
diff --git a/tests/test_api.py b/tests/test_api.py
index 15f12eb..9a9cceb 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -936,7 +936,7 @@ class APITestCase(unittest.TestCase):
app = app.test_client()
resp = app.get('/api')
self.assertEqual(resp.status_code, 302)
- self.assertEqual(resp.headers['Location'], 'http://localhost/')
+ self.assertEqual(resp.headers['Location'], '/')
def test_json_float_marshalled(self):
app = Flask(__name__)
diff --git a/tests/test_reqparse.py b/tests/test_reqparse.py
index 1d75e40..e5c586b 100644
--- a/tests/test_reqparse.py
+++ b/tests/test_reqparse.py
@@ -23,8 +23,9 @@ class ReqParseTestCase(unittest.TestCase):
with app.app_context():
parser = RequestParser()
parser.add_argument('foo', choices=('one', 'two'), help='Bad choice: {error_msg}')
- req = Mock(['values'])
+ req = Mock(["values", "get_json"])
req.values = MultiDict([('foo', 'three')])
+ req.get_json.return_value = None
parser.parse_args(req)
expected = {'foo': 'Bad choice: three is not a valid choice'}
abort.assert_called_with(400, message=expected)
@@ -35,8 +36,9 @@ class ReqParseTestCase(unittest.TestCase):
with app.app_context():
parser = RequestParser()
parser.add_argument('foo', choices=('one', 'two'), help=u'Bad choice: {error_msg}')
- req = Mock(['values'])
+ req = Mock(["values", "get_json"])
req.values = MultiDict([('foo', u'\xf0\x9f\x8d\x95')])
+ req.get_json.return_value = None
parser.parse_args(req)
expected = {'foo': u'Bad choice: \xf0\x9f\x8d\x95 is not a valid choice'}
abort.assert_called_with(400, message=expected)
@@ -47,8 +49,9 @@ class ReqParseTestCase(unittest.TestCase):
with app.app_context():
parser = RequestParser()
parser.add_argument('foo', choices=['one', 'two'], help='Please select a valid choice')
- req = Mock(['values'])
+ req = Mock(["values", "get_json"])
req.values = MultiDict([('foo', 'three')])
+ req.get_json.return_value = None
parser.parse_args(req)
expected = {'foo': 'Please select a valid choice'}
abort.assert_called_with(400, message=expected)
@@ -58,8 +61,9 @@ class ReqParseTestCase(unittest.TestCase):
def bad_choice():
parser = RequestParser()
parser.add_argument('foo', choices=['one', 'two'])
- req = Mock(['values'])
+ req = Mock(["values", "get_json"])
req.values = MultiDict([('foo', 'three')])
+ req.get_json.return_value = None
parser.parse_args(req)
abort.assert_called_with(400, message='three is not a valid choice')
app = Flask(__name__)
@@ -190,7 +194,8 @@ class ReqParseTestCase(unittest.TestCase):
self.assertTrue(len(arg.source(req)) == 0) # yes, basically you don't find it
def test_source_default_location(self):
- req = Mock(['values'])
+ req = Mock(['values', 'get_json'])
+ req.get_json.return_value = None
req._get_child_mock = lambda **kwargs: MultiDict()
arg = Argument('foo')
self.assertEqual(arg.source(req), req.values)
@@ -215,8 +220,9 @@ class ReqParseTestCase(unittest.TestCase):
args = parser.parse_args(req)
self.assertEqual(args['foo'], "bar")
- req = Mock()
+ req = Mock(['get_json'])
req.values = ()
+ req.get_json.return_value = None
req.json = None
req.view_args = {"foo": "bar"}
parser = RequestParser()