nrthomas%gmail.com 6ca7836c2f Bug 816408, support for promptWaitTime attribute, r=rhelmer
git-svn-id: svn://10.0.0.236/trunk@264584 18797224-902f-48f8-a5cc-f745e15eee43
2012-12-20 23:15:58 +00:00

212 lines
6.8 KiB
Python
Executable File

"""
Python translation of fit..
which is copyright (c) 2002 Cunningham & Cunningham, Inc.
Released under the terms of the GNU General Public License version 2 or later.
"""
import feedparser # http://feedparser.org/
import urllib2
from urllib import pathname2url
from fit.ColumnFixture import ColumnFixture
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('khan!', 'khan.mozilla.org', 'morgamic', 'carebears')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
class Verify(ColumnFixture):
_typeDict={"host": "String",
"updateVersion": "String",
"product": "String",
"version": "String",
"build": "String",
"platform": "String",
"locale": "String",
"channel": "String",
"complete": "String",
"partial": "String",
"updateType": "String",
"osVersion": "String",
"dist": "String",
"distVersion": "String",
"force": "String",
"newchannel": "String",
"licenseUrl": "String",
"lastURI": "String",
"newURI": "String",
"hasUpdate": "Boolean",
"hasComplete": "Boolean",
"hasPartial": "Boolean",
"hasLicenseUrl": "Boolean",
"isValidXml": "Boolean",
"isMinorUpdate": "Boolean",
"isMajorUpdate": "Boolean",
"hasForce": "Boolean",
"hasBillboardURL": "Boolean",
"isShowPrompt": "Boolean",
"isShowNeverForVersion": "Boolean",
"isShowSurvey": "Boolean",
"hasActions": "Boolean",
"hasOpenURL": "Boolean",
"hasNotificationURL": "Boolean",
"hasAlertURL": "Boolean",
"hasPromptWaitTime": "Boolean"}
def __init__(self):
super(Verify, self).__init__()
# Variables that are typically set in the FitNesse wiki params.
self.updateVersion = ""
self.host = ""
self.product = ""
self.version = ""
self.platform = ""
self.locale = ""
self.osVersion = ""
self.dist = ""
self.distVersion = ""
self.force = ""
self.newchannel = ""
self.billboardURL = ""
self.showPrompt = ""
self.showNeverForVersion = ""
self.showSurvey = ""
self.actions = ""
self.openURL = ""
self.notificationURL = ""
self.alertURL = ""
self.promptWaitTime = ""
# For storing the last retrieved AUS XML and its URI.
self.lastURI = ""
self.lastXML = ""
# Checks if an update element exists.
def hasUpdate(self):
return ('</update>' in self.getXml())
# Checks if the expected complete patch exists.
def hasComplete(self):
return (self.complete in self.getXml())
# Check if the expected partial patch exists.
def hasPartial(self):
return (self.partial in self.getXml())
# Check if the update type is "minor".
def isMinorUpdate(self):
return ('type="minor"' in self.getXml())
# Check if the update type is "major".
def isMajorUpdate(self):
return ('type="major"' in self.getXml())
# Check to see if the XML has a licenseURL.
def hasLicenseUrl(self):
return (self.licenseUrl in self.getXml())
# Check to see if the XML has force set.
def hasForce (self):
return ('force=1' in self.getXml())
def hasBillboardURL(self):
return ('billboardURL="http://billboardURL"' in self.getXml())
def isShowPrompt(self):
return ('showPrompt="true"' in self.getXml())
def isShowNeverForVersion(self):
return ('showNeverForVersion="true"' in self.getXml())
def isShowSurvey(self):
return ('showSurvey="true"' in self.getXml())
def hasActions(self):
return ('actions="showNotification showAlert"' in self.getXml())
def hasOpenURL(self):
return ('openURL="http://openURL' in self.getXml())
def hasNotificationURL(self):
return ('notificationURL="http://notificationURL' in self.getXml())
def hasAlertURL(self):
return ('alertURL="http://alertURL' in self.getXml())
def hasPromptWaitTime(self):
return ('promptWaitTime="999' in self.getXml())
# Check if the AUS XML document is well-formed.
def isValidXml(self):
# Parse our file, creating a feedparser object.
xml = feedparser.parse(self.getXml())
print xml.version
# If xml.bozo==1, the feed was malformed and unparsable.
if (xml.bozo==1):
return False
# We should always have an xml version.
if ('<?xml version="1.0"?>' not in self.getXml()):
return False
# We should always have a parent 'updates' element.
if ('<updates>' not in self.getXml()):
return False
return True
# Gets and returns an AUS XML document.
def getXml(self):
newURI = self.buildUri();
if (self.lastURI == newURI):
return self.lastXML
print newURI
newXML = urllib2.urlopen(newURI).read()
self.lastURI = newURI
self.lastXML = newXML
return newXML
# Builds an AUS URI based on our test data.
def buildUri(self):
# Assign class variables from FitNesse arguments if they
# are not passed in from the row.
if (not self.host): self.host = self.args[0]
if (not self.updateVersion): self.updateVersion = self.args[1]
if (not self.product): self.product = self.args[2]
if (not self.version): self.version = self.args[3]
if (not self.platform): self.platform = self.args[4]
if (not self.locale): self.locale = self.args[5]
if (not self.osVersion): self.osVersion = self.args[6]
if (self.osVersion != "NULL"):
url = '/'.join((self.host,
pathname2url('/'.join((self.updateVersion, self.product, self.version,
self.build, self.platform, self.locale,
self.channel, self.osVersion, self.dist,
self.distVersion, "update.xml")))
))
else:
url = '/'.join((self.host,
pathname2url('/'.join((self.updateVersion, self.product, self.version,
self.build, self.platform, self.locale,
self.channel, "update.xml")))
))
if (self.force == 'true'):
url += '?force=1'
if (self.newchannel != "NULL"):
url += '?newchannel=' + self.newchannel
return url