-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_converters.py
84 lines (63 loc) · 3.62 KB
/
test_converters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
(c) Peter Sefton 2016
This file is part of Netta.
Netta 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 3 of the License, or
(at your option) any later version.
Netta 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 Netta. If not, see <http://www.gnu.org/licenses/>.
"""
import unittest
import converters
import shutil
import os
class TestLoading(unittest.TestCase):
def cleanup(self):
renditions = os.path.join('test', '_renditions_')
if os.path.exists(renditions):
shutil.rmtree(renditions)
def test_paths(self):
path = "/some/root/path/file_name.docx"
rs = converters.RenditionsStore(path, "/opt/", test_mode=True)
self.assertEqual(rs.renditions_dir, "/opt/_renditions_/some/root/path")
self.assertEqual(rs.pdf_dir, "/opt/_renditions_/some/root/path/pdf")
self.assertEqual(rs.thumb_dir, "/opt/_renditions_/some/root/path/thumbs")
self.assertEqual(rs.thumb_path, "/opt/_renditions_/some/root/path/thumbs/file_name.docx.png")
self.assertEqual(rs.pdf_path, "/opt/_renditions_/some/root/path/pdf/file_name.pdf") #TODO - make this .docx.pdf
home = os.path.expanduser("~")
rs = converters.RenditionsStore(path, test_mode=True)
self.assertEqual(rs.renditions_dir, os.path.join(home, "_renditions_/some/root/path"))
def test_pdf(self):
self.cleanup()
converter_stash = converters.Converters('converters', home = 'test')
self.assertEqual(converter_stash.get_by_ext('.pdf').name, 'PDF')
pdf_converter = converter_stash.get_by_ext('.pdf')("tests/uni-verse.cho.txt_key_C.pdf")
self.assertEqual(pdf_converter.get_metadata()['dc:title'],'Universe')
self.assertEqual(pdf_converter.get_metadata_item('dc:title'),'Universe')
self.assertEqual(pdf_converter.get_mime(),"application/pdf")
self.assertEqual(pdf_converter.renditions_store.thumb_path, "test/_renditions_/tests/thumbs/uni-verse.cho.txt_key_C.pdf.png")
def test_jpg(self):
self.cleanup()
converter_stash = converters.Converters('converters', home = 'test')
self.assertEqual(converter_stash.get_by_ext('.jpg').name, 'Image')
img_converter = converter_stash.get_by_ext('.jpg')("tests/landscape.jpg")
img_converter.get_metadata()
self.assertEqual(img_converter.get_metadata_item('dc:title'),None)
self.assertEqual(img_converter.get_mime(),"image/jpeg")
self.assertEqual(img_converter.renditions_store.thumb_filename, "landscape.jpg.png")
self.assertEqual(img_converter.renditions_store.thumb_path, "test/_renditions_/tests/thumbs/landscape.jpg.png")
self.assertEqual(img_converter.get_viewable(), ("tests/landscape.jpg", "image/jpeg"))
img_converter = converter_stash.get_by_ext('.jpg')("/Users/124411/Dropbox/shillelaghs/all.book.pdf")
self.assertEqual(img_converter.renditions_store.thumb_path, "test/_renditions_/Users/124411/Dropbox/shillelaghs/thumbs/all.book.pdf.png")
def test_office(self):
self.cleanup()
converter_stash = converters.Converters('converters', home = 'test')
self.assertEqual(converter_stash.get_by_ext('.docx').name, 'Office')
self.assertEqual(converter_stash.get_by_ext('.doc').name, 'Office')
if __name__ == '__main__':
unittest.main()