Skip to content

Commit

Permalink
simplify parse mimetype tests (aio-libs#2344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique authored and asvetlov committed Oct 19, 2017
1 parent 032a242 commit 3b95e16
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,27 @@ def test_coro_guard_close():

# ------------------- parse_mimetype ----------------------------------

def test_parse_mimetype_1():
assert helpers.parse_mimetype('') == ('', '', '', {})


def test_parse_mimetype_2():
assert helpers.parse_mimetype('*') == ('*', '*', '', {})


def test_parse_mimetype_3():
assert (helpers.parse_mimetype('application/json') ==
('application', 'json', '', {}))


def test_parse_mimetype_4():
assert (
helpers.parse_mimetype('application/json; charset=utf-8') ==
('application', 'json', '', {'charset': 'utf-8'}))


def test_parse_mimetype_5():
assert (
helpers.parse_mimetype('''application/json; charset=utf-8;''') ==
('application', 'json', '', {'charset': 'utf-8'}))


def test_parse_mimetype_6():
assert(
helpers.parse_mimetype('ApPlIcAtIoN/JSON;ChaRseT="UTF-8"') ==
('application', 'json', '', {'charset': 'UTF-8'}))


def test_parse_mimetype_7():
assert (
helpers.parse_mimetype('application/rss+xml') ==
('application', 'rss', 'xml', {}))


def test_parse_mimetype_8():
assert (
helpers.parse_mimetype('text/plain;base64') ==
('text', 'plain', '', {'base64': ''}))
@pytest.mark.parametrize('mimetype, expected', [
('', ('', '', '', {})),
('*', ('*', '*', '', {})),
('application/json', ('application', 'json', '', {})),
(
'application/json; charset=utf-8',
('application', 'json', '', {'charset': 'utf-8'})
),
(
'''application/json; charset=utf-8;''',
('application', 'json', '', {'charset': 'utf-8'})
),
(
'ApPlIcAtIoN/JSON;ChaRseT="UTF-8"',
('application', 'json', '', {'charset': 'UTF-8'})
),
('application/rss+xml', ('application', 'rss', 'xml', {})),
('text/plain;base64', ('text', 'plain', '', {'base64': ''}))
])
def test_parse_mimetype(mimetype, expected):
assert helpers.parse_mimetype(mimetype) == expected


# ------------------- guess_filename ----------------------------------
Expand Down

0 comments on commit 3b95e16

Please sign in to comment.