Update to a fixed version, but no release version exists. #132
GitHub Actions / Unit Test Results
failed
Oct 30, 2023 in 0s
2 fail, 79 pass in 26s
1 files 1 suites 26s ⏱️
81 tests 79 ✔️ 0 💤 2 ❌
Results for commit 61124db.
Annotations
Check warning on line 0 in brainzutils.flask.test.test_main.FlaskTestCase
github-actions / Unit Test Results
test_debug_toolbar (brainzutils.flask.test.test_main.FlaskTestCase) failed
reports/test_results.xml
Raw output
self = <brainzutils.flask.test.test_main.FlaskTestCase testMethod=test_debug_toolbar>
def test_debug_toolbar(self):
""" Tests that debug toolbar loads if initialized correctly
"""
# create an app
app = flask.CustomFlask(__name__)
self.assertIsNotNone(app)
app.debug = True
app.config['SECRET_KEY'] = 'this is a totally secret key btw'
app.init_debug_toolbar()
# add a dummy route
@app.route('/')
def index():
return '<html><body>test</body></html>'
client = app.test_client()
> response = client.get('/')
brainzutils/flask/test/test_main.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1160: in get
return self.open(*args, **kw)
/usr/local/lib/python3.10/site-packages/flask/testing.py:232: in open
response = super().open(
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1114: in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:986: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1262: in run_wsgi_app
app_rv = app(environ, start_response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1478: in __call__
return self.wsgi_app(environ, start_response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1458: in wsgi_app
response = self.handle_exception(e)
/usr/local/lib/python3.10/site-packages/flask/app.py:1455: in wsgi_app
response = self.full_dispatch_request()
/usr/local/lib/python3.10/site-packages/flask/app.py:870: in full_dispatch_request
return self.finalize_request(rv)
/usr/local/lib/python3.10/site-packages/flask/app.py:891: in finalize_request
response = self.process_response(response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1267: in process_response
response = self.ensure_sync(func)(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <flask_debugtoolbar.DebugToolbarExtension object at 0x7fb4a20979a0>
response = <Response 30 bytes [200 OK]>
def process_response(self, response):
real_request = request._get_current_object()
if real_request not in self.debug_toolbars:
return response
# Intercept http redirect codes and display an html page with a
# link to the target.
if current_app.config['DEBUG_TB_INTERCEPT_REDIRECTS']:
if response.status_code in self._redirect_codes:
redirect_to = response.location
redirect_code = response.status_code
if redirect_to:
content = self.render('redirect.html', {
'redirect_to': redirect_to,
'redirect_code': redirect_code
})
response.content_length = len(content)
response.location = None
response.response = [content]
response.status_code = 200
# If the http response code is an allowed code then we process to add the
# toolbar to the returned html response.
if not (response.status_code in self._toolbar_codes and
response.is_sequence and
response.headers['content-type'].startswith('text/html')):
return response
if 'gzip' in response.headers.get('Content-Encoding', ''):
response_html = gzip_decompress(response.data).decode()
else:
response_html = response.get_data(as_text=True)
no_case = response_html.lower()
body_end = no_case.rfind('</body>')
if body_end >= 0:
before = response_html[:body_end]
after = response_html[body_end:]
elif no_case.startswith('<!doctype html>'):
before = response_html
after = ''
else:
warnings.warn('Could not insert debug toolbar.'
' </body> tag not found in response.')
return response
toolbar = self.debug_toolbars[real_request]
for panel in toolbar.panels:
panel.process_response(real_request, response)
toolbar_html = toolbar.render_toolbar()
content = ''.join((before, toolbar_html, after))
> content = content.encode(response.charset)
E AttributeError: 'Response' object has no attribute 'charset'
/usr/local/lib/python3.10/site-packages/flask_debugtoolbar/__init__.py:260: AttributeError
Check warning on line 0 in brainzutils.flask.test.test_ratelimit.RatelimitTestCase
github-actions / Unit Test Results
test_ratelimit (brainzutils.flask.test.test_ratelimit.RatelimitTestCase) failed
reports/test_results.xml
Raw output
self = <brainzutils.flask.test.test_ratelimit.RatelimitTestCase testMethod=test_ratelimit>
def test_ratelimit(self):
""" Tests that the ratelimit decorator works
"""
# Set the limits as per defines in this class
set_rate_limits(self.max_token_requests, self.max_ip_requests, self.ratelimit_window)
# create an app
app = flask.CustomFlask(__name__)
self.assertIsNotNone(app)
app.debug = True
app.config['SECRET_KEY'] = 'this is a totally secret key btw'
app.init_debug_toolbar()
@app.after_request
def after_request_callbacks(response):
return inject_x_rate_headers(response)
# add a dummy route
@app.route('/')
@ratelimit()
def index():
return '<html><body>test</body></html>'
def print_headers(response):
print("X-RateLimit-Remaining", response.headers['X-RateLimit-Remaining'])
print("X-RateLimit-Limit", response.headers['X-RateLimit-Limit'])
print("X-RateLimit-Reset", response.headers['X-RateLimit-Reset'])
print("X-RateLimit-Reset-In", response.headers['X-RateLimit-Reset-In'])
print()
def make_requests(client, nominal_num_requests, token = None):
print("===== make %d requests" % nominal_num_requests)
# make one more than the allowed number of requests to catch the 429
num_requests = nominal_num_requests + 1
# make a specified number of requests
while True:
reset_time = 0
restart = False
for i in range(num_requests):
if token:
response = client.get('/', headers={'Authorization': token})
else:
response = client.get('/')
if reset_time == 0:
reset_time = response.headers['X-RateLimit-Reset']
if reset_time != response.headers['X-RateLimit-Reset']:
# Whoops, we didn't get our tests done before the window expired. start over.
restart = True
# when restarting we need to do one request less, since the current requests counts to the new window
num_requests = nominal_num_requests
break
if i == num_requests - 1:
self.assertEqual(response.status_code, 429)
else:
self.assertEqual(response.status_code, 200)
self.assertEqual(int(response.headers['X-RateLimit-Remaining']), num_requests - i - 2)
print_headers(response)
sleep(1.1)
if not restart:
break
client = app.test_client()
# Make a pile of requests based on IP address
> make_requests(client, self.max_ip_requests)
brainzutils/flask/test/test_ratelimit.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
brainzutils/flask/test/test_ratelimit.py:82: in make_requests
response = client.get('/')
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1160: in get
return self.open(*args, **kw)
/usr/local/lib/python3.10/site-packages/flask/testing.py:232: in open
response = super().open(
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1114: in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:986: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
/usr/local/lib/python3.10/site-packages/werkzeug/test.py:1262: in run_wsgi_app
app_rv = app(environ, start_response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1478: in __call__
return self.wsgi_app(environ, start_response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1458: in wsgi_app
response = self.handle_exception(e)
/usr/local/lib/python3.10/site-packages/flask/app.py:1455: in wsgi_app
response = self.full_dispatch_request()
/usr/local/lib/python3.10/site-packages/flask/app.py:870: in full_dispatch_request
return self.finalize_request(rv)
/usr/local/lib/python3.10/site-packages/flask/app.py:891: in finalize_request
response = self.process_response(response)
/usr/local/lib/python3.10/site-packages/flask/app.py:1267: in process_response
response = self.ensure_sync(func)(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <flask_debugtoolbar.DebugToolbarExtension object at 0x7fb4a0109900>
response = <Response 30 bytes [200 OK]>
def process_response(self, response):
real_request = request._get_current_object()
if real_request not in self.debug_toolbars:
return response
# Intercept http redirect codes and display an html page with a
# link to the target.
if current_app.config['DEBUG_TB_INTERCEPT_REDIRECTS']:
if response.status_code in self._redirect_codes:
redirect_to = response.location
redirect_code = response.status_code
if redirect_to:
content = self.render('redirect.html', {
'redirect_to': redirect_to,
'redirect_code': redirect_code
})
response.content_length = len(content)
response.location = None
response.response = [content]
response.status_code = 200
# If the http response code is an allowed code then we process to add the
# toolbar to the returned html response.
if not (response.status_code in self._toolbar_codes and
response.is_sequence and
response.headers['content-type'].startswith('text/html')):
return response
if 'gzip' in response.headers.get('Content-Encoding', ''):
response_html = gzip_decompress(response.data).decode()
else:
response_html = response.get_data(as_text=True)
no_case = response_html.lower()
body_end = no_case.rfind('</body>')
if body_end >= 0:
before = response_html[:body_end]
after = response_html[body_end:]
elif no_case.startswith('<!doctype html>'):
before = response_html
after = ''
else:
warnings.warn('Could not insert debug toolbar.'
' </body> tag not found in response.')
return response
toolbar = self.debug_toolbars[real_request]
for panel in toolbar.panels:
panel.process_response(real_request, response)
toolbar_html = toolbar.render_toolbar()
content = ''.join((before, toolbar_html, after))
> content = content.encode(response.charset)
E AttributeError: 'Response' object has no attribute 'charset'
/usr/local/lib/python3.10/site-packages/flask_debugtoolbar/__init__.py:260: AttributeError
Loading