Beispiel #1
0
    def testCacheSubdir (self):
        attach = Attachment (self.testPage)
        hashCalculator = WikiHashCalculator (Application)
        hash_src = hashCalculator.getHash (self.testPage)

        # Добавим файл в dir
        with open (os.path.join (attach.getAttachPath(), "dir", "temp.tmp"), "w") as fp:
            fp.write ("bla-bla-bla")

        hash2 = hashCalculator.getHash (self.testPage)
        self.assertNotEqual (hash_src, hash2)

        # Добавим еще одну вложенную директорию
        subdir = os.path.join (attach.getAttachPath(), "dir", "subdir_2")
        os.mkdir (subdir)

        hash3 = hashCalculator.getHash (self.testPage)
        self.assertNotEqual (hash2, hash3)
        self.assertNotEqual (hash_src, hash3)

        # Добавим файл в dir/subdir_2
        with open (os.path.join (subdir, "temp2.tmp"), "w") as fp:
            fp.write ("bla-bla-bla")

        hash4 = hashCalculator.getHash (self.testPage)
        self.assertNotEqual (hash3, hash4)
        self.assertNotEqual (hash2, hash4)
        self.assertNotEqual (hash_src, hash4)
Beispiel #2
0
    def testCacheSubdir (self):
        attach = Attachment (self.testPage)

        # Только создали страницу, кешировать нельзя
        generator = HtmlGenerator (self.testPage)
        self.assertFalse (generator.canReadFromCache())

        generator.makeHtml (Style().getPageStyle (self.testPage))
        # После того, как один раз сгенерили страницу, если ничего не изменилось, можно кешировать
        self.assertTrue (generator.canReadFromCache())

        # Добавим файл в dir
        with open (os.path.join (attach.getAttachPath(), "dir", "temp.tmp"), "w" ) as fp:
            fp.write ("bla-bla-bla")

        self.assertFalse (generator.canReadFromCache())

        # Добавим еще одну вложенную директорию
        subdir = os.path.join (attach.getAttachPath(), "dir", "subdir_2")
        os.mkdir (subdir)
        self.assertFalse (generator.canReadFromCache())

        generator.makeHtml (Style().getPageStyle (self.testPage))

        # Добавим файл в dir/subdir_2
        with open (os.path.join (subdir, "temp2.tmp"), "w" ) as fp:
            fp.write ("bla-bla-bla")

        self.assertFalse (generator.canReadFromCache())
Beispiel #3
0
    def testCacheSubdir(self):
        attach = Attachment(self.testPage)

        # Только создали страницу, кешировать нельзя
        cache = HtmlCache(self.testPage, Application)
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # После того, как один раз сгенерили страницу, если ничего не изменилось, можно кешировать
        self.assertTrue(cache.canReadFromCache())

        # Добавим файл в dir
        with open(os.path.join(attach.getAttachPath(), "dir", "temp.tmp"),
                  "w") as fp:
            fp.write("bla-bla-bla")

        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # Добавим еще одну вложенную директорию
        subdir = os.path.join(attach.getAttachPath(), "dir", "subdir_2")
        os.mkdir(subdir)
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # Добавим файл в dir/subdir_2
        with open(os.path.join(subdir, "temp2.tmp"), "w") as fp:
            fp.write("bla-bla-bla")

        self.assertFalse(cache.canReadFromCache())
Beispiel #4
0
    def testCacheSubdir(self):
        attach = Attachment(self.testPage)

        # Только создали страницу, кешировать нельзя
        cache = HtmlCache(self.testPage, self.application)
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # После того, как один раз сгенерили страницу, если ничего не
        # изменилось, можно кешировать
        self.assertTrue(cache.canReadFromCache())

        # Добавим файл в dir
        with open(os.path.join(attach.getAttachPath(), "dir", "temp.tmp"), "w") as fp:
            fp.write("bla-bla-bla")

        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # Добавим еще одну вложенную директорию
        subdir = os.path.join(attach.getAttachPath(), "dir", "subdir_2")
        os.mkdir(subdir)
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        # Добавим файл в dir/subdir_2
        with open(os.path.join(subdir, "temp2.tmp"), "w") as fp:
            fp.write("bla-bla-bla")

        self.assertFalse(cache.canReadFromCache())
