Beispiel #1
0
    def testMoveInvalid (self):
        """
        А что, если кто-то блокирует папку с заметкой?
        """
        page = self.wiki[u"Страница 1"]
        attachname = u"add.png"

        attach = Attachment (page)
        attach.attach ([os.path.join (u"../test/samplefiles", attachname)])

        # Откроем на запись файл в папке с вложениями, чтобы нельзя было переместить папку
        with open (attach.getFullPath (u"lock.tmp", True), "w"):
            try:
                page.moveTo (self.wiki[u"Страница 2/Страница 3"])
            except TreeException:
                # Если не удалось переместить страницу
                self.assertEqual (self.wiki[u"Страница 2/Страница 3/Страница 1"], None)
                self.assertNotEqual (self.wiki[u"Страница 1"], None)
                self.assertEqual (len (self.wiki[u"Страница 2/Страница 3"]), 1)

                self.assertTrue (os.path.exists (page.path))
                self.assertFalse (os.path.exists (os.path.join (self.wiki[u"Страница 2/Страница 3"].path, u"Страница 1")))

                self.assertTrue (os.path.exists (attach.getFullPath (attachname)))
            else:
                # А если страницу переместить удалось, то проверим, что она действительно перенеслась
                self.assertEqual (self.wiki[u"Страница 1"], None)
                self.assertTrue (os.path.exists (os.path.join (self.wiki[u"Страница 2/Страница 3"].path, u"Страница 1")))

                self.assertEqual (len (self.wiki[u"Страница 2/Страница 3"]), 2)
                self.assertEqual (len (self.wiki), 3)
                self.assertEqual (self.wiki[u"Страница 2/Страница 3/Страница 1"].title, u"Страница 1")
                self.assertEqual (self.wiki[u"Страница 2/Страница 3/Страница 1/Страница 5"].title, u"Страница 5")
                self.assertEqual (self.wiki[u"Страница 2/Страница 3/Страница 1"].subpath, u"Страница 2/Страница 3/Страница 1")
                self.assertEqual (self.wiki[u"Страница 2/Страница 3/Страница 1/Страница 5"].subpath, u"Страница 2/Страница 3/Страница 1/Страница 5")
Beispiel #2
0
    def testReloading (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        self.wikiroot.selectedPage = self.page
        Application.wikiroot = self.wikiroot

        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (self.fullFilesPath))

        # Создадим другую независимую вики
        newpath = u"../test/testwiki2"
        newwikiroot = WikiDocument.create (newpath)

        TextPageFactory.create (newwikiroot, u"Новая страница 1", [])
        TextPageFactory.create (newwikiroot, u"Новая страница 2", [])

        filesPath = u"../test/samplefiles/"
        newfiles = [u"accept.png", u"add.png", u"anchor.png"]
        newfullFilesPath = [os.path.join (filesPath, fname) for fname in newfiles]    

        newattach = Attachment (newwikiroot[u"Новая страница 1"])
        newattach.attach (newfullFilesPath)
        newwikiroot.selectedPage = newwikiroot[u"Новая страница 1"]

        Application.wikiroot = newwikiroot
        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (newfullFilesPath))

        Application.wikiroot.selectedPage = None
        Application.wikiroot = None
        removeWiki (newpath)
Beispiel #3
0
    def testSortByName(self):
        files = [
            "add.png", "Anchor.png", "image2.png", "image.png", "add.png2",
            "файл с пробелами.tmp", "filename"
        ]

        fullFilesPath = [
            os.path.join("testdata/samplefiles/for_sort", fname)
            for fname in files
        ]

        attach = Attachment(self.page)
        attach.attach(fullFilesPath)

        attach2 = Attachment(self.page)
        files_list = [
            os.path.basename(fname) for fname in attach2.attachmentFull
        ]
        files_list.sort(key=str.lower)

        self.assertEqual(files_list[0], "add.png")
        self.assertEqual(files_list[1], "add.png2")
        self.assertEqual(files_list[2], "Anchor.png")
        self.assertEqual(files_list[3], "filename")
        self.assertEqual(files_list[4], "image.png")
        self.assertEqual(files_list[5], "image2.png")
        self.assertEqual(files_list[6], "файл с пробелами.tmp")
