Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui-tests][full-ci] Add multiple accounts in a single step #11324

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 80 additions & 59 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import squish, test
import psutil
import uuid
from urllib.parse import urlparse
from os import makedirs
from os.path import exists, join
from helpers.SpaceHelper import get_space_id
from helpers.ConfigHelper import get_config, set_config, isWindows
from helpers.SyncHelper import listenSyncStatusForItem
from helpers.api.utils import url_join
from helpers.UserHelper import getDisplaynameForUser


def substituteInLineCodes(value):
Expand Down Expand Up @@ -100,71 +102,86 @@ def startClient():


def getPollingInterval():
pollingInterval = '''[ownCloud]
remotePollInterval={pollingInterval}
'''
pollingInterval = '''
[ownCloud]
remotePollInterval={pollingInterval}
'''
args = {'pollingInterval': 5000}
pollingInterval = pollingInterval.format(**args)
return pollingInterval


def setUpClient(username, displayName, space="Personal"):
userSetting = '''
[Accounts]
0/Folders/1/davUrl={url}
0/Folders/1/ignoreHiddenFiles=true
0/Folders/1/localPath={client_sync_path}
0/Folders/1/displayString={displayString}
0/Folders/1/paused=false
0/Folders/1/targetPath=/
0/Folders/1/version=2
0/Folders/1/virtualFilesMode={vfs}
0/dav_user={davUserName}
0/display-name={displayUserName}
0/http_CredentialVersion=1
0/http_oauth={oauth}
0/http_user={davUserName}
0/url={local_server}
0/user={displayUserFirstName}
0/version=1
0/supportsSpaces={supportsSpaces}
version=2
'''

userSetting = userSetting + getPollingInterval()

syncPath = createUserSyncPath(username)
dav_endpoint = url_join("remote.php/dav/files", username)

server_url = get_config('localBackendUrl')
is_ocis = get_config('ocis')
if is_ocis:
set_config('syncConnectionName', space)
syncPath = createSpacePath(space)
if space == "Personal":
space = displayName
dav_endpoint = url_join("dav/spaces", get_space_id(space, username))

args = {
'url': url_join(server_url, dav_endpoint, ''),
'displayString': get_config('syncConnectionName'),
'displayUserName': displayName,
'davUserName': username if is_ocis else username.lower(),
'displayUserFirstName': displayName.split()[0],
'client_sync_path': syncPath,
'local_server': server_url,
'oauth': 'true' if is_ocis else 'false',
'vfs': 'wincfapi' if isWindows() else 'off',
'supportsSpaces': 'true' if is_ocis else 'false',
}
userSetting = userSetting.format(**args)

configFile = open(get_config('clientConfigFile'), "w")
configFile.write(userSetting)
configFile.close()

def generate_account_config(users, space="Personal"):
sync_paths = {}
user_setting = ''
for idx, username in enumerate(users):
user_setting += '''
{user_index}/Folders/{uuid_v4}/davUrl={url}
{user_index}/Folders/{uuid_v4}/ignoreHiddenFiles=true
{user_index}/Folders/{uuid_v4}/localPath={client_sync_path}
{user_index}/Folders/{uuid_v4}/displayString={displayString}
{user_index}/Folders/{uuid_v4}/paused=false
{user_index}/Folders/{uuid_v4}/targetPath=/
{user_index}/Folders/{uuid_v4}/version=13
{user_index}/Folders/{uuid_v4}/virtualFilesMode=off
{user_index}/dav_user={davUserName}
{user_index}/display-name={displayUserName}
{user_index}/http_CredentialVersion=1
{user_index}/http_oauth={oauth}
{user_index}/http_user={davUserName}
{user_index}/url={local_server}
{user_index}/user={displayUserFirstName}
{user_index}/supportsSpaces={supportsSpaces}
{user_index}/version=13
'''
if not idx:
user_setting = "[Accounts]" + user_setting

sync_path = createUserSyncPath(username)
dav_endpoint = url_join("remote.php/dav/files", username)

server_url = get_config('localBackendUrl')
is_ocis = get_config('ocis')
if is_ocis:
set_config('syncConnectionName', space)
sync_path = createSpacePath(space)
space_name = space
if space == "Personal":
space_name = getDisplaynameForUser(username)
dav_endpoint = url_join("dav/spaces", get_space_id(space_name, username))

args = {
'url': url_join(server_url, dav_endpoint, ''),
'displayString': get_config('syncConnectionName'),
'displayUserName': getDisplaynameForUser(username),
'davUserName': username if is_ocis else username.lower(),
'displayUserFirstName': getDisplaynameForUser(username).split()[0],
'client_sync_path': sync_path,
'local_server': server_url,
'oauth': 'true' if is_ocis else 'false',
'vfs': 'wincfapi' if isWindows() else 'off',
'supportsSpaces': 'true' if is_ocis else 'false',
'user_index': idx,
'uuid_v4': generate_UUIDV4(),
}
user_setting = user_setting.format(**args)
sync_paths.update({username: sync_path})
# append extra configs
user_setting += "version=13"
user_setting = user_setting + getPollingInterval()

config_file = open(get_config('clientConfigFile'), "a+", encoding="utf-8")
config_file.write(user_setting)
config_file.close()

return sync_paths


def setUpClient(username, space="Personal"):
sync_paths = generate_account_config([username], space)
startClient()
listenSyncStatusForItem(syncPath)
for _, sync_path in sync_paths.items():
listenSyncStatusForItem(sync_path)


