Ejemplo n.º 1
0
 def test_tif_file_supported_resolution(self):
     
     self.service.allowed_resolutions['tif'] = [72, 300, 400]
     
     file = os.path.join(get_testfiles_dir(), "testfile.tif")
     file_format, res = self.service.get_format_and_resolution(file)
     self.assertEqual('tif', file_format)
     self.assertEqual(72, res)
 def testConfigWithErrors(self):
     config_file = os.path.join(get_testfiles_dir(), "testconfig_witherrors.xml")
     exception_raised = False
     try:
         self.config = Config(config_file)
     except Exception as e:
         exception_raised = True
         self.assertEqual("Configuration needs exactly 1 configuration node", e.args[0])
     self.assertTrue(exception_raised)
Ejemplo n.º 3
0
    def test_file_format_aliases(self):
        
        self.service.supported_formats = ['tiff']
        self.service.format_aliases = {'tif': 'tiff'}
        self.service.resolution_handlers = {'tiff': get_graphic_file_resolution}

        file = os.path.join(get_testfiles_dir(), "testfile.tif")
        file_format, res = self.service.get_format_and_resolution(file)
        self.assertEqual('tiff', file_format)
        self.assertEqual(72, res)
Ejemplo n.º 4
0
 def test_unsupported_format_file(self):
     self.service.supported_formats = ['tif', 'jpg']
     file = os.path.join(get_testfiles_dir(), "testfile.gif")
     exception_raised = False
     try:
         self.service.get_format_and_resolution(file)
     except UnsupportedFileFormat as e:
         self.assertEqual('gif', e.file_format)
         exception_raised = True
     self.assertTrue(exception_raised)
Ejemplo n.º 5
0
 def test_tif_file_unsupported_resolution(self):
     
     file = os.path.join(get_testfiles_dir(), "testfile.tif")
     exception_raised = False
     try:
         self.service.get_format_and_resolution(file)
     except UnsupportedFileResolution as e:
         self.assertEqual(e.x_resolution, 72)
         exception_raised = True
     self.assertTrue(exception_raised)
Ejemplo n.º 6
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)
    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)
Ejemplo n.º 8
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 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_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 setUp(self):

        self.env = TestEnvironment(mode=MODE_FULL)

        self.document_file_manager = MagicMock(spec=DocumentFileManager)
        self.document_file_info_dao = MagicMock(spec=DocumentFileInfoDao)
        self.graphics_pdf_handler = GraphicsPdfHandler(
            self.document_file_manager)
        self.txt_pdf_handler = TextPdfHandler(self.document_file_manager)
        handlers = {
            'jpg': self.graphics_pdf_handler,
            'tif': self.graphics_pdf_handler,
            'gif': self.graphics_pdf_handler,
            'txt': self.txt_pdf_handler
        }
        self.document_pdf_generation_service = DocumentPdfGenerationService(
            self.document_file_info_dao, self.document_file_manager, handlers)

        self.text_base_dir = os.path.join(
            os.path.join(os.path.join(get_testfiles_dir(), "filestorage"),
                         "docs"), "txt")
        self.tmp_file = tempfile.NamedTemporaryFile(suffix='.pdf',
                                                    delete=not manual_check)
Ejemplo n.º 12
0
 def test_jpeg_file(self):
     file = os.path.join(get_testfiles_dir(), "testfile.jpg")
     file_format, res = self.service.get_format_and_resolution(file)
     self.assertEqual('jpg', file_format)
     self.assertEqual(400, res)
Ejemplo n.º 13
0
 def test_gif_file(self):
             
     file = os.path.join(get_testfiles_dir(), "testfile.gif")
     file_format, res = self.service.get_format_and_resolution(file)
     self.assertEqual('gif', file_format)
     self.assertEqual(300, res)
Ejemplo n.º 14
0
 def get_file_for_file_info(self, file_info):
     return os.path.join(get_testfiles_dir(), "testfile.jpg")
 def setUp(self):
     config_file = os.path.join(get_testfiles_dir(), "testconfig.xml")
     self.config = Config(config_file)
Ejemplo n.º 16
0
    def create_mocks_and_stubs(self):

        self.test_file = os.path.join(get_testfiles_dir(), "testfile.pdf")
        self.test_file_info = DocumentFileInfo()
        self.test_file_info.resolution = 300