Beispiel #5
0
    def testGetFullPath3 (self):
        attach = Attachment (self.page)
        fname = u"Имя файла.ext"

        path_full = attach.getFullPath (fname, create=True)
        path_right = os.path.join (attach.getAttachPath(), fname)

        self.assertTrue (os.path.exists (attach.getAttachPath()))
        self.assertEqual (path_full, path_right)
Beispiel #6
0
    def __testAttachment(self, page):
        attach = Attachment(page)
        if not os.path.exists(attach.getAttachPath()):
            return False

        lowerPhrase = self.phrase.lower()

        for root, subfolders, files in os.walk(attach.getAttachPath()):
            filterfiles = ([fname for fname in files if lowerPhrase in fname.lower()])
            filterdirs = ([dirname for dirname in subfolders if lowerPhrase in dirname.lower()])

            if (len(filterfiles) != 0 or len(filterdirs) != 0):
                return True

        return False
Beispiel #7
0
    def __testAttachment (self, page):
        attach = Attachment (page)
        if not os.path.exists (attach.getAttachPath()):
            return False

        lowerPhrase = self.phrase.lower()

        for root, subfolders, files in os.walk(attach.getAttachPath()):
            filterfiles = (filter (lambda fname: lowerPhrase in fname.lower(), files))
            filterdirs = (filter (lambda dirname: lowerPhrase in dirname.lower(), subfolders))

            if (len (filterfiles) != 0 or len (filterdirs) != 0):
                return True

        return False
Beispiel #8
0
    def _sortFiles (self, names, params_dict):
        """
        Отсортировать дочерние страницы, если нужно
        """
        attach = Attachment (self.parser.page)
        names_full = [os.path.join (attach.getAttachPath(), name) for name in names]

        if u"sort" not in params_dict:
            names.sort (Attachment.sortByName)
            return

        sort = params_dict["sort"].lower()

        if sort == u"name":
            names.sort (Attachment.sortByName)
        elif sort == u"descendname":
            names.sort (Attachment.sortByName, reverse=True)
        elif sort == u"ext":
            names.sort (Attachment.sortByExt)
        elif sort == u"descendext":
            names.sort (Attachment.sortByExt, reverse=True)
        elif sort == u"size":
            names.sort (attach.sortBySizeRelative)
        elif sort == u"descendsize":
            names.sort (attach.sortBySizeRelative, reverse=True)
        elif sort == u"date":
            names.sort (attach.sortByDateRelative)
        elif sort == u"descenddate":
            names.sort (attach.sortByDateRelative, reverse=True)
        else:
            names.sort (Attachment.sortByName)
Beispiel #9
0
    def __getDirContent (self, page, filescontent, dirname="."):
        """
        Сформировать строку для расчета хеша по данным вложенной поддиректории dirname (путь относительно __attach)
        page - страница, для которой собираем список вложений
        filescontent - список, содержащий строки, описывающие вложенные файлы
        """
        attach = Attachment (page)
        attachroot = attach.getAttachPath()

        attachlist = attach.getAttachRelative (dirname)
        attachlist.sort (Attachment.sortByName)

        for fname in attachlist:
            fullpath = os.path.join (attachroot, dirname, fname)

            # Пропустим директории, которые начинаются с __
            if not os.path.isdir (fname) or not fname.startswith ("__"):
                try:
                    filescontent.write (fname.encode (self._unicodeEncoding))
                    filescontent.write (unicode (os.stat (fullpath).st_mtime))

                    if os.path.isdir (fullpath):
                        self.__getDirContent (page, filescontent, os.path.join (dirname, fname))
                except OSError:
                    # Если есть проблемы с доступом к файлу, то здесь на это не будем обращать внимания
                    pass
Beispiel #10
0
    def testAttachPath4 (self):
        attach = Attachment (self.page)

        # Получить путь до прикрепленных файлов, создав ее
        path = attach.getAttachPath(create=True)
        # Вложенных файлов еще нет, поэтому нет и папки
        self.assertTrue (os.path.exists (path))
Beispiel #11
0
    def testAttachPath2 (self):
        attach = Attachment (self.page)

        # Получить путь до прикрепленных файлов, не создавая ее
        path = attach.getAttachPath()
        # Вложенных файлов еще нет, поэтому нет и папки
        self.assertFalse (os.path.exists (path))
Beispiel #12
0
    def __getDirContent(self, page, filescontent, dirname="."):
        """
        Сформировать строку для расчета хеша по данным вложенной поддиректории dirname (путь относительно __attach)
        page - страница, для которой собираем список вложений
        filescontent - список, содержащий строки, описывающие вложенные файлы
        """
        attach = Attachment(page)
        attachroot = attach.getAttachPath()

        attachlist = attach.getAttachRelative(dirname)
        attachlist.sort(key=str.lower)

        for fname in attachlist:
            fullpath = os.path.join(attachroot, dirname, fname)

            # Пропустим директории, которые начинаются с __
            if not os.path.isdir(fname) or not fname.startswith("__"):
                try:
                    filescontent.write(fname)
                    filescontent.write(str(os.stat(fullpath).st_mtime))

                    if os.path.isdir(fullpath):
                        self.__getDirContent(page, filescontent,
                                             os.path.join(dirname, fname))
                except OSError:
                    # Если есть проблемы с доступом к файлу, то здесь на это не
                    # будем обращать внимания
                    pass
Beispiel #13
0
    def _getGlobalVariables(self, selectedText, page):
        globals = {
            defines.VAR_DATE: datetime.now(),
        }

        if page is not None:
            attach = Attachment(page)
            attachList = VarList([fname
                                  for fname
                                  in sorted(attach.getAttachRelative())
                                  if not fname.startswith(u'__')])

            globals_page = {
                defines.VAR_SEL_TEXT: selectedText,
                defines.VAR_TITLE: page.display_title,
                defines.VAR_SUBPATH: page.subpath,
                defines.VAR_ATTACH: attach.getAttachPath(True),
                defines.VAR_FOLDER: page.path,
                defines.VAR_PAGE_ID: self._application.pageUidDepot.createUid(page),
                defines.VAR_DATE_CREATING: page.creationdatetime,
                defines.VAR_DATE_EDITIND: page.datetime,
                defines.VAR_TAGS: VarList(sorted(page.tags)),
                defines.VAR_PAGE_TYPE: page.getTypeString(),
                defines.VAR_CHILDLIST: VarList([subpage.title
                                                for subpage
                                                in page.children]),
                defines.VAR_ATTACHLIST: attachList,
            }
            globals.update(globals_page)

        return globals
Beispiel #14
0
    def execute (self, params, content):
        params_dict = Command.parseParams (params)
        attach = Attachment (self.parser.page)

        attachlist = attach.getAttachRelative ()
        attachpath = attach.getAttachPath()

        (dirs, files) = self.separateDirFiles (attachlist, attachpath)

        self._sortFiles (dirs, params_dict)
        self._sortFiles (files, params_dict)

        return SimpleView.make (dirs + files, attachpath)
Beispiel #15
0
    def _attach_files(self, page, files_list):
        '''
        Copy files to attachments without explicit
            onAttachListChanged event calling.
        '''
        files_full = [
            os.path.join(self._sample_path, fname) for fname in files_list
        ]

        attach = Attachment(page)
        attach_path = attach.getAttachPath(True)
        for fname in files_full:
            shutil.copy(fname, attach_path)
