Converted test_http to pytest

This commit is contained in:
Bruno Oliveira 2015-04-03 20:09:53 -03:00
parent 3129def33e
commit 22df30cdcc

View File

@ -23,46 +23,40 @@ Note that tests for parse_content_disposition are in their own
test_content_disposition.py file. test_content_disposition.py file.
""" """
import unittest
from qutebrowser.browser import http from qutebrowser.browser import http
from qutebrowser.test import stubs
class ParseContentTypeTests(unittest.TestCase): class TestParseContentType(object):
"""Test for parse_content_type.""" """Test for parse_content_type."""
def test_not_existing(self): def test_not_existing(self, stubs):
"""Test without any Content-Type header.""" """Test without any Content-Type header."""
reply = stubs.FakeNetworkReply() reply = stubs.FakeNetworkReply()
mimetype, rest = http.parse_content_type(reply) mimetype, rest = http.parse_content_type(reply)
self.assertIsNone(mimetype) assert mimetype is None
self.assertIsNone(rest) assert rest is None
def test_mimetype(self): def test_mimetype(self, stubs):
"""Test with simple Content-Type header.""" """Test with simple Content-Type header."""
reply = stubs.FakeNetworkReply( reply = stubs.FakeNetworkReply(
headers={'Content-Type': 'image/example'}) headers={'Content-Type': 'image/example'})
mimetype, rest = http.parse_content_type(reply) mimetype, rest = http.parse_content_type(reply)
self.assertEqual(mimetype, 'image/example') assert mimetype == 'image/example'
self.assertIsNone(rest) assert rest is None
def test_empty(self): def test_empty(self, stubs):
"""Test with empty Content-Type header.""" """Test with empty Content-Type header."""
reply = stubs.FakeNetworkReply(headers={'Content-Type': ''}) reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
mimetype, rest = http.parse_content_type(reply) mimetype, rest = http.parse_content_type(reply)
self.assertEqual(mimetype, '') assert mimetype == ''
self.assertIsNone(rest) assert rest is None
def test_additional(self): def test_additional(self, stubs):
"""Test with Content-Type header with additional informations.""" """Test with Content-Type header with additional informations."""
reply = stubs.FakeNetworkReply( reply = stubs.FakeNetworkReply(
headers={'Content-Type': 'image/example; encoding=UTF-8'}) headers={'Content-Type': 'image/example; encoding=UTF-8'})
mimetype, rest = http.parse_content_type(reply) mimetype, rest = http.parse_content_type(reply)
self.assertEqual(mimetype, 'image/example') assert mimetype == 'image/example'
self.assertEqual(rest, ' encoding=UTF-8') assert rest == ' encoding=UTF-8'
if __name__ == '__main__':
unittest.main()