Skip to content

Commit

Permalink
add multiple accounts at once
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Nov 1, 2023
1 parent 12f366e commit 872d75e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 99 deletions.
132 changes: 76 additions & 56 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from urllib.parse import urlparse
import squish
import uuid
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
from helpers.SyncHelper import listenSyncStatusForItem
from helpers.UserHelper import getDisplaynameForUser


def substituteInLineCodes(value):
Expand Down Expand Up @@ -90,65 +92,83 @@ 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=off
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
version=2
'''

userSetting = userSetting + getPollingInterval()

syncPath = createUserSyncPath(username)
dav_endpoint = 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 = join("dav/spaces", get_space_id(space, username))

args = {
'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',
}
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}/version=13
'''

if not idx:
user_setting = "[Accounts]" + user_setting

sync_path = createUserSyncPath(username)
dav_endpoint = 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)
if space == "Personal":
space = getDisplaynameForUser(username)
dav_endpoint = join("dav/spaces", get_space_id(space, username))

args = {
'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',
'user_index': idx,
'uuid_v4': generate_UUIDV4(),
}
user_setting = user_setting.format(**args)
sync_paths.append(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_path = generate_account_config([username], space)
startClient()
listenSyncStatusForItem(syncPath)
listenSyncStatusForItem(sync_path[0])


def generate_UUIDV4():
return str(uuid.uuid4())
59 changes: 37 additions & 22 deletions test/gui/shared/scripts/pageObjects/EnterPassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,69 @@


class EnterPassword:
LOGIN_DIALOG = {
"name": "LoginRequiredDialog",
"type": "OCC::LoginRequiredDialog",
"visible": 1,
}
USERNAME_BOX = {
"name": "usernameLineEdit",
"type": "QLineEdit",
"visible": 1,
"window": LOGIN_DIALOG,
}
PASSWORD_BOX = {
"container": names.loginRequiredDialog_contentWidget_QStackedWidget,
"name": "passwordLineEdit",
"type": "QLineEdit",
"visible": 1,
"window": LOGIN_DIALOG,
}
LOGIN_BUTTON = {
"text": "Log in",
"type": "QPushButton",
"unnamed": 1,
"visible": 1,
"window": names.loginRequiredDialog_OCC_LoginRequiredDialog,
"window": LOGIN_DIALOG,
}
COPY_URL_TO_CLIPBOARD_BUTTON = {
"container": names.loginRequiredDialog_contentWidget_QStackedWidget,
"name": "copyUrlToClipboardButton",
"type": "QPushButton",
"visible": 1,
"window": LOGIN_DIALOG,
}

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

def get_username(self):
return str(squish.waitForObjectExists(self.USERNAME_BOX).text)

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

@staticmethod
def oidcReLogin(username, password):
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 reLogin(username, password):
def reLogin(self, username, password):
if get_config('ocis'):
EnterPassword.oidcReLogin(username, password)
self.oidcReLogin(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)
41 changes: 27 additions & 14 deletions test/gui/shared/steps/account_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
from pageObjects.Toolbar import Toolbar
from pageObjects.AccountSetting import AccountSetting

from helpers.SetupClientHelper import substituteInLineCodes, getClientDetails
from helpers.SetupClientHelper import (
setUpClient,
startClient,
substituteInLineCodes,
getClientDetails,
generate_account_config,
getResourcePath,
)
from helpers.UserHelper import getDisplaynameForUser, getPasswordForUser
from helpers.SetupClientHelper import setUpClient, startClient
from helpers.SyncHelper import waitForInitialSyncToComplete
from helpers.SetupClientHelper import getResourcePath
from helpers.SyncHelper import waitForInitialSyncToComplete, listenSyncStatusForItem
from helpers.ConfigHelper import get_config


@Given(r'the user has added (the first|another) account with', regexp=True)
def step(context, accountType):
if accountType == 'another':
Toolbar.openNewAccountSetup()
account_details = getClientDetails(context)
AccountConnectionWizard.addAccount(account_details)


@When('the user adds the following wrong user credentials:')
def step(context):
account_details = getClientDetails(context)
Expand Down Expand Up @@ -52,14 +49,30 @@ def step(context, displayname, host):
@Given('user "|any|" has set up a client with default settings')
def step(context, username):
password = getPasswordForUser(username)
displayName = getDisplaynameForUser(username)
setUpClient(username, displayName)
setUpClient(username)
EnterPassword.loginAfterSetup(username, password)

# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', username))


@Given('the user has set up the following accounts with default settings:')
def step(context):
users = []
for row in context.table:
users.append(row[0])
sync_paths = generate_account_config(users)
startClient()
for idx, sync_path in enumerate(sync_paths):
listenSyncStatusForItem(sync_path)
# login from last dialog
enter_password = EnterPassword(len(sync_paths) - idx)
username = enter_password.get_username().capitalize()
enter_password.loginAfterSetup(username, getPasswordForUser(username))
# wait for files to sync
waitForInitialSyncToComplete(sync_path)


@Given('the user has started the client')
def step(context):
startClient()
Expand Down
3 changes: 1 addition & 2 deletions test/gui/shared/steps/spaces_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def step(context, user, space_name, role):
@Given('user "|any|" has set up a client with space "|any|"')
def step(context, user, space_name):
password = getPasswordForUser(user)
displayName = getDisplaynameForUser(user)
setUpClient(user, displayName, space_name)
setUpClient(user, space_name)
EnterPassword.loginAfterSetup(user, password)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', user, space_name))
Expand Down
8 changes: 3 additions & 5 deletions test/gui/tst_removeAccountConnection/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ 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
And user "Alice" has set up a client with default settings
And the user has added another account with
| server | %local_server% |
| user | Brian |
| password | AaBb2Cc3Dd4 |
And the user has set up the following accounts with default settings:
| Alice |
| Brian |
When the user removes the connection for user "Brian" and host %local_server_hostname%
Then the account with displayname "Brian Murphy" and host "%local_server_hostname%" should not be displayed
But the account with displayname "Alice Hansen" and host "%local_server_hostname%" should be displayed
Expand Down

0 comments on commit 872d75e

Please sign in to comment.