Skip to content

Commit

Permalink
Fix the test for basic app (#221)
Browse files Browse the repository at this point in the history
1. Update the test app

If I understand correctly, the debug toolbar will only be enabled if `app.debug` is `True`. So I added the `DEBUG=True` to the test app.

Related code: https://github.com/pallets-eco/flask-debugtoolbar/blob/2b8bf9cc449a95f442b99dfdfb6147fa1ae2230a/src/flask_debugtoolbar/__init__.py#L114

2. Update the `src/flask_debugtoolbar/__init__.py`

Fix the two if statements to prevent the following errors:

```
>       if 'gzip' in response.headers.get('Content-Encoding'):
E       TypeError: argument of type 'NoneType' is not iterable
```

Since the `response.headers.get('Content-Encoding')` could be None.

With this PR, all the tests will be passed. The failed style checker will be fixed in #219
  • Loading branch information
greyli committed Nov 21, 2023
1 parent 62ce443 commit e6ae9d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/flask_debugtoolbar/__init__.py
Expand Up @@ -230,7 +230,8 @@ def process_response(self, response):
response.headers['content-type'].startswith('text/html')):
return response

if 'gzip' in response.headers.get('Content-Encoding'):
content_encoding = response.headers.get('Content-Encoding')
if content_encoding and 'gzip' in content_encoding:
response_html = gzip_decompress(response.data).decode()
else:
response_html = response.get_data(as_text=True)
Expand Down Expand Up @@ -258,7 +259,7 @@ def process_response(self, response):

content = ''.join((before, toolbar_html, after))
content = content.encode('utf-8')
if 'gzip' in response.headers.get('Content-Encoding'):
if content_encoding and 'gzip' in content_encoding:
content = gzip_compress(content)
response.response = [content]
response.content_length = len(content)
Expand Down
1 change: 1 addition & 0 deletions test/basic_app.py
Expand Up @@ -4,6 +4,7 @@
from flask_debugtoolbar import DebugToolbarExtension

app = Flask('basic_app')
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'abc123'
app.config['SQLALCHEMY_RECORD_QUERIES'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
Expand Down

0 comments on commit e6ae9d0

Please sign in to comment.