Beispiel #4
0
    def testCache1(self):
        # Только создали страницу, кешировать нельзя
        cache = HtmlCache(self.testPage, self.application)
        self.assertFalse(cache.canReadFromCache())

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

        self.testPage.content = "бла-бла-бла"

        # Изменили содержимое страницы, опять нельзя кешировать
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        self.assertTrue(cache.canReadFromCache())

        # Добавим файл
        attach = Attachment(self.testPage)
        attach.attach([os.path.join(self.filesPath, "add.png")])

        self.assertFalse(cache.canReadFromCache())
        cache.saveHash()

        self.assertTrue(cache.canReadFromCache())
Beispiel #5
0
    def testReloading(self):
        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.wikiroot.selectedPage = self.page
        Application.wikiroot = self.wikiroot

        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(self.fullFilesPath))

        # Создадим другую независимую вики
        newpath = mkdtemp(prefix=u'Абыр Абырвалг')
        newwikiroot = WikiDocument.create(newpath)

        TextPageFactory().create(newwikiroot, u"Новая страница 1", [])
        TextPageFactory().create(newwikiroot, u"Новая страница 2", [])

        filesPath = u"../test/samplefiles/"
        newfiles = [u"accept.png", u"add.png", u"anchor.png"]
        newfullFilesPath = [
            os.path.join(filesPath, fname) for fname in newfiles
        ]

        newattach = Attachment(newwikiroot[u"Новая страница 1"])
        newattach.attach(newfullFilesPath)
        newwikiroot.selectedPage = newwikiroot[u"Новая страница 1"]

        Application.wikiroot = newwikiroot
        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(newfullFilesPath))

        Application.wikiroot.selectedPage = None
        Application.wikiroot = None
        removeDir(newpath)
    def testParseSortDescendDate (self):
        files = [u"add.png", u"Anchor.png",
                 u"image2.png", u"image.png",
                 u"add.png2", u"файл с пробелами.tmp",
                 u"filename"]

        fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files]


        attach = Attachment (self.testPage)
        attach.attach (fullFilesPath)

        os.utime (attach.getFullPath (files[3]), (1000000000, 1000000000))
        os.utime (attach.getFullPath (files[0]), (1000000000, 1100000000))
        os.utime (attach.getFullPath (files[2]), (1000000000, 1200000000))
        os.utime (attach.getFullPath (files[6]), (1000000000, 1300000000))
        os.utime (attach.getFullPath (files[4]), (1000000000, 1400000000))
        os.utime (attach.getFullPath (files[5]), (1000000000, 1500000000))
        os.utime (attach.getFullPath (files[1]), (1000000000, 1600000000))

        text = u"(:attachlist sort=descenddate:)"
        result = self.parser.toHtml (text)

        names = [files[1], files[5], files[4], files[6], files[2], files[0], files[3]]
        titles = names[:]

        self._compareResult (titles, names, result)
