From 7dd5e3bfe9ee153fbb98119b6ae843b6bc4bcf4b Mon Sep 17 00:00:00 2001 From: ishabaral Date: Fri, 13 Sep 2024 16:38:13 +0545 Subject: [PATCH] given step implementation of sharing file or folder in the server --- pyproject.toml | 2 +- test/gui/.pylintrc | 2 +- .../scripts/helpers/api/sharing_helper.py | 39 +++++++++++ test/gui/shared/steps/server_context.py | 9 +++ test/gui/tst_sharing/test.feature | 70 +++++++++---------- 5 files changed, 85 insertions(+), 37 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 947798fdf40..5ff2bc7fe17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ [tool.black] line-length = 88 -target-version = ['py36', 'py37', 'py38'] +target-version = ['py36', 'py37', 'py38', 'py310'] include = '\.pyi?$' skip-string-normalization = true extend-exclude = ''' diff --git a/test/gui/.pylintrc b/test/gui/.pylintrc index f842daec31d..377ef6dd5b7 100644 --- a/test/gui/.pylintrc +++ b/test/gui/.pylintrc @@ -24,7 +24,7 @@ load-plugins= pylint.extensions.overlapping_exceptions, pylint.extensions.typing, pylint.extensions.redefined_variable_type, -py-version=3.8 +py-version=3.10 unsafe-load-any-extension=no [BASIC] diff --git a/test/gui/shared/scripts/helpers/api/sharing_helper.py b/test/gui/shared/scripts/helpers/api/sharing_helper.py index d11efbaf700..aa9dc399bf2 100644 --- a/test/gui/shared/scripts/helpers/api/sharing_helper.py +++ b/test/gui/shared/scripts/helpers/api/sharing_helper.py @@ -12,6 +12,30 @@ ) +def getPermissionsRoleIdByName(permissionsRole): + match permissionsRole: + case "read" | "Download / View": + return 1 + + case "create" | "Download / View / Upload": + return 4 + + case "edit": + return 2 + + case "delete": + return 8 + + case "read, share": + return 17 + + case "read, share, update" | "edit,share": + return 19 + + case "all": + return 31 + + def get_share_url(): return oc.format_json( url_join( @@ -77,3 +101,18 @@ def download_last_public_link_resource(user, resource, public_link_password=None return False else: raise Exception(f"Server returned status code: {response.status_code}") + + +def share_folder(user, folder_name, receiver, permissions): + permissions = getPermissionsRoleIdByName(permissions) + url = get_share_url() + body = { + "path": f"/{folder_name}", + "shareType": 0, + "shareWith": receiver, + "permissions": permissions, + } + response = request.post(url, body, user=user) + request.assertHttpStatus( + response, 200, f"Failed to share folder '{folder_name}' to user '{user}'" + ) diff --git a/test/gui/shared/steps/server_context.py b/test/gui/shared/steps/server_context.py index 88ee78caabf..184c6f187fd 100644 --- a/test/gui/shared/steps/server_context.py +++ b/test/gui/shared/steps/server_context.py @@ -198,3 +198,12 @@ def step(context, user, group_name): @Given('user "|any|" has been created in the server with default attributes') def step(context, user): Provisioning.create_user(user) + + +@Given( + r'user "([^"].*)" has shared (?:file|folder) "([^"].*)" in the server' + r'with user "([^"].*)" with "([^"].*)" permission(?:s)?', + regexp=True, +) +def step(context, user, folder_name, receiver, permissions): + sharing_helper.share_folder(user, folder_name, receiver, permissions) diff --git a/test/gui/tst_sharing/test.feature b/test/gui/tst_sharing/test.feature index 19bfb998972..eb7ad8ae5c9 100644 --- a/test/gui/tst_sharing/test.feature +++ b/test/gui/tst_sharing/test.feature @@ -28,8 +28,8 @@ Feature: Sharing And user "Alice" has created folder "simple-folder" in the server And user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt" in the server And user "Alice" has uploaded file with content "shared file" to "sharedfile.txt" in the server - And user "Alice" has shared folder "shared" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "sharedfile.txt" on the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "shared" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "sharedfile.txt" in the server with user "Brian" with "all" permissions And user "Alice" has set up a client with default settings When the user adds "Brian Murphy" as collaborator of resource "textfile.txt" with permissions "edit,share" using the client-UI And the user adds "Brian Murphy" as collaborator of resource "simple-folder" with permissions "edit,share" using the client-UI @@ -72,8 +72,8 @@ Feature: Sharing Given user "Brian" has been created in the server with default attributes And user "Alice" has created folder "SharedFolder" in the server And user "Alice" has uploaded file with content "ownCloud test text file" to "/textfile.txt" in the server - And user "Alice" has shared folder "SharedFolder" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "SharedFolder" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions And user "Alice" has set up a client with default settings When the user opens the sharing dialog of "textfile.txt" using the client-UI And the user searches for collaborator "Brian Murphy" using the client-UI @@ -132,11 +132,11 @@ Feature: Sharing And user "TestUser2" has been created in the server with default attributes And user "TestUser3" has been created in the server with default attributes And user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt" in the server - And user "Alice" has shared file "textfile.txt" on the server with user "Carol" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "TestUser1" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "TestUser3" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "TestUser2" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Carol" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "TestUser1" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "TestUser3" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "TestUser2" with "all" permissions And user "Alice" has set up a client with default settings When the user opens the sharing dialog of "textfile.txt" using the client-UI Then the collaborators should be listed in the following order: @@ -163,8 +163,8 @@ Feature: Sharing Given user "Brian" has been created in the server with default attributes And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt" in the server And user "Alice" has created folder "Folder" in the server - And user "Alice" has shared file "/textfile0.txt" on the server with user "Brian" with "read, share" permission - And user "Alice" has shared folder "Folder" on the server with user "Brian" with "read, share" permission + And user "Alice" has shared file "/textfile0.txt" in the server with user "Brian" with "read, share" permission + And user "Alice" has shared folder "Folder" in the server with user "Brian" with "read, share" permission And user "Brian" has set up a client with default settings When the user opens the sharing dialog of "textfile0.txt" using the client-UI Then the error text "The item is not shared with any users or groups" should be displayed in the sharing dialog @@ -195,8 +195,8 @@ Feature: Sharing And user "Brian" on the server has been added to group "grp1" And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt" in the server And user "Alice" has created folder "Folder" in the server - And user "Alice" has shared file "/textfile0.txt" on the server with user "Brian" with "read, share, update" permission - And user "Alice" has shared folder "Folder" on the server with user "Brian" with "read, share, update" permission + And user "Alice" has shared file "/textfile0.txt" in the server with user "Brian" with "read, share, update" permission + And user "Alice" has shared folder "Folder" in the server with user "Brian" with "read, share, update" permission And user "Alice" has shared file "/textfile0.txt" on the server with group "grp1" with "read, share, update" permission And user "Alice" has shared folder "Folder" on the server with group "grp1" with "read, share, update" permission And user "Brian" has set up a client with default settings @@ -213,8 +213,8 @@ Feature: Sharing And user "Alice" has uploaded file with content "file inside a folder" to "simple-folder/textfile.txt" in the server And user "Alice" has uploaded file with content "file in the root" to "textfile.txt" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared folder "simple-folder" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "simple-folder" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When the user overwrites the file "textfile.txt" with content "overwrite file in the root" And the user waits for file "textfile.txt" to be synced @@ -231,8 +231,8 @@ Feature: Sharing And user "Alice" has uploaded file with content "file inside a folder" to "Parent/textfile.txt" in the server And user "Alice" has uploaded file with content "file in the root" to "textfile.txt" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared folder "Parent" on the server with user "Brian" with "read" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "read" permissions + And user "Alice" has shared folder "Parent" in the server with user "Brian" with "read" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "read" permissions And user "Brian" has set up a client with default settings When the user tries to overwrite the file "Parent/textfile.txt" with content "overwrite file inside a folder" And the user tries to overwrite the file "textfile.txt" with content "overwrite file in the root" @@ -248,8 +248,8 @@ Feature: Sharing And user "Alice" has created folder "FOLDER" in the server And user "Alice" has uploaded file with content "some content" to "FOLDER/simple.txt" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions - And user "Alice" has shared folder "FOLDER" on the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "FOLDER" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When the user opens the add-account dialog And the user adds the following account: @@ -272,7 +272,7 @@ Feature: Sharing Scenario: sharee creates a file and a folder inside a shared folder Given user "Alice" has created folder "Parent" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared folder "Parent" on the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "Parent" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When user "Brian" creates a file "Parent/localFile.txt" with the following content inside the sync folder """ @@ -290,7 +290,7 @@ Feature: Sharing Scenario: sharee tries to create a file and a folder inside a shared folder without write permission Given user "Alice" has created folder "Parent" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared folder "Parent" on the server with user "Brian" with "read" permissions + And user "Alice" has shared folder "Parent" in the server with user "Brian" with "read" permissions And user "Brian" has set up a client with default settings When user "Brian" creates a file "Parent/localFile.txt" with the following content inside the sync folder """ @@ -309,8 +309,8 @@ Feature: Sharing Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "textfile.txt" in the server And user "Alice" has created folder "FOLDER" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "FOLDER" on the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "FOLDER" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When the user renames a file "textfile.txt" to "lorem.txt" And the user renames a folder "FOLDER" to "PARENT" @@ -331,8 +331,8 @@ Feature: Sharing Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "textfile.txt" in the server And user "Alice" has created folder "Folder" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "Folder" on the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "Folder" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When the user deletes the file "textfile.txt" And the user deletes the folder "Folder" @@ -347,8 +347,8 @@ Feature: Sharing Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "textfile.txt" in the server And user "Alice" has created folder "Folder" in the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "read" permissions - And user "Alice" has shared file "Folder" on the server with user "Brian" with "read" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "read" permissions + And user "Alice" has shared file "Folder" in the server with user "Brian" with "read" permissions And user "Brian" has set up a client with default settings When the user deletes the file "textfile.txt" And the user deletes the folder "Folder" @@ -365,8 +365,8 @@ Feature: Sharing And user "Carol" has been created in the server with default attributes And user "Alice" has created folder "FOLDER" in the server And user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt" in the server - And user "Alice" has shared file "FOLDER" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "all" permissions + And user "Alice" has shared file "FOLDER" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "all" permissions And user "Brian" has set up a client with default settings When the user adds "Carol King" as collaborator of resource "FOLDER" with permissions "edit,share" using the client-UI And the user adds "Carol King" as collaborator of resource "textfile.txt" with permissions "edit,share" using the client-UI @@ -381,8 +381,8 @@ Feature: Sharing And user "Carol" has been created in the server with default attributes And user "Alice" has created folder "FOLDER" in the server And user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt" in the server - And user "Alice" has shared file "FOLDER" on the server with user "Brian" with "read" permissions - And user "Alice" has shared file "textfile.txt" on the server with user "Brian" with "read" permissions + And user "Alice" has shared file "FOLDER" in the server with user "Brian" with "read" permissions + And user "Alice" has shared file "textfile.txt" in the server with user "Brian" with "read" permissions And user "Brian" has set up a client with default settings When the user opens the sharing dialog of "FOLDER" using the client-UI Then the error text "The file can not be shared because it was shared without sharing permission." should be displayed in the sharing dialog @@ -396,8 +396,8 @@ Feature: Sharing Given user "Brian" has been created in the server with default attributes And user "Alice" has uploaded file with content "ownCloud test text file 0" to "textfile0.txt" in the server And user "Alice" has created folder "simple-folder" in the server - And user "Alice" has shared file "textfile0.txt" on the server with user "Brian" with "all" permissions - And user "Alice" has shared folder "simple-folder" on the server with user "Brian" with "all" permissions + And user "Alice" has shared file "textfile0.txt" in the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "simple-folder" in the server with user "Brian" with "all" permissions And user "Alice" has set up a client with default settings When the user unshares the resource "textfile0.txt" for collaborator "Brian Murphy" using the client-UI Then the text "The item is not shared with any users or groups" should be displayed in the sharing dialog @@ -615,8 +615,8 @@ Feature: Sharing And user "Alice" has created folder "simple-folder" in the server And user "Alice" has created file "lorem.txt" on the server And user "Brian" has been created in the server with default attributes - And user "Alice" has shared folder "simple-folder" on the server with user "Brian" with "all" permissions - And user "Alice" has shared file "lorem.txt" on the server with user "Brian" with "all" permissions + And user "Alice" has shared folder "simple-folder" in the server with user "Brian" with "all" permissions + And user "Alice" has shared file "lorem.txt" in the server with user "Brian" with "all" permissions And user "Alice" has set up a client with default settings When the user removes permissions "" for user "Brian Murphy" of resource "simple-folder" using the client-UI Then "" permissions should not be displayed for user "Brian Murphy" for resource "simple-folder" on the client-UI