Beispiel #16
0
    def execute (self, params, content):
        params_dict = Command.parseParams (params)
        attach = Attachment (self.parser.page)

        attachlist = attach.getAttachRelative ()
        attachpath = attach.getAttachPath()

        (dirs, files) = self.separateDirFiles (attachlist, attachpath)

        self._sortFiles (dirs, params_dict)
        self._sortFiles (files, params_dict)

        return SimpleView.make (dirs + files, attachpath)
Beispiel #17
0
    def _attach_files(self, page, files_list):
        '''
        Copy files to attachments without explicit
            onAttachListChanged event calling.
        '''
        files_full = [os.path.join(self._sample_path, fname)
                      for fname
                      in files_list]

        attach = Attachment(page)
        attach_path = attach.getAttachPath(True)
        for fname in files_full:
            shutil.copy(fname, attach_path)
Beispiel #18
0
    def test_remove_empty_attach_dir(self):
        self._application.wikiroot = self.wikiroot
        self._application.selectedPage = self.page_01

        attach = Attachment(self.page_01)
        attach_dir = attach.getAttachPath(True)

        watcher = AttachWatcher(self._application, self._period_ms)
        watcher.initialize()

        shutil.rmtree(attach_dir)

        wx.MilliSleep(500)
        self.myYield()
        watcher.clear()
        self.assertEqual(self._eventCount, 0)
Beispiel #19
0
    def test_remove_empty_attach_dir(self):
        self._application.wikiroot = self.wikiroot
        self._application.selectedPage = self.page_01

        attach = Attachment(self.page_01)
        attach_dir = attach.getAttachPath(True)

        watcher = AttachWatcher(self._application, self._period_ms)
        watcher.initialize()

        shutil.rmtree(attach_dir)

        wx.MilliSleep(500)
        self.myYield()
        watcher.clear()
        self.assertEqual(self._eventCount, 0)
Beispiel #20
0
    def OnDropFiles(self, _x, _y, files):
        assert self._application.selectedPage is not None

        if len(files) == 1 and '\n' in files[0]:
            files = files[0].split('\n')

        file_protocol = 'file://'

        # Prepare absolute path for attach folder
        attach = Attachment(self._application.selectedPage)
        attach_path = os.path.realpath(
            os.path.abspath(attach.getAttachPath(False)))

        if not attach_path.endswith(os.sep):
            attach_path += os.sep

        correctedFiles = []
        is_attached = False

        for fname in files:
            if not fname.strip():
                continue

            # Remove file:// protocol
            if fname.startswith(file_protocol):
                fname = fname[len(file_protocol):]

            corrected_fname = os.path.realpath(os.path.abspath(fname))

            # Is attached file?
            prefix = os.path.commonprefix([corrected_fname, attach_path])
            if prefix == attach_path:
                is_attached = True
                corrected_fname = corrected_fname[len(prefix):]

            correctedFiles.append(corrected_fname)

        if is_attached:
            self._application.onAttachmentPaste(correctedFiles)
        else:
            text = ' '.join(correctedFiles)
            self._editor.replaceText(text)

        return True
Beispiel #21
0
    def _getGlobalVariables(self, selectedText, page):
        globals = {
            defines.VAR_DATE: datetime.now(),
        }

        if page is not None:
            attach = Attachment(page)
            attachList = VarList([
                fname for fname in sorted(attach.getAttachRelative())
                if not fname.startswith(u'__')
            ])

            globals_page = {
                defines.VAR_SEL_TEXT:
                selectedText,
                defines.VAR_TITLE:
                page.display_title,
                defines.VAR_SUBPATH:
                page.subpath,
                defines.VAR_ATTACH:
                attach.getAttachPath(True),
                defines.VAR_FOLDER:
                page.path,
                defines.VAR_PAGE_ID:
                self._application.pageUidDepot.createUid(page),
                defines.VAR_DATE_CREATING:
                page.creationdatetime,
                defines.VAR_DATE_EDITIND:
                page.datetime,
                defines.VAR_TAGS:
                VarList(sorted(page.tags)),
                defines.VAR_PAGE_TYPE:
                page.getTypeString(),
                defines.VAR_CHILDLIST:
                VarList([subpage.title for subpage in page.children]),
                defines.VAR_ATTACHLIST:
                attachList,
            }
            globals.update(globals_page)

        return globals