Beispiel #7
0
    def testSortByDateRelative (self):
        files = [u"add.png", u"Anchor.png",
                 u"image2.png", u"image.png",
                 u"add.png2", u"файл с пробелами.tmp",
                 u"filename"]

        fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files]


        attach = Attachment (self.page)
        attach.attach (fullFilesPath)

        files_list = attach.attachmentFull
        files_list.sort (Attachment.sortByName)

        os.utime (files_list[3], (1000000000, 1000000000))
        os.utime (files_list[0], (1000000000, 1100000000))
        os.utime (files_list[2], (1000000000, 1200000000))
        os.utime (files_list[6], (1000000000, 1300000000))
        os.utime (files_list[4], (1000000000, 1400000000))
        os.utime (files_list[5], (1000000000, 1500000000))
        os.utime (files_list[1], (1000000000, 1600000000))

        attach2 = Attachment (self.page)
        files_list2 = attach.getAttachRelative()
        files_list2.sort (attach2.sortByDateRelative)

        for n in range (1, len (files)):
            self.assertTrue (os.stat (attach2.getFullPath (files_list2[n - 1])).st_mtime <=
                             os.stat (attach2.getFullPath (files_list2[n])).st_mtime)
    def testRemoveError2(self):
        page1 = self.wikiroot["Страница 2"]
        page2 = self.wikiroot["Страница 2/Страница 3"]

        pagepath = page1.path

        attach2 = Attachment(page2)
        attachname = "add.png"
        attach2.attach([os.path.join("../test/samplefiles", attachname)])

        with open(attach2.getFullPath("111.txt", True), "w"):
            try:
                page1.remove()
            except IOError:
                self.assertTrue(os.path.exists(pagepath))
                self.assertNotEqual(self.wikiroot["Страница 2"], None)
                self.assertTrue(
                    os.path.exists(self.wikiroot["Страница 2"].path)
                )
                self.assertEqual(len(self.wikiroot), 3)
                self.assertNotEqual(self.wikiroot["Страница 2/Страница 3"],
                                    None)
                self.assertNotEqual(
                    self.wikiroot["Страница 2/Страница 3/Страница 4"],
                    None)
            else:
                self.assertEqual(self.wikiroot["Страница 2"], None)
                self.assertFalse(os.path.exists(pagepath))
    def testParseSortDescendDate(self):
        files = [
            "add.png", "Anchor.png", "image2.png", "image.png", "add.png2",
            "файл с пробелами.tmp", "filename"
        ]

        fullFilesPath = [
            os.path.join("testdata/samplefiles/for_sort", fname)
            for fname in files
        ]

        attach = Attachment(self.testPage)
        attach.attach(fullFilesPath)

        os.utime(attach.getFullPath(files[3]), (1000000000, 1000000000))
        os.utime(attach.getFullPath(files[0]), (1000000000, 1100000000))
        os.utime(attach.getFullPath(files[2]), (1000000000, 1200000000))
        os.utime(attach.getFullPath(files[6]), (1000000000, 1300000000))
        os.utime(attach.getFullPath(files[4]), (1000000000, 1400000000))
        os.utime(attach.getFullPath(files[5]), (1000000000, 1500000000))
        os.utime(attach.getFullPath(files[1]), (1000000000, 1600000000))

        text = "(:attachlist sort=descenddate:)"
        result = self.parser.toHtml(text)

        names = [
            files[1], files[5], files[4], files[6], files[2], files[0],
            files[3]
        ]
        titles = names[:]

        self._compareResult(titles, names, result)
Beispiel #10
0
    def testSortByExt(self):
        files = [
            u"add.png", u"Anchor.png", u"image2.png", u"image.png",
            u"add.png2", u"файл с пробелами.tmp", u"filename"
        ]

        fullFilesPath = [
            os.path.join(u"../test/samplefiles/for_sort", fname)
            for fname in files
        ]

        attach = Attachment(self.page)
        attach.attach(fullFilesPath)

        attach2 = Attachment(self.page)
        files_list = [
            os.path.basename(fname) for fname in attach2.attachmentFull
        ]
        files_list.sort(Attachment.sortByExt)

        self.assertEqual(files_list[0], u"filename")
        self.assertEqual(files_list[1], u"add.png")
        self.assertEqual(files_list[2], u"Anchor.png")
        self.assertEqual(files_list[3], u"image.png")
        self.assertEqual(files_list[4], u"image2.png")
        self.assertEqual(files_list[5], u"add.png2")
        self.assertEqual(files_list[6], u"файл с пробелами.tmp")
Beispiel #11
0
    def testCache1(self):
        # Только создали страницу, кешировать нельзя
        cache = HtmlCache(self.testPage, Application)
        self.assertFalse(cache.canReadFromCache())

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

        self.testPage.content = u"бла-бла-бла"

        # Изменили содержимое страницы, опять нельзя кешировать
        self.assertFalse(cache.canReadFromCache())

        cache.saveHash()

        self.assertTrue(cache.canReadFromCache())

        # Добавим файл
        attach = Attachment(self.testPage)
        attach.attach([os.path.join(self.filesPath, u"add.png")])

        self.assertFalse(cache.canReadFromCache())
        cache.saveHash()

        self.assertTrue(cache.canReadFromCache())
