def getStringChecked(self, sField): """ Check if specified field is present in server response and returns it as string. If not present, a fitting exception will be raised. """ if not sField in self._dResponse: raise testboxcommons.TestBoxException( 'Required data (' + str(sField) + ') was not found in server response') return str(self._dResponse[sField]).strip()
def checkParameterCount(self, cExpected): """ Checks the parameter count, raise TestBoxException if it doesn't meet the expectations. """ if len(self._dResponse) != cExpected: raise testboxcommons.TestBoxException( 'Expected %d parameters, server sent %d' % (cExpected, len(self._dResponse))) return True
def getIntChecked(self, sField, iMin=None, iMax=None): """ Check if specified field is present in server response and returns it as integer. If not present, a fitting exception will be raised. The iMin and iMax values are inclusive. """ if not sField in self._dResponse: raise testboxcommons.TestBoxException( 'Required data (' + str(sField) + ') was not found in server response') try: iValue = int(self._dResponse[sField]) except: raise testboxcommons.TestBoxException( 'Malformed integer field %s: "%s"' % (sField, self._dResponse[sField])) if (iMin is not None and iValue < iMin) \ or (iMax is not None and iValue > iMax): raise testboxcommons.TestBoxException('Value (%d) of field %s is out of range [%s..%s]' \ % (iValue, sField, iMin, iMax)) return iValue