Beispiel #22
0
 def testAttachPath1 (self):
     attach = Attachment (self.page)
     self.assertEqual (attach.getAttachPath(), os.path.join (self.page.path, Attachment.attachDir))
Beispiel #23
0
class ParserThumbTest (unittest.TestCase):
    def setUp(self):
        self.encoding = "utf8"

        self.filesPath = u"../test/samplefiles/"

        self.pagelinks = [u"Страница 1", u"/Страница 1", u"/Страница 2/Страница 3"]
        self.pageComments = [u"Страницо 1", u"Страницо 1", u"Страницо 3"]

        self.__createWiki()

        factory = ParserFactory()
        self.__wikiconfig = WikiConfig (Application.config)
        self.__wikiconfig.thumbSizeOptions.value = WikiConfig.THUMB_SIZE_DEFAULT

        self.parser = factory.make (self.testPage, Application.config)


    def __createWiki (self):
        # Здесь будет создаваться вики
        self.path = mkdtemp (prefix=u'Абырвалг абыр')

        self.wikiroot = WikiDocument.create (self.path)
        WikiPageFactory().create (self.wikiroot, u"Страница 2", [])
        self.testPage = self.wikiroot[u"Страница 2"]

        files = [u"accept.png", u"add.png", u"anchor.png", u"filename.tmp",
                 u"файл с пробелами.tmp", u"картинка с пробелами.png",
                 u"image.jpg", u"image.jpeg", u"image.png", u"image.tif", u"image.tiff", u"image.gif",
                 u"image_01.JPG", u"dir", u"dir.xxx", u"dir.png", "particle_01.PNG"]

        fullFilesPath = [os.path.join (self.filesPath, fname) for fname in files]

        self.attach_page2 = Attachment (self.wikiroot[u"Страница 2"])

        # Прикрепим к двум страницам файлы
        Attachment (self.testPage).attach (fullFilesPath)


    def tearDown(self):
        self.__wikiconfig.thumbSizeOptions.value = WikiConfig.THUMB_SIZE_DEFAULT
        removeDir (self.path)


    def testThumbWidthJpg (self):
        text = u'бла-бла-бла \nкхм % width = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_width_100_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_width_100_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbWidthJpg2 (self):
        text = u'бла-бла-бла \nкхм % thumb width = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_width_100_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_width_100_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbWidthJpeg (self):
        text = u'бла-бла-бла \nкхм % width = 100 px % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_width_100_image.jpeg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_width_100_image.jpeg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbWidthGif (self):
        text = u'бла-бла-бла \nкхм % width = 100 px % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_width_100_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_width_100_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbWidthPng (self):
        text = u'бла-бла-бла \nкхм % width = 100 px % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_width_100_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_width_100_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbHeightJpg (self):
        text = u'бла-бла-бла \nкхм % height = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_height_100_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_height_100_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbHeightJpg2 (self):
        text = u'бла-бла-бла \nкхм % thumb height = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_height_100_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_height_100_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbHeightJpeg (self):
        text = u'бла-бла-бла \nкхм % height = 100 px % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_height_100_image.jpeg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_height_100_image.jpeg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbHeightGif (self):
        text = u'бла-бла-бла \nкхм % height = 100 px % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_height_100_image.png")
        result = u'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_height_100_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbHeightPng (self):
        text = u'бла-бла-бла \nкхм % height = 100 px % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_height_100_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_height_100_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbJpg (self):
        text = u'бла-бла-бла \nкхм % thumb % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_250_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_250_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbJpeg (self):
        text = u'бла-бла-бла \nкхм % thumb % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_250_image.jpeg")
        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_250_image.jpeg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbPng (self):
        text = u'бла-бла-бла \nкхм % thumb % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_250_image.png")
        result = u'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_250_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbCapitalizeExtension (self):
        text = u'бла-бла-бла \nкхм % thumb % Attach:particle_01.PNG %% бла-бла-бла\nбла-бла-бла'

        path = os.path.join ("__attach", "__thumb", "th_maxsize_250_particle_01.PNG")

        result = u'бла-бла-бла \nкхм <a href="__attach/particle_01.PNG"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(),
                             "__thumb/th_maxsize_250_particle_01.PNG")

        self.assertTrue (os.path.exists (path), path.encode (self.encoding))

    def testThumbGif (self):
        text = u'бла-бла-бла \nкхм % thumb % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_250_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path = path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_250_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbMaxSizeJpg (self):
        text = u'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_300_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_300_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbMaxSizeJpg2 (self):
        text = u'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_300_image.jpg")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_300_image.jpg")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbMaxSizePng (self):
        text = u'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_300_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_300_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbMaxSizeGif (self):
        text = u'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_300_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path=path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_300_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))


    def testThumbGifDefaultThumb (self):
        self.__wikiconfig.thumbSizeOptions.value = 333

        text = u'бла-бла-бла \nкхм % thumb % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join ("__attach", "__thumb", "th_maxsize_333_image.png")

        result = u'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format (path = path.replace ("\\", "/"))

        self.assertEqual (self.parser.toHtml (text), result, self.parser.toHtml (text).encode (self.encoding))

        path = os.path.join (self.attach_page2.getAttachPath(), "__thumb/th_maxsize_333_image.png")
        self.assertTrue (os.path.exists (path), path.encode (self.encoding))