Beispiel #12
0
    def testSortByDate(self):
        files = ["add.png", "Anchor.png",
                 "image2.png", "image.png",
                 "add.png2", "файл с пробелами.tmp",
                 "filename"]

        fullFilesPath = [os.path.join("../test/samplefiles/for_sort", fname)
                         for fname in files]

        attach = Attachment(self.page)
        attach.attach(fullFilesPath)

        files_list = attach.attachmentFull
        files_list.sort(key=str.lower)

        os.utime(files_list[3], (1000000000, 1000000000))
        os.utime(files_list[0], (1000000000, 1100000000))
        os.utime(files_list[2], (1000000000, 1200000000))
        os.utime(files_list[6], (1000000000, 1300000000))
        os.utime(files_list[4], (1000000000, 1400000000))
        os.utime(files_list[5], (1000000000, 1500000000))
        os.utime(files_list[1], (1000000000, 1600000000))

        Attachment(self.page)
        files_list2 = attach.attachmentFull
        files_list2.sort(key=Attachment.sortByDate)

        for n in range(1, len(files)):
            self.assertTrue(os.stat(files_list2[n - 1]).st_mtime <=
                            os.stat(files_list2[n]).st_mtime)
Beispiel #13
0
    def testReloading(self):
        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.wikiroot.selectedPage = self.page
        self.application.wikiroot = self.wikiroot

        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), len(self.fullFilesPath))

        # Создадим другую независимую вики
        newpath = mkdtemp(prefix='Абыр Абырвалг')
        newwikiroot = WikiDocument.create(newpath)

        TextPageFactory().create(newwikiroot, "Новая страница 1", [])
        TextPageFactory().create(newwikiroot, "Новая страница 2", [])

        filesPath = "../test/samplefiles/"
        newfiles = ["accept.png", "add.png", "anchor.png"]
        newfullFilesPath = [os.path.join(filesPath, fname) for fname in newfiles]

        newattach = Attachment(newwikiroot["Новая страница 1"])
        newattach.attach(newfullFilesPath)
        newwikiroot.selectedPage = newwikiroot["Новая страница 1"]

        self.application.wikiroot = newwikiroot
        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), len(newfullFilesPath))

        self.application.wikiroot.selectedPage = None
        self.application.wikiroot = None
        removeDir(newpath)
Beispiel #14
0
    def testRemoveError2(self):
        page1 = self.wikiroot["Страница 2"]
        page2 = self.wikiroot["Страница 2/Страница 3"]

        pagepath = page1.path

        attach2 = Attachment(page2)
        attachname = "add.png"
        attach2.attach([os.path.join("../test/samplefiles", attachname)])

        with open(attach2.getFullPath("111.txt", True), "w"):
            try:
                page1.remove()
            except IOError:
                self.assertTrue(os.path.exists(pagepath))
                self.assertNotEqual(self.wikiroot["Страница 2"], None)
                self.assertTrue(
                    os.path.exists(self.wikiroot["Страница 2"].path)
                )
                self.assertEqual(len(self.wikiroot), 3)
                self.assertNotEqual(self.wikiroot["Страница 2/Страница 3"],
                                    None)
                self.assertNotEqual(
                    self.wikiroot["Страница 2/Страница 3/Страница 4"],
                    None)
            else:
                self.assertEqual(self.wikiroot["Страница 2"], None)
                self.assertFalse(os.path.exists(pagepath))
Beispiel #15
0
    def testAttach2 (self):
        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page

        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (self.fullFilesPath))
Beispiel #16
0
    def testAttach2(self):
        self.application.wikiroot = self.wikiroot
        self.application.wikiroot.selectedPage = self.page

        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), len(self.fullFilesPath))
Beispiel #17
0
    def testAttach8 (self):
        # Не подключаем к Application созданную вики. Панель не должна реагировать на прикрепленные файлы
        self.wikiroot.selectedPage = self.page

        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), 0)
Beispiel #18
0
    def testGetAttachRelative4 (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        attach_right = set ([u"attach.png", u"dir.xxx", u"subdir"])

        attach_names = set (attach.getAttachRelative(u"dir"))
        self.assertEqual (attach_right, attach_names)
Beispiel #19
0
    def testGetAttachRelative3 (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        attach_right = set (self.files)

        attach_names = set (attach.getAttachRelative())
        self.assertEqual (attach_right, attach_names)
Beispiel #20
0
    def testRemoveAttachDir1 (self):
        attach = Attachment (self.page)

        attach.attach (self.fullFilesPath)

        attach.removeAttach ([u"dir"])

        self.assertEqual (len (attach.attachmentFull), len (self.fullFilesPath[1:]))
Beispiel #21
0
    def testAttach8(self):
        # Не подключаем к self.application созданную вики. Панель не должна реагировать на прикрепленные файлы
        self.wikiroot.selectedPage = self.page

        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), 0)
