def setUpClass(cls): cls.root = tempfile.mkdtemp() cls.downloads = tempfile.mkdtemp() cls.name = "TempUser" cls.user = User.new(cls.root, cls.name, downloads=cls.downloads) cls.user2 = User.new(cls.root, cls.name + "2") cls.user3 = User.new(cls.root, cls.name + "3") with open(os.path.join(cls.root, "desktop.ini"), "w"): pass # create a "junk" file in the share directory
def test_check_folder_error(self): """Verify a user fails the check with a missing folders.""" user = User.new(self.root, "_temp") try: shutil.rmtree(user.path_drops) self.assertRaises(ValueError, user.check) finally: user.delete()
def test_check_file_error(self): """Verify a user fails the check with a missing files.""" user = User.new(self.root, "_temp") try: os.remove(user.path_info) self.assertRaises(ValueError, user.check) finally: user.delete()
def test_new_folder_exists(self): """Verify a user can be created when their friend directory exists.""" name = "FolderExists" os.mkdir(os.path.join(self.user.path, name)) user = User.new(self.root, name) try: pass finally: user.delete()
def test_add_old_format(self): """Verify a user can be added to an old format.""" root = tempfile.mkdtemp() try: with patch("dtb.user.get_info", Mock(return_value=self.INFOS[0])): user = User.new(root, "TempUser") open(user.path_info, "w").close() # blank the file with patch("dtb.user.get_info", Mock(return_value=self.INFOS[1])): user2 = User.add(root, "TempUser") self.assertEqual(1, len(user2.info)) finally: shutil.rmtree(root)
def test_multiple_computers(self): """Verify a user can use multiple computers.""" infos = [("pc1", "name"), ("pc2", "name"), ("pc2", "name")] root = tempfile.mkdtemp() downloads = tempfile.mkdtemp() try: with patch("dtb.user.get_info", Mock(side_effect=infos)): user = User.new(root, "name", downloads=downloads) user2 = User.add(root, "name") user3 = User.add(root, "name") self.assertEqual(user, user2) self.assertEqual(user, user3) finally: shutil.rmtree(root)
def test_delete(self): """Verify a user can be deleted.""" user = User.new(self.root, "_temp") self.assertTrue(os.path.isdir(user.path)) user.delete() self.assertFalse(os.path.isdir(user.path))