qutebrowser/tests/browser/http/test_http.py

89 lines
3.1 KiB
Python
Raw Normal View History

2014-08-12 09:04:43 +02:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2015-01-03 15:51:31 +01:00
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
2014-08-12 09:04:43 +02:00
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
2015-02-05 06:59:00 +01:00
"""Tests for qutebrowser.browser.http.
2014-08-12 09:04:43 +02:00
Note that tests for parse_content_disposition are in their own
test_content_disposition.py file.
"""
import pytest
from PyQt5.QtCore import QUrl
2015-02-05 06:59:00 +01:00
from qutebrowser.browser import http
2014-08-12 09:04:43 +02:00
class TestNoContentDisposition:
"""Test parse_content_disposition with no Content-Disposition header."""
@pytest.mark.parametrize('url', ['http://example.com/path',
'http://example.com/foo/path'])
def test_url(self, stubs, url):
"""Test with a filename in the URL."""
reply = stubs.FakeNetworkReply(url=QUrl(url))
inline, filename = http.parse_content_disposition(reply)
assert inline
assert filename == 'path'
@pytest.mark.parametrize('url', ['http://example.com',
'http://example.com/'])
def test_none(self, stubs, url):
"""Test with no filename at all."""
reply = stubs.FakeNetworkReply(url=QUrl(url))
inline, filename = http.parse_content_disposition(reply)
assert inline
assert filename == 'qutebrowser-download'
class TestParseContentType:
2014-08-12 09:04:43 +02:00
"""Test for parse_content_type."""
2015-04-04 01:09:53 +02:00
def test_not_existing(self, stubs):
2014-08-12 09:04:43 +02:00
"""Test without any Content-Type header."""
2014-08-26 19:10:14 +02:00
reply = stubs.FakeNetworkReply()
mimetype, rest = http.parse_content_type(reply)
2015-04-04 01:09:53 +02:00
assert mimetype is None
assert rest is None
2014-08-12 09:04:43 +02:00
2015-04-04 01:09:53 +02:00
def test_mimetype(self, stubs):
2014-08-12 09:04:43 +02:00
"""Test with simple Content-Type header."""
2014-08-26 19:10:14 +02:00
reply = stubs.FakeNetworkReply(
headers={'Content-Type': 'image/example'})
mimetype, rest = http.parse_content_type(reply)
2015-04-04 01:09:53 +02:00
assert mimetype == 'image/example'
assert rest is None
2014-08-12 09:04:43 +02:00
2015-04-04 01:09:53 +02:00
def test_empty(self, stubs):
2014-08-12 09:04:43 +02:00
"""Test with empty Content-Type header."""
2014-08-26 19:10:14 +02:00
reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
mimetype, rest = http.parse_content_type(reply)
2015-04-04 01:09:53 +02:00
assert mimetype == ''
assert rest is None
2014-08-12 09:04:43 +02:00
2015-04-04 01:09:53 +02:00
def test_additional(self, stubs):
2014-08-12 09:04:43 +02:00
"""Test with Content-Type header with additional informations."""
2014-08-26 19:10:14 +02:00
reply = stubs.FakeNetworkReply(
2014-08-12 09:04:43 +02:00
headers={'Content-Type': 'image/example; encoding=UTF-8'})
2014-08-26 19:10:14 +02:00
mimetype, rest = http.parse_content_type(reply)
2015-04-04 01:09:53 +02:00
assert mimetype == 'image/example'
assert rest == ' encoding=UTF-8'