def is_app_killed(pid):
Expand All @@ -185,3 +202,7 @@ def wait_until_app_killed(pid=0):
test.log(
"Application was not terminated within {} milliseconds".format(timeout)
)


def generate_UUIDV4():
return str(uuid.uuid4())
2 changes: 1 addition & 1 deletion test/gui/shared/scripts/helpers/SpaceHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_share_endpint():


def create_space(space_name):
body = json.dumps({"Name": space_name})
body = json.dumps({"name": space_name})
response = request.post(get_space_endpint(), body)
if response.status_code != 201:
raise Exception(
Expand Down
97 changes: 64 additions & 33 deletions test/gui/shared/scripts/pageObjects/EnterPassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
import squish
from helpers.WebUIHelper import authorize_via_webui
from helpers.ConfigHelper import get_config
from pageObjects.AccountConnectionWizard import AccountConnectionWizard
from helpers.UserHelper import getPasswordForUser


class EnterPassword:
LOGIN_CONTAINER = {
"name": "LoginRequiredDialog",
"type": "OCC::LoginRequiredDialog",
"visible": 1,
}
LOGIN_USER_LABEL = {
"name": "topLabel",
"type": "QLabel",
"visible": 1,
"window": LOGIN_CONTAINER,
}
USERNAME_BOX = {
"name": "usernameLineEdit",
"type": "QLineEdit",
"visible": 1,
"window": LOGIN_CONTAINER,
}
PASSWORD_BOX = {
"container": names.loginRequiredDialog_contentWidget_QStackedWidget,
"name": "passwordLineEdit",
"type": "QLineEdit",
"visible": 1,
"window": LOGIN_CONTAINER,
}
LOGIN_BUTTON = {
"text": "Log in",
Expand All @@ -25,55 +42,69 @@ class EnterPassword:
"window": names.stack_stackedWidget_QStackedWidget,
}
COPY_URL_TO_CLIPBOARD_BUTTON = {
"container": names.loginRequiredDialog_contentWidget_QStackedWidget,
"name": "copyUrlToClipboardButton",
"type": "QPushButton",
"visible": 1,
"window": LOGIN_CONTAINER,
}
TLS_CERT_WINDOW = {
"name": "OCC__TlsErrorDialog",
"type": "OCC::TlsErrorDialog",
"visible": 1,
}
ACCEPT_CERTIFICATE_YES = {
"text": "Yes",
"type": "QPushButton",
"visible": 1,
"window": TLS_CERT_WINDOW,
}

@staticmethod
def enterPassword(password):
squish.waitForObject(
EnterPassword.PASSWORD_BOX, get_config('maxSyncTimeout') * 1000
)
squish.type(squish.waitForObject(EnterPassword.PASSWORD_BOX), password)
squish.clickButton(squish.waitForObject(EnterPassword.LOGIN_BUTTON))
def __init__(self, occurrence=1):
if occurrence > 1 and get_config('ocis'):
self.TLS_CERT_WINDOW.update({"occurrence": occurrence})

@staticmethod
def oidcReLogin(username, password):
def get_username(self):
# Parse username from following label:
# Please enter your password to log in to the account Alice Hansen@localhost.
# The account Alice Hansen@localhost:9200 is currently logged out.
label = str(squish.waitForObjectExists(self.LOGIN_USER_LABEL).text)
label = label.split("@", maxsplit=1)[0].split(" ")
label.reverse()
return label[1].capitalize()

def enterPassword(self, password):
squish.waitForObject(self.PASSWORD_BOX, get_config('maxSyncTimeout') * 1000)
squish.type(squish.waitForObject(self.PASSWORD_BOX), password)
squish.clickButton(squish.waitForObject(self.LOGIN_BUTTON))

def oidcReLogin(self, username, password):
# wait 500ms for copy button to fully load
squish.snooze(1 / 2)
squish.clickButton(
squish.waitForObject(EnterPassword.COPY_URL_TO_CLIPBOARD_BUTTON)
)
squish.clickButton(squish.waitForObject(self.COPY_URL_TO_CLIPBOARD_BUTTON))
authorize_via_webui(username, password)

@staticmethod
def oauthReLogin(username, password):
def oauthReLogin(self, username, password):
# wait 500ms for copy button to fully load
squish.snooze(1 / 2)
squish.clickButton(
squish.waitForObject(EnterPassword.COPY_URL_TO_CLIPBOARD_BUTTON)
)
squish.clickButton(squish.waitForObject(self.COPY_URL_TO_CLIPBOARD_BUTTON))
authorize_via_webui(username, password, "oauth")

@staticmethod
def reLogin(username, password, oauth=False):
def reLogin(self, username, password, oauth=False):
if get_config('ocis'):
EnterPassword.oidcReLogin(username, password)
self.oidcReLogin(username, password)
elif oauth:
EnterPassword.oauthReLogin(username, password)
self.oauthReLogin(username, password)
else:
EnterPassword.enterPassword(password)
self.enterPassword(password)

@staticmethod
def loginAfterSetup(username, password):
def loginAfterSetup(self, username, password):
if get_config('ocis'):
AccountConnectionWizard.acceptCertificate()
EnterPassword.oidcReLogin(username, password)
self.oidcReLogin(username, password)
else:
EnterPassword.enterPassword(password)
self.enterPassword(password)

def logout(self):
squish.clickButton(squish.waitForObject(self.LOGOUT_BUTTON))

@staticmethod
def logout():
squish.clickButton(squish.waitForObject(EnterPassword.LOGOUT_BUTTON))
def accept_certificate(self):
squish.clickButton(squish.waitForObject(self.ACCEPT_CERTIFICATE_YES))
Loading
Loading