def test_binary_eh(self): self.assertFalse(Type('text/plain').is_binary) self.assertTrue(Type('image/jpeg').is_binary) self.assertTrue(Type('application/x-msword').is_binary) self.assertFalse(Type('text/vCard').is_binary) self.assertTrue(Type('application/pkcs7-mime').is_binary) self.assertTrue(self.zip_type.is_binary)
def test_sub_type(self): self.assertEqual(Type('text/plain').sub_type, 'plain') self.assertEqual(Type('image/jpeg').sub_type, 'jpeg') self.assertEqual(Type('application/x-msword').sub_type, 'msword') self.assertEqual(Type('text/vCard').sub_type, 'vcard') self.assertEqual(Type('application/pkcs7-mime').sub_type, 'pkcs7-mime') self.assertEqual(self.zip_type.sub_type, 'zip')
def test_content_type(self): self.assertEqual(Type('text/plain').content_type, 'text/plain') self.assertEqual(Type('image/jpeg').content_type, 'image/jpeg') self.assertEqual( Type('application/x-msword').content_type, 'application/x-msword') self.assertEqual(Type('text/vCard').content_type, 'text/vCard') self.assertEqual( Type('application/pkcs7-mime').content_type, 'application/pkcs7-mime') self.assertEqual(self.zip_type.content_type, 'x-appl/x-zip')
def test_class_index_1(self): text_plain = Type('text/plain') text_plain.encoding = '8bit' text_plain.extensions = 'asc txt c cc h hh cpp hpp dat hlp'.split() text_plain_vms = Type('text/plain') text_plain_vms.encoding = '8bit' text_plain_vms.extensions = ['doc'] text_plain_vms.system = 'vms' self.assertEqual(Types['text/plain'], [text_plain, text_plain_vms])
def test_like_eh(self): self.assertTrue(Type('text/plain').is_like(Type('text/plain'))) self.assertTrue(Type('text/plain').is_like(Type('text/x-plain'))) self.assertFalse(Type('text/plain').is_like(Type('image/jpeg'))) self.assertTrue(Type('text/plain').is_like('text/plain')) self.assertTrue(Type('text/plain').is_like('text/x-plain')) self.assertFalse(Type('text/plain').is_like('image/jpeg'))
def test_class_from_hash(self): yaml = Type.from_hash({'Content-Type': 'text/x-yaml', 'Content-Transfer-Encoding': '8bit', 'System': 'd9d172f608', 'Extensions': ['yaml', 'yml']}) self.assertTrue(isinstance(yaml, Type)) self.assertEqual('text/yaml', yaml.simplified)
def test_class_from_hash(self): yaml = Type.from_hash({ 'Content-Type': 'text/x-yaml', 'Content-Transfer-Encoding': '8bit', 'System': 'd9d172f608', 'Extensions': ['yaml', 'yml'] }) self.assertTrue(isinstance(yaml, Type)) self.assertEqual('text/yaml', yaml.simplified)
def test_class_index_2(self): re_type = re.compile('bmp$') tst_bmp = Types['image/x-bmp'] + Types['image/vnd.wap.wbmp'] + Types['image/x-win-bmp'] self.assertEqual(sorted(tst_bmp), sorted(Types[re_type])) Types['image/bmp'][0].system = PLATFORM self.assertEqual([Type.from_array('image/x-bmp', ['bmp'])], Types.m(re_type, {'platform': True}))
def test_encoding(self): self.assertEqual(Type('text/plain').encoding, 'quoted-printable') self.assertEqual(Type('image/jpeg').encoding, 'base64') self.assertEqual(Type('application/x-msword').encoding, 'base64') self.assertEqual(Type('text/vCard').encoding, 'quoted-printable') self.assertEqual(Type('application/pkcs7-mime').encoding, 'base64') yaml = self.yaml_mime_type_from_array self.assertEqual(yaml.encoding, '8bit') yaml.encoding = 'base64' self.assertEqual(yaml.encoding, 'base64') yaml.encoding = 'default' self.assertEqual(yaml.encoding, 'quoted-printable') def raise_func(yaml): yaml.encoding = 'binary' self.assertRaises(TypeError, raise_func, yaml) self.assertEqual(self.zip_type.encoding, 'base64')
def test_class_index_2(self): re_type = re.compile('bmp$') tst_bmp = Types['image/x-bmp'] + Types['image/vnd.wap.wbmp'] + Types[ 'image/x-win-bmp'] self.assertEqual(sorted(tst_bmp), sorted(Types[re_type])) Types['image/bmp'][0].system = PLATFORM self.assertEqual([Type.from_array('image/x-bmp', ['bmp'])], Types.m(re_type, {'platform': True}))
def test_class_constructors(self): self.assertTrue(self.zip_type is not None) yaml = Type('text/x-yaml') yaml.extensions = ['yaml', 'yml'] yaml.encoding = '8bit' yaml.system = 'd9d172f608' self.assertTrue(isinstance(yaml, Type)) def error_content_type(ct): return Type(ct) self.assertRaises(InvalidContentType, error_content_type, 'apps') self.assertRaises(InvalidContentType, error_content_type, None)
def test_simplified(self): self.assertEqual(Type.simplify('text/plain'), 'text/plain') self.assertEqual(Type.simplify('image/jpeg'), 'image/jpeg') self.assertEqual(Type.simplify('application/x-msword'), 'application/msword') self.assertEqual(Type.simplify('text/vCard'), 'text/vcard') self.assertEqual(Type.simplify('application/pkcs7-mime'), 'application/pkcs7-mime') self.assertEqual(self.zip_type.simplified, 'appl/zip') self.assertEqual(Type.simplify('x-xyz/abc'), 'xyz/abc')
def test_media_type(self): self.assertEqual(Type('text/plain').media_type, 'text') self.assertEqual(Type('image/jpeg').media_type, 'image') self.assertEqual( Type('application/x-msword').media_type, 'application') self.assertEqual(Type('text/vCard').media_type, 'text') self.assertEqual( Type('application/pkcs7-mime').media_type, 'application') self.assertEqual(Type('x-chemical/x-pdb').media_type, 'chemical') self.assertEqual(self.zip_type.media_type, 'appl')
def test_class_from_mime_type(self): zip2 = Type.from_mime_type(self.zip_type) self.assertTrue(isinstance(zip2, Type)) self.assertEqual('appl/zip', self.zip_type.simplified) self.assertNotEqual(id(self.zip_type), id(zip2))
def yaml_mime_type_from_array(self): return Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit', 'd9d172f608')
def test_signature_eh(self): self.assertFalse(Type('text/plain').is_signature) self.assertFalse(Type('image/jpeg').is_signature) self.assertFalse(Type('application/x-msword').is_signature) self.assertTrue(Type('text/vCard').is_signature) self.assertTrue(Type('application/pkcs7-mime').is_signature)
def test_CMP(self): self.assertEqual(Type('text/plain'), Type('text/plain')) self.assertNotEqual(Type('text/plain'), Type('image/jpeg')) self.assertEqual(Type('text/plain').to_s, 'text/plain') self.assertNotEqual(Type('text/plain').to_s, 'image/jpeg') self.assertTrue(Type('text/plain') > Type('text/html')) self.assertTrue(Type('text/plain') > 'text/html') self.assertTrue(Type('text/html') < Type('text/plain')) self.assertTrue(Type('text/html') < 'text/plain') self.assertEqual('text/html', Type('text/html').to_s) self.assertTrue('text/html' < Type('text/plain')) self.assertTrue('text/plain' > Type('text/html'))
def test_eql(self): self.assertTrue(Type('text/plain') == Type('text/plain')) self.assertFalse(Type('text/plain') == Type('image/jpeg')) self.assertFalse(Type('text/plain') == 'text/plain') self.assertFalse(Type('text/plain') == 'image/jpeg')
def error_content_type(ct): return Type(ct)
def test_class_add(self): eruby = Type('application/x-eruby') eruby.extensions = 'rhtml' eruby.encoding = '8bit' Types.add(eruby) self.assertEqual(Types['application/x-eruby'], [eruby])
def setUp(self): zip_type = Type('x-appl/x-zip') zip_type.extensions = ['zip', 'zp'] self.zip_type = zip_type
def test_to_s(self): self.assertEqual(Type('text/plain').to_s, 'text/plain') self.assertEqual(str(Type('text/plain')), 'text/plain')