Beispiel #22
0
    def testMoveInvalid(self):
        """
        А что, если кто-то блокирует папку с заметкой?
        """
        page = self.wiki[u"Страница 1"]
        attachname = u"add.png"

        attach = Attachment(page)
        attach.attach([os.path.join(u"../test/samplefiles", attachname)])

        # Откроем на запись файл в папке с вложениями,
        # чтобы нельзя было переместить папку
        with open(attach.getFullPath(u"lock.tmp", True), "w"):
            try:
                page.moveTo(self.wiki[u"Страница 2/Страница 3"])
            except TreeException:
                # Если не удалось переместить страницу
                self.assertEqual(
                    self.wiki[u"Страница 2/Страница 3/Страница 1"],
                    None
                )
                self.assertNotEqual(self.wiki[u"Страница 1"], None)
                self.assertEqual(len(self.wiki[u"Страница 2/Страница 3"]), 1)

                self.assertTrue(os.path.exists(page.path))
                self.assertFalse(os.path.exists(
                    os.path.join(self.wiki[u"Страница 2/Страница 3"].path,
                                 u"Страница 1")))

                self.assertTrue(os.path.exists(attach.getFullPath(attachname)))
            else:
                # А если страницу переместить удалось, то проверим,
                # что она действительно перенеслась
                self.assertEqual(self.wiki[u"Страница 1"], None)
                self.assertTrue(
                    os.path.exists(
                        os.path.join(
                            self.wiki[u"Страница 2/Страница 3"].path,
                            u"Страница 1")
                    )
                )

                self.assertEqual(len(self.wiki[u"Страница 2/Страница 3"]), 2)
                self.assertEqual(len(self.wiki), 3)
                self.assertEqual(
                    self.wiki[u"Страница 2/Страница 3/Страница 1"].title,
                    u"Страница 1"
                )
                self.assertEqual(
                    self.wiki[u"Страница 2/Страница 3/Страница 1/Страница 5"].title,
                    u"Страница 5"
                )
                self.assertEqual(
                    self.wiki[u"Страница 2/Страница 3/Страница 1"].subpath,
                    u"Страница 2/Страница 3/Страница 1")
                self.assertEqual(
                    self.wiki[u"Страница 2/Страница 3/Страница 1/Страница 5"].subpath,
                    u"Страница 2/Страница 3/Страница 1/Страница 5")
Beispiel #23
0
    def test_drop_single_attach(self):
        attach = Attachment(self.testpage)
        attach.attach(['../test/images/icon.png'])

        files = sorted(attach.attachmentFull)
        self.dropTarget.OnDropFiles(0, 0, files)

        expected_text = 'Attach:icon.png'
        self.assertEqual(self.editor.GetText(), expected_text)
Beispiel #24
0
    def test_drop_several_attach(self):
        attach = Attachment(self.testpage)
        attach.attach(['../test/images/icon.png', '../test/images/first.png'])

        files = sorted(attach.attachmentFull)
        self.dropTarget.OnDropFiles(0, 0, files)

        expected_text = 'first.png icon.png'
        self.assertEqual(self.editor.GetText(), expected_text)
Beispiel #25
0
    def test_drop_several_attach(self):
        attach = Attachment(self.testpage)
        attach.attach(['testdata/images/icon.png', 'testdata/images/first.png'])

        files = sorted(attach.attachmentFull)
        self.dropTarget.OnDropFiles(0, 0, files)

        expected_text = '__attach/first.png __attach/icon.png'
        self.assertEqual(self.editor.GetText(), expected_text)
Beispiel #26
0
    def testAttach4 (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page
        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (self.fullFilesPath))

        Application.wikiroot.selectedPage = self.wikiroot[u"Страница 1"]
        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), 0)
Beispiel #27
0
    def testAttach6(self):
        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.application.wikiroot = self.wikiroot
        self.application.wikiroot.selectedPage = self.page
        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), len(self.fullFilesPath))

        self.application.wikiroot.selectedPage = None
        self.assertEqual(self.mainWindow.attachPanel.panel.attachList.GetItemCount(), 0)
Beispiel #28
0
    def testAttach1 (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page
        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (self.fullFilesPath))

        attach.removeAttach ([self.files[0]])
        self.assertEqual (self.wnd.attachPanel.panel.attachList.GetItemCount(), len (self.fullFilesPath) - 1)
