Beispiel #1
0
 def test_get_display_image_path(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     display_path = self.document_file_manager.get_generated_file_path(
         file_info, DISPLAY_IMAGE)
     self.assertTrue("filestorage/archive/1000/tif/display/00000001.png" in
                     display_path)
 def test_update_resolution_missing_tiff(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     self.document_file_manager.get_file_path.side_effect = DocumentFileNotFound(
         file_info)
     self.service._update_resolution(file_info)
     self.assertEqual(300, file_info.resolution)
Beispiel #3
0
 def test_get_thumb_path(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     thumb_path = self.document_file_manager.get_generated_file_path(
         file_info, THUMBNAIL)
     self.assertTrue(
         "filestorage/archive/1000/tif/thumb/00000001.png" in thumb_path)
Beispiel #4
0
 def test_get_pdf_path_3(self):
     document_file_info = DocumentFileInfo(8)
     document_file_info.filetype = 'pdf'
     document_file_info.document_id = 8
     self.document_file_info_dao.get_by_id.return_value = document_file_info
     pdf_path = self.document_file_manager.get_generated_file_path(
         document_file_info, DOCUMENT_PDF)
     self.assertTrue("filestorage/docs/pdf/pdf/00000008.pdf" in pdf_path)
Beispiel #5
0
 def test_get_pdf_path(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     file_info.document_id = 1
     pdf_path = self.document_file_manager.get_generated_file_path(
         file_info, DOCUMENT_PDF)
     self.assertTrue(
         "filestorage/archive/1000/tif/pdf/00000001.pdf" in pdf_path)
Beispiel #6
0
 def add_document_file(self, document, file):
     file_info = DocumentFileInfo(len(self.file_infos[document]) + 1)
     filetype, res = self.file_format_service.get_format_and_resolution(
         file)
     file_info.filetype = filetype
     file_info.resolution = res
     file_info.document_id = document.id
     self.file_infos[document].append(file_info)
Beispiel #7
0
 def test_get_file_path_for_non_existing_file(self):
     document_file_info = DocumentFileInfo(2)
     document_file_info.filetype = "txt"
     exception_raised = False
     try:
         self.document_file_manager.get_file_path(document_file_info)
     except DocumentFileNotFound:
         exception_raised = True
     self.assertTrue(exception_raised)
    def testRealLifeTexts(self):
        doc = Document(5)
        file_info1 = DocumentFileInfo(5)
        file_info1.filetype = 'txt'
        file1 = os.path.join(self.text_base_dir, "00000005.txt")
        file_info2 = DocumentFileInfo(10)
        file_info2.filetype = 'txt'
        file2 = os.path.join(self.text_base_dir, "00000011.txt")
        file_info3 = DocumentFileInfo(11)
        file_info3.filetype = 'txt'
        file3 = os.path.join(self.text_base_dir, "00000012.txt")

        values = {file_info1: file1, file_info2: file2, file_info3: file3}

        def side_effect(arg):
            return values[arg]

        self.document_file_info_dao.get_file_infos_for_document.return_value = [
            file_info1, file_info2, file_info3
        ]
        self.document_file_manager.get_file_path.side_effect = side_effect

        pdf = self.document_pdf_generation_service.generate_document_pdf(doc)
        self.tmp_file.write(pdf)

        self.document_file_info_dao.get_file_infos_for_document.assert_called_with(
            5)
        self.document_file_manager.get_file_path.assert_has_calls(
            (call(file_info1), call(file_info2), call(file_info3)))
Beispiel #9
0
 def __init__(self):
     config = Config(os.path.join(get_testfiles_dir(), "testconfig.xml"))
     self.file_format_service = FileFormatService(config)
     self.file_infos = {}
     document = Document(1)
     self.file_infos[document] = []
     file_info = DocumentFileInfo(1)
     file_info.document_id = 1
     file_info.filetype = "tif"
     file_info.resolution = 300
     self.file_infos[document].append(file_info)
Beispiel #10
0
    def test_add_new_file_non_existing_target_dir(self):
        target = os.path.join(self.env.tmpdir.name, "newjpgfile.jpg")

        shutil.copy(os.path.join(get_testfiles_dir(), "testfile.jpg"), target)
        self.assertTrue(os.path.isfile(target))
        document_file_info = DocumentFileInfo(4711)
        document_file_info.filetype = 'jpg'
        self.document_file_manager.add_file(target, document_file_info)
        self.assertFalse(os.path.isfile(target))
        self.assertEqual("jpg", document_file_info.filetype)
        new_path = os.path.join(os.path.join(self.env.document_dir, "jpg"),
                                "00004711.jpg")
        self.assertTrue(os.path.isfile(new_path))
    def testMissingHandler(self):
        doc = Document(1)
        file_info = DocumentFileInfo(2)
        file_info.filetype = 'xls'

        self.document_file_info_dao.get_file_infos_for_document.return_value = [
            file_info
        ]

        pdf = self.document_pdf_generation_service.generate_document_pdf(doc)
        self.tmp_file.write(pdf)

        self.document_file_info_dao.get_file_infos_for_document.assert_called_with(
            1)
Beispiel #12
0
    def test_display_image_generation_unsupported_filetype(self):

        document_file_manager = MagicMock(spec=DocumentFileManager)
        document_file_manager.get_generated_file.side_effect = FileNotFoundError(
        )
        self.file_provider = FileProvider(document_file_manager,
                                          self.document_file_info_dao,
                                          self.document_pdf_generation_service,
                                          self.document_file_image_generator)
        document_file_info = DocumentFileInfo(27)
        document_file_info.filetype = 'xls'
        display_image = self.file_provider.get_display_image(
            document_file_info)

        self.assertEquals(b'\x89PNG\r\n', display_image[0:6])
    def testDelete(self):

        document = Document(1)

        file_infos = []
        file_infos.append(DocumentFileInfo(2))
        file_infos.append(DocumentFileInfo(3))
        self.document_file_info_dao.get_file_infos_for_document = MagicMock(
            return_value=file_infos)
        self.document_dao.delete = MagicMock()

        self.service.delete(document)

        self.document_file_manager.delete_file.call_args_list = [
            call(file_infos[0]), call(file_infos[1])
        ]
        self.document_dao.delete.assert_called_once_with(1)
Beispiel #14
0
    def test_get_file_path(self):
        file_info = DocumentFileInfo(5)
        file_info.filetype = "txt"
        file_path = self.document_file_manager.get_file_path(file_info)
        self.assertEqual(file_path, self.env.file_paths[5])

        file_info = DocumentFileInfo(6)
        file_info.filetype = "jpg"
        file_path = self.document_file_manager.get_file_path(file_info)
        self.assertEqual(file_path, self.env.file_paths[6])

        file_info = DocumentFileInfo(1)
        file_info.filetype = "tif"
        file_path = self.document_file_manager.get_file_path(file_info)
        self.assertEqual(file_path, self.env.file_paths[1])
    def test_get_file_infos_for_document(self):

        document = Document(1)
        self.document_file_info_dao.get_file_infos_for_document.return_value = [
            DocumentFileInfo(1)
        ]
        file_infos = self.service.get_file_infos_for_document(document)
        self.assertEqual(1, len(file_infos))
        self.document_file_info_dao.get_file_infos_for_document.assert_called_once_with(
            1)
Beispiel #16
0
 def test_get_pdf_path_2(self):
     document_file_info = DocumentFileInfo(1)
     document_file_info.filetype = 'tif'
     document_file_info.document_id = 1
     file_info = DocumentFileInfo(3)
     file_info.filetype = 'gif'
     file_info.document_id = 1
     self.document_file_info_dao.get_by_id.return_value = document_file_info
     pdf_path = self.document_file_manager.get_generated_file_path(
         file_info, DOCUMENT_PDF)
     self.assertTrue(
         "filestorage/archive/1000/tif/pdf/00000001.pdf" in pdf_path)
    def test_add_document_file_working(self):

        test_file = os.path.join(get_testfiles_dir(), "testfile.jpg")
        document = Document(1)
        file_info = DocumentFileInfo(1)

        self.document_file_info_dao.create_new_file_info.return_value = file_info

        self.service.add_document_file(document, test_file)

        self.document_file_manager.add_file.assert_called_once_with(
            test_file, file_info)
Beispiel #18
0
    def append_file_info(self, id, filetype, resolution, page, document_id):

        info = DocumentFileInfo(id)
        info.filetype = filetype
        info.resolution = resolution
        info.page = page
        info.document_id = document_id
        self.document_file_infos.append(info)
    def test_replace_document_file_working(self):

        # Prepare input
        test_file = os.path.join(get_testfiles_dir(), "testfile.jpg")

        file_info = DocumentFileInfo(1)
        file_info.filetype = 'gif'
        file_info.resolution = 72

        # Prepare mock
        self.document_file_info_dao.create_new_file_info.return_value = file_info

        # And action!
        self.service.replace_document_file(file_info, test_file)

        # Assert
        self.document_file_manager.delete_file.assert_called_once_with(
            file_info)
        self.document_file_info_dao.save.assert_called_once_with(file_info)
        self.document_file_manager.add_file.assert_called_once_with(
            test_file, file_info)
        self.assertEqual('jpg', file_info.filetype)
        self.assertEqual(400, file_info.resolution)
    def test_add_document_file_not_working(self):

        test_file = os.path.join(get_testfiles_dir(), "testfile.jpg")
        document = Document(1)
        file_info = DocumentFileInfo(1)

        self.document_file_info_dao.create_new_file_info.return_value = file_info
        self.document_file_manager.add_file.side_effect = FileNotFoundError()
        self.document_file_manager.delete_file.side_effect = Exception()

        exception_raised = False
        try:
            self.service.add_document_file(document, test_file)
        except FileNotFoundError:
            exception_raised = True
        self.assertTrue(exception_raised)

        self.document_file_manager.add_file.assert_called_once_with(
            test_file, file_info)
        self.document_file_manager.delete_file.assert_called_once_with(
            file_info)
        self.document_file_info_dao.delete.assert_called_once_with(
            file_info.id)
 def test_update_resolution_tiff(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     self.document_file_manager.get_file_path.return_value = self.env.tif_file_path
     self.service._update_resolution(file_info)
     self.assertEqual(72.0, file_info.resolution)
    def test_filename_generation(self):

        info = DocumentFileInfo(4711)
        info.filetype = "txt"
        self.assertEqual(info.get_file_name(), "00004711.txt")
    def test_string_generation_new_info(self):

        info = DocumentFileInfo()
        info.filetype = "txt"
        self.assertEqual("%s" % info, "New document file info")
    def test_string_generation(self):

        info = DocumentFileInfo(4711)
        info.filetype = "txt"
        self.assertEqual("%s" % info, "00004711.txt")
 def test_update_resolution_gif(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'gif'
     self.service._update_resolution(file_info)
     self.assertEqual(300, file_info.resolution)
 def test_no_resolution_update_necessary(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'tif'
     file_info.resolution = 666
     self.service._update_resolution(file_info)
     self.assertEqual(666, file_info.resolution)
 def test_get_file_info_by_id(self):
     file_info = DocumentFileInfo(1)
     file_info.filetype = 'gif'
     self.document_file_info_dao.get_by_id.return_value = file_info
     file_info = self.service.get_file_info_by_id(1)
     self.assertEqual(300, file_info.resolution)
 def test_get_file_for_file_info(self):
     file_info = DocumentFileInfo(4)
     self.document_file_manager.get_file_path.return_value = "/some/path"
     path = self.service.get_file_for_file_info(file_info)
     self.assertEqual(path, "/some/path")
 def test_get_display_image(self):
     document_file_info = DocumentFileInfo(1)
     self.service.get_display_image(document_file_info)
     self.document_file_provider.get_display_image.assert_called_once_with(
         document_file_info)
 def test_get_thumbnail(self):
     document_file_info = DocumentFileInfo(1)
     self.service.get_thumbnail(document_file_info)
     self.document_file_provider.get_thumbnail.assert_called_once_with(
         document_file_info)