def test_organizeWithFiles(self):
        fields = DocumentFields()
        fields.setField("title", "document about internet")
        d = DocumentFolder()
        d.setDocFields(fields)

        bibfile = File("bibfile.bib")
        bibfile.createFile()
        pdffilename = "pdffile.pdf"
        pdffile = File(pdffilename)
        pdffile.createFile()
        fileList = [bibfile, pdffilename]

        d.create()

        d.organize(fileList)
        self.assertFalse(File("bibfile.bib").exists())
        self.assertFalse(File("pdffile.pdf").exists())

        folderPath = d.getDir().getPath().getAbsolutePath()
        newbibfile = File(folderPath + "/" + "bibfile.bib")
        newpdffile = File(folderPath + "/" + "pdffile.pdf")

        self.assertTrue(newbibfile.exists())
        self.assertTrue(newpdffile.exists())

        d.delete()
 def createFile(self, path):
     self.path = path
     tree = etree.Element("documents")
     file = File(path)
     content = etree.tostring(tree, xml_declaration=True, pretty_print=True, encoding="utf-8")
     print(content.decode("utf-8"))
     file.createFile()
     file.writeContent(content.decode("utf-8"))
    def test_move(self):
        f = File("hello")
        f.createFile()
        f.moveFile("newdest")

        self.assertTrue(f.exists())
        self.assertEqual(f.getPath().path, "newdest")

        oldFile = File("hello")
        self.assertFalse(oldFile.exists())

        f.removeFile()
        self.assertFalse(f.exists())
 def test_containsExtension(self):
     d = Directory("dir")
     f1 = File("dir/text.txt")
     f2 = File("dir/image.png")
     
     d.createDir()
     
     f1.createFile()
     f2.createFile()
     
     self.assertTrue(d.containsFileExtension(".txt"), "Directory contains .txt")
     self.assertTrue(d.containsFileExtension(".png"), "Directory contains .png")
     self.assertFalse(d.containsFileExtension(".pdf"), "Directory does not contain .pdf")
     
     d.removeDir()
 def content(self):
     d = Directory("dir")
     d1 = Directory("dir/a/b")
     d2 = Directory("dir/c")
     d3 = Directory("dir/d/e")
     f1 = File("dir/g.txt")
     f2 = File("dir/e.txt")
     
     d1.createTree()
     d2.createTree()
     d3.createTree()
     f1.createFile()
     f2.createFile()
     
     l = d.getFilesList()
     assert (l == {"dir/e.txt", "dir/g.txt"})
     
     l = d.getDirsList()
     assert (l == {"dir/a", "dir/c", "dir/d"})
     
     l = d.getContentList()
     assert (l == {"dir/e.txt", "dir/g.txt", "dir/a", "dir/c", "dir/d"})
     
     d.removeDir()
 def test_create(self):
     f = File("hello")
     f.createFile()
     self.assertTrue(f.exists())
     self.assertTrue(f.isRegularFile())
     self.assertFalse(f.isDirectory())
 def create(self): 
     f = File("hello")
     f.createFile()
     assert(f.exists())
     assert(f.isRegularFile())
     assert(not f.isDirectory())