Beispiel #29
0
    def testAttachBasename (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        self.assertEqual (len (attach.getAttachRelative()), len (self.files))

        attachBasenames = attach.getAttachRelative()

        for fname in self.files:
            self.assertTrue (fname in attachBasenames, fname)
Beispiel #30
0
    def test_drop_several_mixed(self):
        attach = Attachment(self.testpage)
        attach.attach(['testdata/images/first.png'])

        files = (attach.attachmentFull +
                 [os.path.abspath('testdata/images/icon.png')])
        self.dropTarget.OnDropFiles(0, 0, files)

        expected_text = ('first.png '
                         + os.path.abspath('testdata/images/icon.png'))

        self.assertEqual(self.editor.GetText(), expected_text)
Beispiel #31
0
    def testAttach1(self):
        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page
        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(self.fullFilesPath))

        attach.removeAttach([self.files[0]])
        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(self.fullFilesPath) - 1)
Beispiel #32
0
    def test_drop_several_mixed(self):
        attach = Attachment(self.testpage)
        attach.attach(['../test/images/first.png'])

        files = (attach.attachmentFull +
                 [os.path.abspath('../test/images/icon.png')])
        self.dropTarget.OnDropFiles(0, 0, files)

        expected_text = ('first.png '
                         + os.path.abspath('../test/images/icon.png'))

        self.assertEqual(self.editor.GetText(), expected_text)
Beispiel #33
0
    def testAttach5(self):
        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page
        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(self.fullFilesPath))

        Application.wikiroot = None
        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         0)
Beispiel #34
0
    def testAttach3(self):
        Application.wikiroot = self.wikiroot
        Application.wikiroot.selectedPage = self.page

        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath[:1])

        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         1)
        attach.attach(self.fullFilesPath[1:])

        self.assertEqual(self.wnd.attachPanel.panel.attachList.GetItemCount(),
                         len(self.fullFilesPath))
Beispiel #35
0
    def testAttachFull3 (self):
        attach = Attachment (self.page)

        attach.attach (self.fullFilesPath)

        attach2 = Attachment (self.page)
        self.assertTrue (attach != attach2)
        self.assertEqual (len (attach2.attachmentFull), len (self.fullFilesPath))

        attachBasenames = [os.path.basename (path) for path in attach2.attachmentFull]

        for path in self.fullFilesPath:
            self.assertTrue (os.path.basename (path) in attachBasenames, path)
Beispiel #36
0
    def testRemoveAttaches2 (self):
        attach = Attachment (self.page)
        attach2 = Attachment (self.page)

        attach.attach (self.fullFilesPath)

        attach.removeAttach ([self.files[0]])

        self.assertEqual (len (attach2.attachmentFull), len (self.fullFilesPath[1:]))

        attachBasenames = [os.path.basename (path) for path in attach2.attachmentFull]

        for path in self.fullFilesPath [1:]:
            self.assertTrue (os.path.basename (path) in attachBasenames, path)
Beispiel #37
0
    def testHash1 (self):
        # Только создали страницу, кешировать нельзя
        hashCalculator = WikiHashCalculator (Application)
        hash_src = hashCalculator.getHash (self.testPage)

        self.testPage.content = u"бла-бла-бла"
        hash2 = hashCalculator.getHash (self.testPage)

        self.assertNotEqual (hash_src, hash2)

        # Добавим файл
        attach = Attachment (self.testPage)
        attach.attach ([os.path.join (self.filesPath, u"add.png")])

        hash3 = hashCalculator.getHash (self.testPage)
        self.assertNotEqual (hash_src, hash3)
        self.assertNotEqual (hash2, hash3)
Beispiel #38
0
    def testSortBySize (self):
        files = [u"add.png", u"Anchor.png",
                 u"image2.png", u"image.png",
                 u"add.png2", u"файл с пробелами.tmp",
                 u"filename"]

        fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files]

        attach = Attachment (self.page)
        attach.attach (fullFilesPath)
        attach.attach ([os.path.join (u"../test/samplefiles", "dir")])

        attach2 = Attachment (self.page)
        files_list = attach2.attachmentFull
        files_list.sort (Attachment.sortBySize)

        for n in range (1, len (files_list)):
            self.assertTrue (os.stat (files_list[n - 1]).st_size <= os.stat (files_list[n]).st_size)
