Skip to content

Commit

Permalink
add failing tests for bom
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Rodrigues committed Feb 9, 2019
1 parent f507a3e commit 9e27326
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ env/
.venv/
.eggs/
.tox/
.pytest_cache/
.vscode/

.workon

Expand Down
30 changes: 30 additions & 0 deletions tests/test_testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ def test_text_response(self):
assert r.text == u'roflol'
assert r.headers['Content-Length'] == '6'

def test_text_bom_response(self):
"""the text_response_server sends the given text with UTF-8 BOM"""
server = Server.text_response_server(
"HTTP/1.1 200 OK\r\n" +
"Content-Type: text/html; charset=UTF-8\r\n" +
u'\r\n\ufeff<doctype html><html><body>ジェーピーニック</body></html>'
)

with server as (host, port):
r = requests.get('http://{}:{}'.format(host, port))

assert r.status_code == 200
assert r.text == u'<doctype html><html><body>ジェーピーニック</body></html>'
assert r.headers['Content-Type'] == 'text/html; charset=UTF-8'

def test_json_bom_response(self):
"""the text_response_server sends the given JSON with UTF-8 BOM"""
server = Server.text_response_server(
"HTTP/1.1 200 OK\r\n" +
"Content-Type: application/json; charset=utf-8\r\n" +
u'\r\n\ufeff{"success": true}'
)

with server as (host, port):
r = requests.get('http://{}:{}'.format(host, port))

assert r.status_code == 200
assert r.json() == {'success': True}
assert r.headers['Content-Type'] == 'application/json; charset=utf-8'

def test_basic_response(self):
"""the basic response server returns an empty http response"""
with Server.basic_response_server() as (host, port):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_bad_utf_like_encoding(self):

@pytest.mark.parametrize(
('encoding', 'expected'), (
('utf-8-sig', 'utf-8'),
('utf-8-sig', 'utf-8-sig'),
('utf-16-be', 'utf-16'),
('utf-16-le', 'utf-16'),
('utf-32-be', 'utf-32'),
Expand Down

0 comments on commit 9e27326

Please sign in to comment.