Skip to content

Commit

Permalink
Merge 9df50ec into be1240b
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Nov 15, 2018
2 parents be1240b + 9df50ec commit 2c7f128
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
7 changes: 4 additions & 3 deletions parsec/core/fs/sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ async def _process_message(self, sender_id, ciphered):
return

for i in count(1):
sharing_name = f"{msg['name']} (shared by {sender_user_id})"
if i > 1:
sharing_name += f" {i}"
if i == 1:
sharing_name = msg["name"]
else:
sharing_name = f"{msg['name']} {i}"
if sharing_name not in user_manifest["children"]:
break
user_manifest["children"][sharing_name] = msg["access"]
Expand Down
57 changes: 55 additions & 2 deletions tests/core/fs/test_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def test_share_workspace(running_backend, alice_fs, bob_fs):
await alice_fs.share("/foo", recipient="bob")

# Bob should get a notification
bob_foo_name = "foo (shared by alice)"
bob_foo_name = "foo"
with bob_fs.event_bus.listen() as spy:
await bob_fs.process_last_messages()
spy.assert_event_occured("sharing.new", kwargs={"path": f"/{bob_foo_name}", "access": spy.ANY})
Expand All @@ -42,6 +42,59 @@ async def test_share_workspace(running_backend, alice_fs, bob_fs):
assert bob_file_data == b"Hello from Alice !"


@pytest.mark.trio
async def test_share_workspace_multiple_times(running_backend, alice_fs, bob_fs):
# Create a workspace with Alice
await alice_fs.workspace_create("/foo")
await alice_fs.folder_create("/foo/spam")
await alice_fs.file_create("/foo/spam/bar.txt")
await alice_fs.file_write("/foo/spam/bar.txt", b"Alice workspace")
await alice_fs.sync("/foo")

# Create a workspace with Bob
await bob_fs.workspace_create("/foo")
await bob_fs.folder_create("/foo/spam")
await bob_fs.file_create("/foo/spam/bar.txt")
await bob_fs.file_write("/foo/spam/bar.txt", b"Bob workspace")
await bob_fs.sync("/foo")

# Now we can share this workspace with Bob
await alice_fs.share("/foo", recipient="bob")

# Bob should get a notification
bob_foo_name = "foo 2"
with bob_fs.event_bus.listen() as spy:
await bob_fs.process_last_messages()
spy.assert_event_occured("sharing.new", kwargs={"path": f"/{bob_foo_name}", "access": spy.ANY})

# Bob shares his workspace with Alice
await bob_fs.share("/foo", recipient="alice")

# Bob should get a notification
alice_foo_name = "foo 2"
with alice_fs.event_bus.listen() as spy:
await alice_fs.process_last_messages()
spy.assert_event_occured(
"sharing.new", kwargs={"path": f"/{alice_foo_name}", "access": spy.ANY}
)

# Read the data in Bob workspace with Bob
bob_file_data = await bob_fs.file_read(f"/foo/spam/bar.txt")
assert bob_file_data == b"Bob workspace"

# Read the data in Alice workspace with Bob
alice_file_data = await bob_fs.file_read(f"/foo 2/spam/bar.txt")
assert alice_file_data == b"Alice workspace"

# Read the data in Alice workspace with Alice
alice_file_data = await alice_fs.file_read(f"/foo/spam/bar.txt")
assert alice_file_data == b"Alice workspace"

# Read the data in Bob workspace with Alice
bob_file_data = await alice_fs.file_read(f"/foo 2/spam/bar.txt")
assert bob_file_data == b"Bob workspace"


@pytest.mark.trio
@pytest.mark.parametrize("already_synced", [True, False])
async def test_share_workspace_placeholder(already_synced, running_backend, alice_fs, bob_fs):
Expand All @@ -54,7 +107,7 @@ async def test_share_workspace_placeholder(already_synced, running_backend, alic
spy.assert_event_occured("fs.entry.synced", kwargs={"path": f"/foo", "id": spy.ANY})

# Bob should get a notification
bob_foo_name = "foo (shared by alice)"
bob_foo_name = "foo"
with bob_fs.event_bus.listen() as spy:
await bob_fs.process_last_messages()
spy.assert_event_occured("sharing.new", kwargs={"path": f"/{bob_foo_name}", "access": spy.ANY})
Expand Down

0 comments on commit 2c7f128

Please sign in to comment.