def test_setup(self, test_name, args=None, trash_db=False, trash_files=False): self.root = Path(u"/tmp/gpTests/{}".format(test_name)) self.db_file = self.root / "gphotos.sqlite" if trash_files: if self.root.exists(): shutil.rmtree(self.root) elif trash_db: self.db_file.unlink() if not self.root.exists(): self.root.mkdir(parents=True) do_check(self.root) all_args = [str(self.root), "--log-level", "warning"] if args: all_args += args credentials_file = self.test_folder / ".gphotos.token" shutil.copy(credentials_file, self.root) self.parsed_args = self.gp.parser.parse_args(all_args) self.parsed_args.root_folder = Path(self.parsed_args.root_folder) self.gp.setup(self.parsed_args, Path(self.root))
def test_os_filesystem(self): if is_travis: pytest.skip( "skipping windows filesystem test since travis has no NTFS", allow_module_level=True, ) if os_name == "nt": # assume there is a c:\ on the test machine (which is likely) do_check(Path("C:\\")) self.assertFalse(get_check().is_linux) else: do_check(test_data) self.assertTrue(get_check().is_linux)
def fs_checks(root_folder: Path, args: dict): Utils.minimum_date(root_folder) # store the root folder filesystem checks globally for all to inspect do_check(root_folder, int(args.max_filename), bool(args.ntfs)) # check if symlinks are supported if not get_check().is_symlink: args.skip_albums = True # check if file system is case sensitive if not args.case_insensitive_fs: if not get_check().is_case_sensitive: args.case_insensitive_fs = True return args
def test_bad_filenames(self): folder = do_check(test_data) filename = folder.valid_file_name("hello. ") if os_name == "nt": self.assertEqual(filename, "hello") else: self.assertEqual(filename, "hello.") filename = folder.valid_file_name("hello.😀") self.assertEqual(filename, "hello.😀") filename = folder.valid_file_name("hello./") self.assertEqual(filename, "hello._") # patch the checks folder.is_linux = False folder.is_unicode = False filename = folder.valid_file_name("hello. ") self.assertEqual(filename, "hello") filename = folder.valid_file_name("hello.😀") self.assertEqual(filename, "hello._") filename = folder.valid_file_name("hello..") self.assertEqual(filename, "hello")
def test_checks(self): a_path = Path("/tmp") c = do_check(a_path) assert c.is_linux with patch("gphotos.Checks.Path.symlink_to", side_effect=FileNotFoundError()): assert not c._symlinks_supported() with patch("gphotos.Checks.Path.unlink", side_effect=FileNotFoundError()): assert not c._check_case_sensitive() with patch("gphotos.Checks.Path.glob", return_value=["a"]): assert not c._check_case_sensitive() with patch( "gphotos.Checks.subprocess.check_output", side_effect=BaseException() ): assert c._get_max_path_length() == 248 if os.name != "nt": with patch("gphotos.Checks.os.statvfs", side_effect=BaseException()): assert c._get_max_filename_length() == 248 with patch("gphotos.Checks.Path.touch", side_effect=BaseException()): assert not c._unicode_filenames()
def test_empty_media(self): do_check(test_data) g = GoogleAlbumMedia(json.loads('{"emptyJson":"0"}')) self.assertEqual(0, g.size) self.assertEqual("none", g.mime_type) self.assertEqual("none", g.description) self.assertEqual(None, g.create_date) self.assertEqual(None, g.modify_date) # noinspection PyBroadException try: _ = g.url assert False, "empty album url should throw" except Exception: pass self.assertEqual(Path("") / "", g.full_folder) g.duplicate_number = 1 self.assertEqual("none (2)", g.filename)