def doc_pair(name: str, synced: bool = True, with_rpaths: bool = False) -> Path: """Create a valid doc pair in the database and return the local_path field.""" # Craft the local file finfo = FileInfo(Path("."), Path(name), False, datetime.now()) dao.insert_local_state(finfo, Path(name).parent) local_path = Path(f"/{name}") if synced: # Edit pair states to mimic a synced document doc_pair = dao.get_state_from_local(local_path) assert doc_pair is not None assert doc_pair.local_name == name doc_pair.local_state = "synchronized" doc_pair.remote_state = "synchronized" dao.update_local_state(doc_pair, finfo) if with_rpaths: # Also set fake remote paths rinfo = RemoteFileInfo.from_dict( { "id": "self-uid", "parentId": "parent-uid", "path": "/some/path", "name": name, "digest": "0" * 32, } ) doc_pair.remote_parent_path = "remote-aprent-path" dao.update_remote_state(doc_pair, rinfo) return local_path
def test_fileinfo_normalization(self): local = self.local_1 self.engine_1.start() self.wait_sync(wait_for_async=True) self.engine_1.stop() name = "Teste\u0301" local.make_file("/", name, content=b"Test") # FileInfo() will normalize the filename assert FileInfo(local.base_folder, Path(name), False, 0).name != name # The encoding should be different, # cannot trust the get_children as they use FileInfo children = os.listdir(local.abspath("/")) assert len(children) == 1 assert children[0] != name
def doc_pair(name: str) -> int: """Create a valid doc pair in the database and return the row ID.""" # Craft the local file path = tmp() file = path / name file.parent.mkdir() file.write_text("azerty") finfo = FileInfo(path, file, False, datetime.now()) rowid = dao.insert_local_state(finfo, None) # Edit pair states to mimic a synced document doc_pair = dao.get_state_from_id(rowid) doc_pair.local_state = "modified" doc_pair.remote_state = "modified" dao.update_local_state(doc_pair, finfo) dao.update_remote_name(rowid, name) return rowid