Beispiel #39
0
    def testEvent(self):
        self.pageUpdateCount = 0

        Application.onAttachListChanged += self.onAttachListChanged

        attach = Attachment(self.page)

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

        self.assertEqual(self.pageUpdateCount, 1)
        self.assertEqual(self.pageUpdateSender, self.page)

        attach.attach(self.fullFilesPath[2:])

        self.assertEqual(self.pageUpdateCount, 2)
        self.assertEqual(self.pageUpdateSender, self.page)

        Application.onAttachListChanged -= self.onAttachListChanged
Beispiel #40
0
    def testEvent (self):
        self.pageUpdateCount = 0

        Application.onPageUpdate += self.onPageUpdate

        attach = Attachment (self.page)

        # Прикрепим к двум страницам файлы
        attach.attach (self.fullFilesPath [: 2])
        
        self.assertEqual (self.pageUpdateCount, 1)
        self.assertEqual (self.pageUpdateSender, self.page)

        attach.attach (self.fullFilesPath [2 :])
        
        self.assertEqual (self.pageUpdateCount, 2)
        self.assertEqual (self.pageUpdateSender, self.page)

        Application.onPageUpdate -= self.onPageUpdate
Beispiel #41
0
    def testCache2 (self):
        # Только создали страницу, кешировать нельзя
        generator = HtmlGenerator (self.testPage)

        path = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime = os.stat(path).st_mtime
        time.sleep (0.1)

        path2 = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime2 = os.stat(path).st_mtime

        self.assertEqual (ftime, ftime2)
        time.sleep (0.1)

        # Изменили содержимое страницы, опять нельзя кешировать
        self.testPage.content = u"бла-бла-бла"
        path3 = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime3 = os.stat(path).st_mtime

        self.assertNotEqual (ftime2, ftime3)
        time.sleep (0.1)

        path4 = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime4 = os.stat(path).st_mtime

        self.assertEqual (ftime3, ftime4)
        time.sleep (0.1)

        # Добавим файл
        attach = Attachment (self.testPage)
        attach.attach ([os.path.join (self.filesPath, u"add.png")])

        path5 = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime5 = os.stat(path).st_mtime

        self.assertNotEqual (ftime4, ftime5)
        time.sleep (0.1)

        path6 = generator.makeHtml (Style().getPageStyle (self.testPage))
        ftime6 = os.stat(path).st_mtime

        self.assertEqual (ftime5, ftime6)
Beispiel #42
0
    def testEvent (self):
        self.pageUpdateCount = 0

        Application.onPageUpdate += self.onPageUpdate

        attach = Attachment (self.page)

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

        self.assertEqual (self.pageUpdateCount, 1)
        self.assertEqual (self.pageUpdateSender, self.page)
        self.assertEqual (self.prev_kwargs['change'], PAGE_UPDATE_ATTACHMENT)

        attach.attach (self.fullFilesPath [2:])

        self.assertEqual (self.pageUpdateCount, 2)
        self.assertEqual (self.pageUpdateSender, self.page)

        Application.onPageUpdate -= self.onPageUpdate
Beispiel #43
0
    def setUp(self):
        self.initApplication()
        self.wikiroot = self.createWiki()

        factory = TextPageFactory()
        factory.create(self.wikiroot, 'Страница 1', [])
        factory.create(self.wikiroot, 'Страница 2', [])
        factory.create(self.wikiroot['Страница 2'], 'Страница 3', [])

        self.page = self.wikiroot['Страница 2/Страница 3']

        filesPath = 'testdata/samplefiles/'
        self.files = ['accept.png', 'add.png']
        self.fullFilesPath = [os.path.join(
            filesPath, fname) for fname in self.files]

        attach = Attachment(self.page)
        attach.attach(self.fullFilesPath)

        self.application.wikiroot = self.wikiroot
        self.application.wikiroot.selectedPage = self.page
