2013-09-28 11:33:40 +02:00
|
|
|
#!/usr/bin/env python2
|
2007-08-20 10:50:20 +02:00
|
|
|
|
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
# Copyright (C) 2007, One Laptop Per Child
|
|
|
|
#
|
|
|
|
# This program 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 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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 this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2012-12-09 15:29:45 +01:00
|
|
|
import os
|
2007-08-20 10:50:20 +02:00
|
|
|
import unittest
|
|
|
|
|
2012-12-09 15:29:45 +01:00
|
|
|
from sugar3 import mime
|
2007-08-20 10:50:20 +02:00
|
|
|
|
2012-12-09 15:29:45 +01:00
|
|
|
tests_dir = os.path.dirname(__file__)
|
|
|
|
data_dir = os.path.join(tests_dir, "data")
|
2010-10-15 19:53:25 +02:00
|
|
|
|
2013-05-18 04:52:03 +02:00
|
|
|
|
2007-08-20 10:50:20 +02:00
|
|
|
class TestMime(unittest.TestCase):
|
2012-12-09 15:29:45 +01:00
|
|
|
def test_split_uri_list(self):
|
|
|
|
self.assertSequenceEqual(mime.split_uri_list("http://one\nhttp://two"),
|
|
|
|
("http://one", "http://two"))
|
|
|
|
|
|
|
|
def test_get_mime_parents(self):
|
|
|
|
self.assertListEqual(mime.get_mime_parents("image/svg+xml"),
|
|
|
|
["application/xml"])
|
|
|
|
|
|
|
|
def test_get_for_file(self):
|
|
|
|
self.assertEqual(mime.get_for_file(os.path.join(data_dir, "mime.svg")),
|
|
|
|
'image/svg+xml')
|
|
|
|
|
2007-08-20 10:50:20 +02:00
|
|
|
def test_from_file_name(self):
|
2007-12-12 12:15:43 +01:00
|
|
|
self.assertEqual(mime.get_from_file_name('test.pdf'),
|
2007-08-20 10:50:20 +02:00
|
|
|
'application/pdf')
|
|
|
|
|
|
|
|
def test_choose_most_significant(self):
|
|
|
|
# Mozilla's text in dnd
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['text/plain', 'text/_moz_htmlcontext', 'text/unicode',
|
|
|
|
'text/html', 'text/_moz_htmlinfo'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'text/html')
|
2010-10-15 19:45:11 +02:00
|
|
|
|
2007-08-20 10:50:20 +02:00
|
|
|
# Mozilla's text in c&v
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['text/_moz_htmlcontext',
|
|
|
|
'STRING',
|
|
|
|
'text/html',
|
|
|
|
'text/_moz_htmlinfo',
|
|
|
|
'text/x-moz-url-priv',
|
|
|
|
'UTF8_STRING',
|
|
|
|
'COMPOUND_TEXT'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'text/html')
|
|
|
|
|
|
|
|
# Mozilla gif in dnd
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['application/x-moz-file-promise-url',
|
|
|
|
'application/x-moz-file-promise-dest-filename',
|
|
|
|
'text/_moz_htmlinfo', 'text/x-moz-url-desc',
|
|
|
|
'text/_moz_htmlcontext', 'text/x-moz-url-data',
|
|
|
|
'text/uri-list'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'text/uri-list')
|
|
|
|
|
|
|
|
# Mozilla url in dnd
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['text/_moz_htmlcontext',
|
|
|
|
'text/html',
|
|
|
|
'text/_moz_htmlinfo',
|
|
|
|
'_NETSCAPE_URL',
|
|
|
|
'text/x-moz-url',
|
|
|
|
'text/x-moz-url-desc',
|
|
|
|
'text/x-moz-url-data',
|
|
|
|
'text/plain',
|
|
|
|
'text/unicode'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'text/x-moz-url')
|
|
|
|
|
|
|
|
# Abiword text in dnd
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['text/rtf', 'text/uri-list'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'text/uri-list')
|
|
|
|
|
|
|
|
# Abiword text in c&v
|
2007-12-12 12:15:43 +01:00
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['UTF8_STRING', 'STRING', 'text/html', 'TEXT', 'text/rtf',
|
|
|
|
'COMPOUND_TEXT', 'application/rtf', 'text/plain',
|
|
|
|
'application/xhtml+xml'])
|
2007-08-20 10:50:20 +02:00
|
|
|
self.assertEqual(mime_type, 'application/rtf')
|
|
|
|
|
2007-12-12 12:15:43 +01:00
|
|
|
# Abiword text in c&v
|
|
|
|
mime_type = mime.choose_most_significant(
|
2013-05-18 04:52:03 +02:00
|
|
|
['GTK_TEXT_BUFFER_CONTENTS',
|
|
|
|
'application/x-gtk-text-buffer-rich-text',
|
|
|
|
'UTF8_STRING', 'COMPOUND_TEXT', 'TEXT', 'STRING',
|
|
|
|
'text/plain;charset=utf-8', 'text/plain;charset=UTF-8',
|
|
|
|
'text/plain'])
|
2007-12-12 12:15:43 +01:00
|
|
|
self.assertEqual(mime_type, 'text/plain')
|