class CommonTest(unittest.TestCase): ''' Initialize ''' def setUp(self): self.common = Common() ''' Test MIME type from the file ''' def test_readMime(self): # Initialize file = "artifacts/css-cheat-sheet-v1.png" # Assert self.assertEqual("image/png", self.common.readMime(file)) ''' Test for valid folder when output is True ''' def test_validateFolderTrue(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts") # Execute status = self.common.validateFolder(folder) # Assert self.assertTrue(status) # Cleanup self.common.changeFolder(current) ''' Test for valid folder when output is False ''' def test_validateFolderFalse(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/arti") # Execute status = self.common.validateFolder(folder) # Assert self.assertFalse(status) # Cleanup self.common.changeFolder(current) ''' Test folder name from the MIME type ''' def test_getFolderName(self): # Initialize mime = self.common.readMime("artifacts/css-cheat-sheet-v1.png") # Assert self.assertEqual("Image/Png", self.common.getFolderName(mime)) ''' Test chaning to user's supplied folder ''' def test_changeFolder(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts") # Execute self.common.changeFolder(folder) # Assert self.assertEqual(os.getcwd(), folder) # Cleanup self.common.changeFolder(current) ''' Test create folder if not already exists ''' def test_createFolder(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts/tmp") # Execute self.common.createFolder(folder) status = os.path.isdir(folder) & os.path.exists(folder) # Assert self.assertTrue(status) # Cleanup os.rmdir(folder) ''' Test moving files to the newly created folder ''' def test_moveFileToFolder(self): # Initialize current = os.getcwd() parent = os.path.join(current, "tests/artifacts") folder = os.path.join(parent, "tmp") file = "css-cheat-sheet-v1.png" newfile = "css-cheat-sheet-v1-new.png" # Execute self.common.changeFolder(parent) copyfile(file, newfile) self.common.createFolder(folder) self.common.moveFileToFolder(folder, newfile) status = os.path.isfile(os.path.join(folder, newfile)) # Assert self.assertTrue(status) # Cleanup os.remove(os.path.join(folder, newfile)) os.rmdir(folder) self.common.changeFolder(current) ''' Test folder's permission when output is True ''' def test_checkFolderPermissionTrue(self): # Initialize folder = os.path.join(os.getcwd(), "tests/artifacts") # Execute status = self.common.checkFolderPermission(folder) # Assert self.assertTrue(status) ''' Check folder's permission when output is False ''' def test_checkFolderPermissionFalse(self): # Initialize folder = "/etc/apache2/extra" # Execute status = self.common.checkFolderPermission(folder) # Assert self.assertFalse(status)
class FileOrganizerTest(unittest.TestCase): ''' Initialize ''' def setUp(self): self.fileOrganizer = FileOrganizer() self.common = Common() ''' Test Folder validation when output is True ''' def test_validateFolderTrue(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts") self.fileOrganizer.currentFolder = folder # Execute status = self.fileOrganizer.validateFolder() # Assert self.assertTrue(status) # Cleanup self.common.changeFolder(current) ''' Test Folder validation when output is False ''' def test_validateFolderFalse(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/arti") self.fileOrganizer.currentFolder = folder # Execute status = self.fileOrganizer.validateFolder() # Assert self.assertFalse(status) # Cleanup self.common.changeFolder(current) ''' Test folder's permission when output is True ''' def test_folderPermissionTrue(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts") self.fileOrganizer.currentFolder = folder # Execute status = self.fileOrganizer.folderPermission() # Assert self.assertTrue(status) ''' Check folder's permission when output is False ''' def test_folderPermissionFalse(self): # Initialize folder = "/etc/apache2/extra" self.fileOrganizer.currentFolder = folder # Execute status = self.fileOrganizer.folderPermission() # Assert self.assertFalse(status) ''' Test fetching all the files from the folder ''' def test_fetchFiles(self): # Initialize current = os.getcwd() folder = os.path.join(current, "tests/artifacts") # Execute self.common.changeFolder(folder) self.fileOrganizer.fetchFiles() # Assert self.assertEqual(2, len(self.fileOrganizer.currentFiles)) # Cleanup self.common.changeFolder(current) ''' Test organizing files when folder is empty ''' def test_organizeFilesEmpty(self): # Initialize self.fileOrganizer.currentFiles = [] # Execute status = self.fileOrganizer.organizeFiles() # Assert self.assertFalse(status)