Skip to content

Commit

Permalink
given step implementation of creating user in the server (#11802)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishabaral authored Aug 29, 2024
1 parent 0c6a0a0 commit 356342c
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 85 deletions.
3 changes: 2 additions & 1 deletion test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from helpers.StacktraceHelper import getCoredumps, generateStacktrace
from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync
from helpers.SpaceHelper import delete_project_spaces
from helpers.api.Provisioning import delete_created_groups
from helpers.api.Provisioning import delete_created_groups, delete_created_users
from helpers.SetupClientHelper import wait_until_app_killed
from helpers.ConfigHelper import (
init_config,
Expand Down Expand Up @@ -149,6 +149,7 @@ def hook(context):
if get_config("ocis"):
delete_project_spaces()
delete_created_groups()
delete_created_users()


# runs after every scenario
Expand Down
64 changes: 38 additions & 26 deletions test/gui/shared/scripts/helpers/UserHelper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
import requests
from base64 import b64encode
from helpers.ConfigHelper import get_config
from helpers.api.utils import url_join

createdUsers = {}

test_users = {
"admin": {
"username": "admin",
"password": "admin",
"displayname": "adminUsername",
},
"Alice": {
"username": "Alice",
"password": "1234",
"displayname": "Alice Hansen",
"email": "alice@example.org",
},
"Brian": {
"username": "Brian",
"password": "AaBb2Cc3Dd4",
"displayname": "Brian Murphy",
"email": "brian@example.org",
},
"Carol": {
"username": "Carol",
"password": "1234",
"displayname": "Carol King",
"email": "carol@example.org",
},
"David": {
"username": "David",
"password": "1234",
"displayname": "David Lopez",
"email": "david@example.org",
},
"regularuser": {
"password": "1234",
},
}


def basic_auth_header(user=None, password=None):
if not user and not password:
Expand All @@ -17,31 +49,11 @@ def basic_auth_header(user=None, password=None):
return {"Authorization": "Basic " + token}


# gets all users information created in a test scenario
def getCreatedUsersFromMiddleware():
createdUsers = {}
try:
res = requests.get(
url_join(get_config('middlewareUrl'), 'state'),
headers={"Content-Type": "application/json"},
)
createdUsers = res.json()['created_users']
except ValueError:
raise Exception("Could not get created users information from middleware")

return createdUsers


def getUserInfo(username, attribute):
# add and update users to the global createdUsers dict if not already there
# so that we don't have to request for user information in every scenario
# but instead get user information from the global dict
global createdUsers
if username in createdUsers:
return createdUsers[username][attribute]
if username in test_users:
return test_users[username][attribute]
else:
createdUsers = {**createdUsers, **getCreatedUsersFromMiddleware()}
return createdUsers[username][attribute]
return test_users["regularuser"][attribute]


def getDisplaynameForUser(username):
Expand Down
33 changes: 33 additions & 0 deletions test/gui/shared/scripts/helpers/api/Provisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import helpers.api.ocis as ocis
from helpers.api.utils import url_join
from helpers.ConfigHelper import get_config
import helpers.UserHelper as UserHelper

created_groups = {}

Expand Down Expand Up @@ -58,3 +59,35 @@ def add_user_to_group(user, group_name):
ocis.add_user_to_group(user, group_name)
else:
oc.add_user_to_group(user, group_name)


def create_user(username):
user = {}
if username in UserHelper.test_users:
user = UserHelper.test_users[username]
else:
user = {
"username": username,
"displayname": username,
"email": f'{username}@mail.com',
"password": UserHelper.test_users["regularuser"]["password"],
}

if get_config('ocis'):
user_info = ocis.create_user(
user['username'], user['password'], user['displayname'], user['email']
)
else:
user_info = oc.create_user(
user['username'], user['password'], user['displayname'], user['email']
)
UserHelper.createdUsers[username] = user_info


def delete_created_users():
for username, user_info in list(UserHelper.createdUsers.items()):
if get_config('ocis'):
ocis.delete_user(user_info["id"])
else:
oc.delete_user(user_info["username"])
del UserHelper.createdUsers[username]
31 changes: 31 additions & 0 deletions test/gui/shared/scripts/helpers/api/oc10.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,34 @@ def add_user_to_group(user, group_name):
body = {"groupid": group_name}
response = request.post(url, body)
request.assertHttpStatus(response, 200)


def create_user(username, password, displayname, email):
url = url_join(get_ocs_url(), "users")
body = {
"userid": username,
"password": password,
"displayname": displayname,
"email": email,
}
response = request.post(url, body)
request.assertHttpStatus(response, 200)
# oc10 does not set display name while creating user,
# so we need update the user info
user_url = url_join(get_ocs_url(), "users", username)
display_name_body = {"key": "displayname", "value": displayname}
display_name_response = request.put(user_url, display_name_body)
request.assertHttpStatus(display_name_response, 200)
return {
"id": username,
"username": username,
"password": password,
"displayname": displayname,
"email": email,
}


def delete_user(userid):
url = url_join(get_ocs_url(), 'users', userid)
response = request.delete(url)
request.assertHttpStatus(response, 200)
28 changes: 28 additions & 0 deletions test/gui/shared/scripts/helpers/api/ocis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,31 @@ def add_user_to_group(user, group_name):
body = json.dumps({"@odata.id": data})
response = request.post(url, body)
request.assertHttpStatus(response, 204)


def create_user(username, password, displayname, email):
url = url_join(get_graph_url(), "users")
body = json.dumps(
{
"onPremisesSamAccountName": username,
"passwordProfile": {"password": password},
"displayname": displayname,
"mail": email,
}
)
response = request.post(url, body)
request.assertHttpStatus(response, 201)
resp_object = response.json()
return {
"id": resp_object['id'],
"username": username,
"password": password,
"displayname": resp_object['displayName'],
"email": resp_object['mail'],
}


def delete_user(id):
url = url_join(get_graph_url(), 'users', id)
response = request.delete(url)
request.assertHttpStatus(response, 204)
5 changes: 5 additions & 0 deletions test/gui/shared/steps/server_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ def step(context, group_name):
@Given('user "|any|" has been added to group "|any|" in the server')
def step(context, user, group_name):
Provisioning.add_user_to_group(user, group_name)


@Given('user "|any|" has been created in the server with default attributes')
def step(context, user):
Provisioning.create_user(user)
8 changes: 4 additions & 4 deletions test/gui/tst_activity/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Feature: filter activity for user


Scenario: filter synced activities
Given user "Alice" has been created on the server with default attributes and without skeleton files
And user "Brian" has been created on the server with default attributes and without skeleton files
And user "Alice" has created folder "simple-folder" on the server
Given user "Alice" has been created in the server with default attributes
And user "Brian" has been created in the server with default attributes
And user "Alice" has created folder "simple-folder" in the server
And the user has set up the following accounts with default settings:
| Alice |
| Brian |
Expand All @@ -20,7 +20,7 @@ Feature: filter activity for user


Scenario: filter not synced activities
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Alice" has created a folder "Folder1" inside the sync folder
And user "Alice" has set up a client with default settings
When user "Alice" creates the following files inside the sync folder:
Expand Down
4 changes: 2 additions & 2 deletions test/gui/tst_addAccount/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: adding accounts
So that I can sync data with various organisations

Background:
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes


Scenario: Check default options in advanced configuration
Expand All @@ -29,7 +29,7 @@ Feature: adding accounts


Scenario: Adding multiple accounts
Given user "Brian" has been created on the server with default attributes and without skeleton files
Given user "Brian" has been created in the server with default attributes
And user "Alice" has set up a client with default settings
When the user opens the add-account dialog
And the user adds the following account:
Expand Down
4 changes: 2 additions & 2 deletions test/gui/tst_checkAlltabs/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Visually check all tabs


Scenario: Tabs in toolbar looks correct
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Alice" has set up a client with default settings
Then the toolbar should have the following tabs:
| Add Account |
Expand All @@ -15,7 +15,7 @@ Feature: Visually check all tabs


Scenario: Verify various setting options in Settings tab
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Alice" has set up a client with default settings
When the user clicks on the settings tab
Then the settings tab should have the following options in the general section:
Expand Down
2 changes: 1 addition & 1 deletion test/gui/tst_deletFilesFolders/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: deleting files and folders
So that I can keep my filing system clean and tidy

Background:
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes

@issue-9439
Scenario Outline: Delete a file
Expand Down
2 changes: 1 addition & 1 deletion test/gui/tst_editFiles/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: edit files
So that I can modify and change file data

Background:
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes


Scenario: Modify orignal content of a file with special character
Expand Down
2 changes: 1 addition & 1 deletion test/gui/tst_loginLogout/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Logout users
So that I can protect my work and identity and be assured of privacy

Background:
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes


Scenario: logging out
Expand Down
2 changes: 1 addition & 1 deletion test/gui/tst_moveFilesFolders/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: move file and folder
So that I can organize my files and folders

Background:
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Alice" has created folder "folder1" in the server
And user "Alice" has created folder "folder1/folder2" in the server
And user "Alice" has created folder "folder1/folder2/folder3" in the server
Expand Down
6 changes: 3 additions & 3 deletions test/gui/tst_removeAccountConnection/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Feature: remove account connection


Scenario: remove an account connection
Given user "Alice" has been created on the server with default attributes and without skeleton files
And user "Brian" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Brian" has been created in the server with default attributes
And the user has set up the following accounts with default settings:
| Alice |
| Brian |
Expand All @@ -16,7 +16,7 @@ Feature: remove account connection


Scenario: remove the only account connection
Given user "Alice" has been created on the server with default attributes and without skeleton files
Given user "Alice" has been created in the server with default attributes
And user "Alice" has set up a client with default settings
When the user removes the connection for user "Alice" and host %local_server_hostname%
Then connection wizard should be visible
Loading

0 comments on commit 356342c

Please sign in to comment.