Beispiel #44
0
    def testRemoveError1(self):
        page = self.rootwiki[u"Страница 2"]
        pagepath = page.path

        attach = Attachment(page)
        attachname = u"add.png"
        attach.attach([os.path.join(u"../test/samplefiles", attachname)])

        with open(attach.getFullPath("111.txt", True), "w") as fp:
            try:
                page.remove()
            except IOError:
                self.assertTrue(os.path.exists(pagepath))
                self.assertNotEqual(self.rootwiki[u"Страница 2"], None)
                self.assertTrue(os.path.exists(self.rootwiki[u"Страница 2"].path))
                self.assertEqual(len(self.rootwiki), 3)
                self.assertNotEqual(self.rootwiki[u"Страница 2/Страница 3"], None)
                self.assertNotEqual(self.rootwiki[u"Страница 2/Страница 3/Страница 4"], None)
            else:
                self.assertEqual(self.rootwiki[u"Страница 2"], None)
                self.assertFalse(os.path.exists(pagepath))
Beispiel #45
0
    def testRemoveAttachesEvent (self):
        attach = Attachment (self.page)

        attach.attach (self.fullFilesPath)

        Application.onPageUpdate += self.onPageUpdate

        attach.removeAttach ([self.files[0]])

        self.assertEqual (len (attach.attachmentFull), len (self.fullFilesPath) - 1)
        self.assertEqual (self.pageUpdateCount, 1)
        self.assertEqual (self.pageUpdateSender, self.page)


        attach.removeAttach ([self.files[1], self.files[2]])

        self.assertEqual (len (attach.attachmentFull), len (self.fullFilesPath) - 3)
        self.assertEqual (self.pageUpdateCount, 2)
        self.assertEqual (self.pageUpdateSender, self.page)

        Application.onPageUpdate -= self.onPageUpdate
Beispiel #46
0
    def testSortByExt (self):
        files = [u"add.png", u"Anchor.png",
                 u"image2.png", u"image.png",
                 u"add.png2", u"файл с пробелами.tmp",
                 u"filename"]

        fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files]

        attach = Attachment (self.page)
        attach.attach (fullFilesPath)

        attach2 = Attachment (self.page)
        files_list = [os.path.basename (fname) for fname in attach2.attachmentFull]
        files_list.sort (Attachment.sortByExt)

        self.assertEqual (files_list[0], u"filename")
        self.assertEqual (files_list[1], u"add.png")
        self.assertEqual (files_list[2], u"Anchor.png")
        self.assertEqual (files_list[3], u"image.png")
        self.assertEqual (files_list[4], u"image2.png")
        self.assertEqual (files_list[5], u"add.png2")
        self.assertEqual (files_list[6], u"файл с пробелами.tmp")
Beispiel #47
0
    def testSortBySizeRelative(self):
        files = [
            "add.png", "Anchor.png", "image2.png", "image.png", "add.png2",
            "файл с пробелами.tmp", "filename"
        ]

        fullFilesPath = [
            os.path.join("testdata/samplefiles/for_sort", fname)
            for fname in files
        ]

        attach = Attachment(self.page)
        attach.attach(fullFilesPath)
        attach.attach([os.path.join("testdata/samplefiles", "dir")])

        attach2 = Attachment(self.page)
        files_list = attach2.getAttachRelative()
        files_list.sort(key=attach2.sortBySizeRelative)

        for n in range(1, len(files_list)):
            self.assertTrue(
                os.stat(attach2.getFullPath(files_list[n - 1])).st_size <=
                os.stat(attach2.getFullPath(files_list[n])).st_size)
Beispiel #48
0
    def testCache1 (self):
        # Только создали страницу, кешировать нельзя
        generator = HtmlGenerator (self.testPage)
        self.assertFalse (generator.canReadFromCache())

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

        self.testPage.content = u"бла-бла-бла"

        # Изменили содержимое страницы, опять нельзя кешировать
        self.assertFalse (generator.canReadFromCache())
        generator.makeHtml (Style().getPageStyle (self.testPage))
        self.assertTrue (generator.canReadFromCache())

        # Добавим файл
        attach = Attachment (self.testPage)
        attach.attach ([os.path.join (self.filesPath, u"add.png")])

        self.assertFalse (generator.canReadFromCache())
        generator.makeHtml (Style().getPageStyle (self.testPage))
        self.assertTrue (generator.canReadFromCache())
Beispiel #49
0
    def testGetAttachRelative5 (self):
        attach = Attachment (self.page)
        attach.attach (self.fullFilesPath)

        self.assertRaises (OSError, attach.getAttachRelative, "invaliddir")