Skip to content

Commit

Permalink
NXDRIVE-2830: Do not rename locally when a new account is added (#3905)
Browse files Browse the repository at this point in the history
* NXDRIVE-2800: Do not rename locally when the document is updated
  • Loading branch information
gitofanindya committed Apr 20, 2023
1 parent 0c5ab6f commit f7289e2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changes/5.3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release date: `2023-xx-xx`
- [NXDRIVE-2772](https://jira.nuxeo.com/browse/NXDRIVE-2772): Sync icons disappear after restart
- [NXDRIVE-2801](https://jira.nuxeo.com/browse/NXDRIVE-2801): Do not prefix synchronized folder name with ancestors when there is no duplicated root
- [NXDRIVE-2800](https://jira.nuxeo.com/browse/NXDRIVE-2800): Do not rename locally when the document is updated
- [NXDRIVE-2830](https://jira.nuxeo.com/browse/NXDRIVE-2830): Do not rename locally when a new account is added
- [NXDRIVE-2764](https://jira.nuxeo.com/browse/NXDRIVE-2764): Fix handling of special and non-English characters in document names

### Direct Edit
Expand Down
2 changes: 2 additions & 0 deletions nxdrive/engine/watcher/remote_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ def _scan_remote_recursive(
continue

log.debug(f"Scanning remote child: {child_info!r}")
if WORKSPACE_ROOT in child_info.uid:
child_info = self.engine.remote.expand_sync_root_name(child_info)
new_pair = False
child_pair = None
if child_info.uid in children:
Expand Down
88 changes: 88 additions & 0 deletions tests/functional/test_remote_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import patch

from nxdrive.engine.watcher.remote_watcher import RemoteWatcher
from nxdrive.objects import RemoteFileInfo


def test_sync_root_name(manager_factory):
Expand All @@ -23,6 +24,9 @@ def test_sync_root_name(manager_factory):
"",
),
)

remote_path = "/org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#"

test_watcher = RemoteWatcher(engine, dao)

def get_changes():
Expand Down Expand Up @@ -59,6 +63,12 @@ def get_changes():
51b7841d648-test" }'
)

def init_scan_remote(doc_pair, remote_info):
return remote_path

def get_children(arg):
return []

def get_states_from_remote_(path):
return [docpair]

Expand All @@ -80,6 +90,84 @@ def _find_remote_child_match_or_create_(parent_pair, new_info):

update_remote_states = test_watcher._update_remote_states

scan_remote = test_watcher._scan_remote_recursive

with patch.object(test_watcher, "_get_changes", new=get_changes):
info = update_remote_states

assert info is not None

remote_info = RemoteFileInfo.from_dict(
eval(
'{"id": "defaultSyncRootFolderItemFactory#default\
#a7e4ce2a-e4a7-432a-b5e1-62b354606929-test",\
"parentId": "org.nuxeo.drive.service.impl.\
DefaultTopLevelFolderItemFactory#",\
"name": "ROY",\
"folder": True,\
"creator": "Administrator",\
"lastContributor": "Administrator",\
"creationDate": 1681875486061,\
"lastModificationDate": 1681875528408,\
"canRename": True,\
"canDelete": True,\
"lockInfo": None,\
"path": "/org.nuxeo.drive.service.\
impl.DefaultTopLevelFolderItemFactory\
#/defaultSyncRootFolderItemFactory#default\
#a7e4ce2a-e4a7-432a-b5e1-62b354606929-test",\
"userName": "Administrator",\
"canCreateChild": True,\
"canScrollDescendants": True\
}'
)
)

def get_fs_children_(*args):
return [remote_info]

def interact():
return

def do_scan_remote(*args, **kwargs):
return

def add_scanned(path):
assert path == remote_path

def find_remote_child_match_or_create(*args):
return (
namedtuple(
"DocPair",
"local_path, local_parent_path, remote_ref, local_state, remote_state, pair_state, last_error",
defaults=(
".",
".",
"org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#",
"synchronized",
"synchronized",
"synchronized",
None,
),
),
True,
)

with patch.object(test_watcher, "_init_scan_remote", new=init_scan_remote):
with patch.object(test_watcher, "_interact", new=interact):
with patch.object(
test_watcher,
"_find_remote_child_match_or_create",
new=find_remote_child_match_or_create,
):
with patch.object(test_watcher, "_do_scan_remote", new=do_scan_remote):
with patch.object(dao, "add_path_scanned", new=add_scanned):
with patch.object(dao, "get_remote_children", new=get_children):
with patch.object(
engine.remote, "get_fs_children", new=get_fs_children_
):
scan_remote(docpair, remote_info)

with patch.object(test_watcher, "_get_changes", new=get_changes):
with patch.object(test_watcher, "_force_remote_scan", new=_force_remote_scan_):
with patch.object(
Expand Down

0 comments on commit f7289e2

Please sign in to comment.