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

[tests-only] Added more gui tests for sharing with user (Part 02) #9323

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def hook(context):
DEFAULT_CONFIG = {
'localBackendUrl': 'https://localhost:9200/',
'secureLocalBackendUrl': 'https://localhost:9200/',
'clientSyncTimeout': 60,
'clientSyncTimeout': 10,
'middlewareUrl': 'http://localhost:3000/',
'clientConfigFile': '-',
'clientRootSyncPath': '/tmp/client-bdd/',
Expand Down
87 changes: 59 additions & 28 deletions test/gui/shared/scripts/pageObjects/PublicLinkDialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import names
import squish
import test
import datetime
from datetime import datetime


class PublicLinkDialog:
Expand Down Expand Up @@ -72,6 +72,9 @@ class PublicLinkDialog:
"visible": 1,
}

# to store current default public link expiry date
defaultExpiryDate = ''

def openPublicLinkDialog(self):
squish.mouseClick(
squish.waitForObject(self.PUBLIC_LINKS_TAB),
Expand Down Expand Up @@ -139,40 +142,57 @@ def setPassword(self, password):
def toggleExpirationDate(self):
squish.clickButton(squish.waitForObject(self.EXPIRYDATE_CHECKBOX))

@staticmethod
def setDefaultExpiryDate(defaultDate):
defaultDate = datetime.strptime(defaultDate, '%m/%d/%y')
PublicLinkDialog.defaultExpiryDate = (
f"{defaultDate.year}-{defaultDate.month}-{defaultDate.day}"
)

@staticmethod
def getDefaultExpiryDate():
return PublicLinkDialog.defaultExpiryDate

def setExpirationDate(self, expireDate):
enabled = squish.waitForObjectExists(self.EXPIRYDATE_CHECKBOX).checked
if not enabled:
self.toggleExpirationDate()

expDate = datetime.datetime.strptime(expireDate, '%Y-%m-%d')
expYear = expDate.year - 2000
squish.mouseClick(
squish.waitForObject(self.EXPIRATION_DATE_FIELD),
0,
0,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
squish.nativeType("<Delete>")
squish.nativeType("<Delete>")
squish.nativeType(expDate.month)
squish.nativeType(expDate.day)
squish.nativeType(expYear)
squish.nativeType("<Return>")
if not expireDate == "default":
expDate = datetime.strptime(expireDate, '%Y-%m-%d')
expYear = expDate.year - 2000
squish.mouseClick(
squish.waitForObject(self.EXPIRATION_DATE_FIELD),
0,
0,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
squish.nativeType("<Delete>")
squish.nativeType("<Delete>")
squish.nativeType(expDate.month)
squish.nativeType(expDate.day)
squish.nativeType(expYear)
squish.nativeType("<Return>")

actualDate = squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
expectedDate = f"{expDate.month}/{expDate.day}/{expYear}"
if not actualDate == expectedDate:
# retry with workaround
self.setExpirationDateWithWorkaround(expYear, expDate.month, expDate.day)
actualDate = str(
squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
)
expectedDate = f"{expDate.month}/{expDate.day}/{expYear}"
if not actualDate == expectedDate:
# retry with workaround
self.setExpirationDateWithWorkaround(
expYear, expDate.month, expDate.day
)

squish.waitFor(
lambda: (test.vp("publicLinkExpirationProgressIndicatorInvisible"))
)
test.compare(
str(squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText),
str(expectedDate),
)
squish.waitFor(
lambda: (test.vp("publicLinkExpirationProgressIndicatorInvisible"))
)
else:
defaultDate = str(
squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
)
PublicLinkDialog.setDefaultExpiryDate(defaultDate)

# This workaround is needed because the above function 'setExpirationDate'
# will not work while creating new public link
Expand Down Expand Up @@ -246,3 +266,14 @@ def verifyResource(self, resource):
str(squish.waitForObjectExists(self.ITEM_TO_SHARE).text),
resource,
)

def verifyExpirationDate(self, expectedDate):
expectedDate = datetime.strptime(expectedDate, '%Y-%m-%d')
# date format in client UI is 'mm/dd/yy' e.g. '01/15/22'
expYear = expectedDate.year - 2000
saw-jan marked this conversation as resolved.
Show resolved Hide resolved
expectedDate = f"{expectedDate.month}/{expectedDate.day}/{expYear}"

test.compare(
str(squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText),
str(expectedDate),
)
128 changes: 102 additions & 26 deletions test/gui/shared/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import names
import os
import sys
from os import listdir
from os import listdir, rename
from os.path import isfile, join, isdir
import re
import urllib.request
Expand Down Expand Up @@ -157,20 +157,16 @@ def isFileSynced(fileName):
return isItemSynced('FILE', fileName)


def waitForFileToBeSynced(context, fileName):
def waitForFileToBeSynced(context, filePath):
waitFor(
lambda: isFileSynced(
sanitizePath(context.userData['currentUserSyncPath'] + fileName)
),
lambda: isFileSynced(sanitizePath(filePath)),
context.userData['clientSyncTimeout'] * 1000,
)


def waitForFolderToBeSynced(context, folderName):
def waitForFolderToBeSynced(context, folderPath):
waitFor(
lambda: isFolderSynced(
sanitizePath(context.userData['currentUserSyncPath'] + folderName)
),
lambda: isFolderSynced(sanitizePath(folderPath)),
context.userData['clientSyncTimeout'] * 1000,
)

Expand Down Expand Up @@ -334,19 +330,23 @@ def step(context):
waitForFolderToBeSynced(context, '/')


@When('the user waits for file "|any|" to be synced')
def step(context, fileName):
waitForFileToBeSynced(context, fileName)
def waitForResourceToSync(context, resource, resourceType):
resource = join(context.userData['currentUserSyncPath'], resource)

if resourceType == "file":
waitForFileToBeSynced(context, resource)
elif resourceType == "folder":
waitForFolderToBeSynced(context, resource)

@When('the user waits for folder "|any|" to be synced')
def step(context, folderName):
waitForFolderToBeSynced(context, folderName)

@When(r'the user waits for (file|folder) "([^"]*)" to be synced', regexp=True)
def step(context, type, resource):
waitForResourceToSync(context, resource, type)

@Given('the user has waited for file "|any|" to be synced')
def step(context, fileName):
waitForFileToBeSynced(context, fileName)

@Given(r'the user has waited for (file|folder) "([^"]*)" to be synced', regexp=True)
def step(context, type, resource):
waitForResourceToSync(context, resource, type)


@Given(
Expand All @@ -363,6 +363,13 @@ def step(context, username, filename):
createFile(context, filename, username)


@When(
'user "|any|" tries to create a file "|any|" with the following content inside the sync folder'
)
def step(context, username, filename):
createFile(context, filename, username)


def createFile(context, filename, username=None):
fileContent = "\n".join(context.multiLineText)
syncPath = None
Expand All @@ -380,6 +387,11 @@ def step(context, username, foldername):
createFolder(context, foldername, username)


@When('user "|any|" tries to create a folder "|any|" inside the sync folder')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need an extra step here, that does the same thing as the one above?

actually the user does not only try to create a folder, the user creates a folder (on the local disk) but it might or might not get synced to the server.

Same for the steps with files

def step(context, username, foldername):
createFolder(context, foldername, username)


@Given('user "|any|" has created a folder "|any|" inside the sync folder')
def step(context, username, foldername):
createFolder(context, foldername, username)
Expand All @@ -395,13 +407,34 @@ def createFolder(context, foldername, username=None):
os.makedirs(path)


def renameFileFolder(context, source, destination):
source = join(context.userData['currentUserSyncPath'], source)
destination = join(context.userData['currentUserSyncPath'], destination)
rename(source, destination)


@When('the user copies the folder "|any|" to "|any|"')
def step(context, sourceFolder, destinationFolder):
source_dir = join(context.userData['currentUserSyncPath'], sourceFolder)
destination_dir = join(context.userData['currentUserSyncPath'], destinationFolder)
shutil.copytree(source_dir, destination_dir)


@When('the user renames a folder "|any|" to "|any|"')
def step(context, sourceFolder, destinationFolder):
renameFileFolder(context, sourceFolder, destinationFolder)


@When('the user renames a file "|any|" to "|any|"')
def step(context, sourceFile, destinationFile):
renameFileFolder(context, sourceFile, destinationFile)


@When('the user tries to rename a file "|any|" to "|any|"')
def step(context, sourceFile, destinationFile):
renameFileFolder(context, sourceFile, destinationFile)


@Given(r"^(.*) on the server (.*)$", regexp=True)
def step(context, stepPart1, stepPart2):
executeStepThroughMiddleware(context, "Given " + stepPart1 + " " + stepPart2)
Expand Down Expand Up @@ -685,6 +718,21 @@ def step(context, resource, password):
createPublicLinkShare(context, resource, password)


@Then('the expiration date of the last public link of file "|any|" should be "|any|"')
def step(context, resource, expiryDate):
openSharingDialog(context, resource)
publicLinkDialog = PublicLinkDialog()
publicLinkDialog.openPublicLinkDialog()

if expiryDate.strip("%") == "default":
expiryDate = PublicLinkDialog.getDefaultExpiryDate()

publicLinkDialog.verifyExpirationDate(expiryDate)

shareItem = SharingDialog()
shareItem.closeSharingDialog()


def setExpirationDateWithVerification(resource, publicLinkName, expireDate):
publicLinkDialog = PublicLinkDialog()
publicLinkDialog.verifyResource(resource)
Expand Down Expand Up @@ -721,11 +769,18 @@ def step(context):
linkSettings = {}
for row in context.table:
linkSettings[row[0]] = row[1]

if "path" not in linkSettings:
raise Exception("'path' is required but not given.")

if "expireDate" in linkSettings and linkSettings['expireDate'] == "%default%":
linkSettings['expireDate'] = linkSettings['expireDate'].strip("%")

createPublicLinkShare(
context,
resource=linkSettings['path'],
password=linkSettings['password'],
expireDate=linkSettings['expireDate'],
password=linkSettings['password'] if "password" in linkSettings else None,
expireDate=linkSettings['expireDate'] if "expireDate" in linkSettings else None,
)


Expand Down Expand Up @@ -918,6 +973,7 @@ def step(context, resource, group):
@When('the user overwrites the file "|any|" with content "|any|"')
def step(context, resource, content):
print("starting file overwrite")
resource = join(context.userData['currentUserSyncPath'], resource)
waitForFileToBeSynced(context, resource)
waitForFolderToBeSynced(context, '/')

Expand All @@ -928,21 +984,20 @@ def step(context, resource, content):

snooze(5)

f = open(context.userData['currentUserSyncPath'] + resource, "w")
f = open(resource, "w")
f.write(content)
f.close()

print("file has been overwritten")
waitForFileToBeSynced(context, resource)


@When('the user tries to overwrite the file "|any|" with content "|any|"')
def step(context, resource, content):
def tryToOverwriteFile(context, resource, content):
waitForFileToBeSynced(context, resource)
waitForFolderToBeSynced(context, '/')

try:
f = open(context.userData['currentUserSyncPath'] + resource, "w")
f = open(resource, "w")
f.write(content)
f.close()
except:
Expand All @@ -951,6 +1006,18 @@ def step(context, resource, content):
waitForFileToBeSynced(context, resource)


@When('the user tries to overwrite the file "|any|" with content "|any|"')
def step(context, resource, content):
resource = context.userData['currentUserSyncPath'] + resource
tryToOverwriteFile(context, resource, content)


@When('user "|any|" tries to overwrite the file "|any|" with content "|any|"')
def step(context, user, resource, content):
resource = getResourcePath(context, resource, user)
tryToOverwriteFile(context, resource, content)


def enableVFSSupport(vfsBtnText):
# The enabling/disabling VFS button do not have it's own object
# But it is inside the "stack_folderList_QTreeView" object.
Expand Down Expand Up @@ -1030,8 +1097,7 @@ def step(context, errorMsg):
test.compare(str(waitForObjectExists(newAccount.ERROR_LABEL).text), errorMsg)


@When(r'the user deletes the (file|folder) "([^"]*)"', regexp=True)
def step(context, itemType, resource):
def deleteResource(context, itemType, resource):
resourcePath = sanitizePath(context.userData['currentUserSyncPath'] + resource)
if itemType == 'file':
os.remove(resourcePath)
Expand All @@ -1041,6 +1107,16 @@ def step(context, itemType, resource):
raise Exception("No such item type for resource")


@When(r'the user deletes the (file|folder) "([^"]*)"', regexp=True)
def step(context, itemType, resource):
deleteResource(context, itemType, resource)


@When(r'the user tries to delete the (file|folder) "([^"]*)"', regexp=True)
def step(context, itemType, resource):
deleteResource(context, itemType, resource)


@When(
'the user unshares the resource "|any|" for collaborator "|any|" using the client-UI'
)
Expand Down
Loading