view MoinMoin/util/_tests/test_mimetype.py @ 2657:080673c3e60a

Now nameless items can also be downloaded and removed unnecessary blank spaces in items/content.py
author Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
date Sun, 06 Jul 2014 09:25:31 +0530
parents ee404f81afe9
children
line wrap: on
line source
# -*- coding: utf-8 -*-
# Copyright: 2011 Prashant Kumar <contactprashantat AT gmail DOT com>
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - MoinMoin.util.mimetype Tests
"""


from MoinMoin.util import mimetype


class TestMimeType(object):
    """ Test: util.mimetype """

    def test_parse_format(self):
        MimeType_obj = mimetype.MimeType(filename='test_file.jpg')
        # format in PARSER_TEXT_MIMETYPE
        test = [
            # test_format, test_mimetype
            ('html', ('text', 'html')),
            ('css', ('text', 'css')),
            ('python', ('text', 'python')),
            ('latex', ('text', 'latex')),
        ]

        for test_format, test_mimetype in test:
            result = MimeType_obj.parse_format(test_format)
            assert result == test_mimetype

        # format not in PARSER_TEXT_MIMETYPE
        test = [
            # test_format, test_mimetype
            ('wiki', ('text', 'x.moin.wiki')),
            ('irc', ('text', 'irssi')),
            ('test_random', ('text', 'x-test_random')),
        ]

        for test_format, test_mimetype in test:
            result = MimeType_obj.parse_format(test_format)
            assert result == test_mimetype

    def test_mime_type(self):
        test = [
            # test_extension, test_major/minor
            ('.mpeg', 'video/mpeg'),
            ('.pdf', 'application/pdf'),
            ('.txt', 'text/plain'),
            ('.jpeg', 'image/jpeg'),
            ('.png', 'image/png'),
            ('.svg', 'image/svg+xml'),
            ('', 'application/octet-stream'),
        ]

        # when mimestr is None
        for test_extension, test_major_minor in test:
            MimeType_obj = mimetype.MimeType(filename='test_file' + test_extension)
            result = MimeType_obj.mime_type()
            expected = test_major_minor
            assert result == expected

        # when mimestr is not None
        MimeType_obj = mimetype.MimeType(filename='test_file', mimestr='image/jpeg;charset="utf-8";misc=moin_misc')
        result = MimeType_obj.mime_type()
        assert result == 'image/jpeg'

    def test_content_type(self):
        MimeType_obj = mimetype.MimeType('test_file.mpeg')

        result1 = MimeType_obj.content_type(major='application', minor='pdf', charset="utf-16", params=None)
        expected = 'application/pdf'
        assert result1 == expected

        # major == 'text'
        result2 = MimeType_obj.content_type(major='text', minor='plain', charset="utf-16", params=None)
        expected = 'text/plain;charset="utf-16"'
        assert result2 == expected

        # when all the parameters passed are None
        result3 = MimeType_obj.content_type()
        expected = 'text/x-test_file.mpeg'
        assert result3 == expected