Beispiel #24
0
 def testAttachPath1(self):
     attach = Attachment(self.page)
     self.assertEqual(attach.getAttachPath(),
                      os.path.join(self.page.path, PAGE_ATTACH_DIR))
Beispiel #25
0
class ParserThumbTest (BaseOutWikerMixin, TestCase):
    def setUp(self):
        self.initApplication()
        self.encoding = "utf8"

        self.filesPath = "testdata/samplefiles/"

        self.pagelinks = [
            "Страница 1",
            "/Страница 1",
            "/Страница 2/Страница 3"]
        self.pageComments = ["Страницо 1", "Страницо 1", "Страницо 3"]

        self.__createWiki()

        factory = ParserFactory()
        self.__wikiconfig = WikiConfig(self.application.config)
        self.__wikiconfig.thumbSizeOptions.value = WikiConfig.THUMB_SIZE_DEFAULT

        self.parser = factory.make(self.testPage, self.application.config)

    def __createWiki(self):
        # Здесь будет создаваться вики
        self.path = mkdtemp(prefix='Абырвалг абыр')

        self.wikiroot = WikiDocument.create(self.path)
        WikiPageFactory().create(self.wikiroot, "Страница 2", [])
        self.testPage = self.wikiroot["Страница 2"]

        files = ["accept.png", "add.png", "anchor.png", "filename.tmp",
                 "файл с пробелами.tmp", "картинка с пробелами.png",
                 "image.jpg", "image.jpeg", "image.png", "image.tif",
                 "image.tiff", "image.gif", "image_01.JPG", "dir", "dir.xxx",
                 "dir.png", "particle_01.PNG"]

        fullFilesPath = [
            os.path.join(
                self.filesPath,
                fname) for fname in files]

        self.attach_page2 = Attachment(self.wikiroot["Страница 2"])

        # Прикрепим к двум страницам файлы
        Attachment(self.testPage).attach(fullFilesPath)

    def tearDown(self):
        self.destroyApplication()
        self.__wikiconfig.thumbSizeOptions.value = WikiConfig.THUMB_SIZE_DEFAULT
        removeDir(self.path)

    def testThumbWidthJpg(self):
        text = 'бла-бла-бла \nкхм % width = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_width_100_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_width_100_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbWidthJpg2(self):
        text = 'бла-бла-бла \nкхм % thumb width = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_width_100_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_width_100_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbWidthJpeg(self):
        text = 'бла-бла-бла \nкхм % width = 100 px % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_width_100_image.jpeg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_width_100_image.jpeg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbWidthGif(self):
        text = 'бла-бла-бла \nкхм % width = 100 px % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_width_100_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_width_100_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbWidthPng(self):
        text = 'бла-бла-бла \nкхм % width = 100 px % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_width_100_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_width_100_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbHeightJpg(self):
        text = 'бла-бла-бла \nкхм % height = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_height_100_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_height_100_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbHeightJpg2(self):
        text = 'бла-бла-бла \nкхм % thumb height = 100 px % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_height_100_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_height_100_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbHeightJpeg(self):
        text = 'бла-бла-бла \nкхм % height = 100 px % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_height_100_image.jpeg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_height_100_image.jpeg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbHeightGif(self):
        text = 'бла-бла-бла \nкхм % height = 100 px % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_height_100_image.png")
        result = 'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_height_100_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbHeightPng(self):
        text = 'бла-бла-бла \nкхм % height = 100 px % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_height_100_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_height_100_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbJpg(self):
        text = 'бла-бла-бла \nкхм % thumb % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_250_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_250_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbJpeg(self):
        text = 'бла-бла-бла \nкхм % thumb % Attach:image.jpeg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_250_image.jpeg")
        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpeg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_250_image.jpeg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbPng(self):
        text = 'бла-бла-бла \nкхм % thumb % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_250_image.png")
        result = 'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_250_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbCapitalizeExtension(self):
        text = 'бла-бла-бла \nкхм % thumb % Attach:particle_01.PNG %% бла-бла-бла\nбла-бла-бла'

        path = os.path.join(
            "__attach",
            "__thumb",
            "th_maxsize_250_particle_01.PNG")

        result = 'бла-бла-бла \nкхм <a href="__attach/particle_01.PNG"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(self.attach_page2.getAttachPath(),
                            "__thumb/th_maxsize_250_particle_01.PNG")

        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbGif(self):
        text = 'бла-бла-бла \nкхм % thumb % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_250_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_250_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbMaxSizeJpg(self):
        text = 'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_300_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_300_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbMaxSizeJpg2(self):
        text = 'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.jpg %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_300_image.jpg")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.jpg"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_300_image.jpg")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbMaxSizePng(self):
        text = 'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.png %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_300_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.png"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_300_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbMaxSizeGif(self):
        text = 'бла-бла-бла \nкхм % maxsize = 300 % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_300_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_300_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))

    def testThumbGifDefaultThumb(self):
        self.__wikiconfig.thumbSizeOptions.value = 333

        text = 'бла-бла-бла \nкхм % thumb % Attach:image.gif %% бла-бла-бла\nбла-бла-бла'
        path = os.path.join("__attach", "__thumb", "th_maxsize_333_image.png")

        result = 'бла-бла-бла \nкхм <a href="__attach/image.gif"><img src="{path}"/></a> бла-бла-бла\nбла-бла-бла'.format(
            path=path.replace("\\", "/"))

        self.assertEqual(
            self.parser.toHtml(text),
            result,
            self.parser.toHtml(text).encode(
                self.encoding))

        path = os.path.join(
            self.attach_page2.getAttachPath(),
            "__thumb/th_maxsize_333_image.png")
        self.assertTrue(os.path.exists(path), path.encode(self.encoding))