Commit 085469b8 authored by Christian Stenger's avatar Christian Stenger

Squish: Enhance tst_codepasting

* set a random expiry for the paste
* make sure server side errors are handled

Change-Id: I28feab982fefbb97a9f603144943a57cc268538c
Reviewed-by: default avatarRobert Loehning <robert.loehning@digia.com>
parent 1e3f1508
......@@ -196,6 +196,7 @@
:Send to Codepaster.Description:_QLabel {name='descriptionLabel' text='Description:' type='QLabel' visible='1' window=':Send to Codepaster_CodePaster::PasteView'}
:Send to Codepaster.Paste_QPushButton {text='Paste' type='QPushButton' unnamed='1' visible='1' window=':Send to Codepaster_CodePaster::PasteView'}
:Send to Codepaster.protocolBox_QComboBox {name='protocolBox' type='QComboBox' visible='1' window=':Send to Codepaster_CodePaster::PasteView'}
:Send to Codepaster.qt_spinbox_lineedit_QLineEdit {name='qt_spinbox_lineedit' type='QLineEdit' visible='1' window=':Send to Codepaster_CodePaster::PasteView'}
:Send to Codepaster.stackedWidget_QStackedWidget {name='stackedWidget' type='QStackedWidget' visible='1' window=':Send to Codepaster_CodePaster::PasteView'}
:Send to Codepaster_CodePaster::PasteView {name='CodePaster__Internal__ViewDialog' type='CodePaster::PasteView' visible='1' windowTitle='Send to Codepaster'}
:Session Manager_ProjectExplorer::Internal::SessionDialog {name='ProjectExplorer__Internal__SessionDialog' type='ProjectExplorer::Internal::SessionDialog' visible='1' windowTitle='Session Manager'}
......
......@@ -28,16 +28,26 @@
#############################################################################
source("../../shared/qtcreator.py")
import random
def invalidPasteId(protocol):
if protocol == 'Paste.KDE.Org':
return None
else:
return -1
def main():
startApplication("qtcreator" + SettingsPath)
if not startedWithoutPluginError():
return
protocolsToTest = ["Paste.KDE.Org"]
protocolsToTest = ["Paste.KDE.Org", "Pastebin.Ca"]
# Be careful with Pastebin.Com, there are only 10 pastes per 24h
# for all machines using the same IP-address like you.
# protocolsToTest += ["Pastebin.Com"]
sourceFile = os.path.join(os.getcwd(), "testdata", "main.cpp")
aut = currentApplicationContext()
# make sure General Messages is open
openGeneralMessages()
for protocol in protocolsToTest:
invokeMenuItem("File", "Open File or Project...")
selectFromFileDialog(sourceFile)
......@@ -53,10 +63,31 @@ def main():
type(waitForObject(":uiDescription_QLineEdit"), description)
typeLines(pasteEditor, "// tst_codepasting %s" % datetime.utcnow())
pastedText = pasteEditor.plainText
expiry = waitForObject(":Send to Codepaster.qt_spinbox_lineedit_QLineEdit")
expiryDays = random.randint(1, 10)
replaceEditorContent(expiry, "%d" % expiryDays)
test.log("Using expiry of %d days." % expiryDays)
# make sure to read all former errors (they won't get read twice)
aut.readStderr()
clickButton(waitForObject(":Send to Codepaster.Paste_QPushButton"))
outputWindow = waitForObject(":Qt Creator_Core::OutputWindow")
waitFor("not outputWindow.plainText.isEmpty()", 20000)
pasteId = str(outputWindow.plainText).rsplit("/", 1)[1]
output = str(outputWindow.plainText)
stdErrOut = aut.readStderr()
match = re.search("^%s protocol error: (.*)$" % protocol, stdErrOut, re.MULTILINE)
if match:
pasteId = invalidPasteId(protocol)
if "Internal Server Error" in match.group(1):
test.warning("Server Error - trying to continue...")
else:
test.fail("%s protocol error: %s" % (protocol, match.group(1)))
elif output.strip() == "":
pasteId = invalidPasteId(protocol)
elif "Post limit, maximum pastes per 24h reached" in output:
test.warning("Maximum pastes per day exceeded.")
pasteId = None
else:
pasteId = output.rsplit("/", 1)[1]
clickButton(waitForObject(":*Qt Creator.Clear_QToolButton"))
invokeMenuItem('File', 'Revert "main.cpp" to Saved')
clickButton(waitForObject(":Revert to Saved.Proceed_QPushButton"))
......@@ -68,14 +99,25 @@ def main():
selectFromCombo(":CodePaster__Internal__PasteSelectDialog.protocolBox_QComboBox", protocol)
pasteModel = waitForObject(":CodePaster__Internal__PasteSelectDialog.listWidget_QListWidget").model()
waitFor("pasteModel.rowCount() > 1", 20000)
try:
pasteLine = filter(lambda str: pasteId in str, dumpItems(pasteModel))[0]
except:
test.fail("Could not find id '%s' in list of pastes from %s" % (pasteId, protocol))
clickButton(waitForObject(":CodePaster__Internal__PasteSelectDialog.Cancel_QPushButton"))
continue
if protocol == "Pastebin.Com":
test.verify(description in pasteLine, "Verify that line in list of pastes contains the description")
if protocol == 'Pastebin.Ca':
description = description[:32]
if pasteId == -1:
try:
pasteLine = filter(lambda str: description in str, dumpItems(pasteModel))[0]
pasteId = pasteLine.split(" ", 1)[0]
except:
test.fail("Could not find description line in list of pastes from %s" % protocol)
clickButton(waitForObject(":CodePaster__Internal__PasteSelectDialog.Cancel_QPushButton"))
continue
else:
try:
pasteLine = filter(lambda str: pasteId in str, dumpItems(pasteModel))[0]
except:
test.fail("Could not find id '%s' in list of pastes from %s" % (pasteId, protocol))
clickButton(waitForObject(":CodePaster__Internal__PasteSelectDialog.Cancel_QPushButton"))
continue
if protocol.startswith("Pastebin."):
test.verify(description in pasteLine, "Verify that line in list of pastes contains the description")
pasteLine = pasteLine.replace(".", "\\.")
waitForObjectItem(":CodePaster__Internal__PasteSelectDialog.listWidget_QListWidget", pasteLine)
clickItem(":CodePaster__Internal__PasteSelectDialog.listWidget_QListWidget", pasteLine, 5, 5, 0, Qt.LeftButton)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment