def testValidate(self): val = Validate(MultiDict([(u'size', u'0')])) size_cond = [ ["%(name)s must be an integer", lambda i: not isinstance(int(i), int)], ["%(name)s cannot be negative", lambda i: int(i) < 0 ], ["%(name)s cannot exceed max value", lambda i: int(i) > 1024 ] ] # size is valid val.validate('size', size_cond) val = Validate(MultiDict([(u'size', u'foo')])) self.assertRaises(HTTPPreconditionFailed, val.validate, 'size', size_cond)
def download_sub(self): print 'Validation: ' + str(self.validate) if self.validate: validate = Validate(self.movie_path) chain_iterators = chain(DBSub().download_sub(self.movie_path), OpenSubs().download_sub(self.movie_path)) for file_path in chain_iterators: if self.validate: subs = pysrt.open(file_path) text_slices = subs.slice(starts_after={'minutes': validate.start_min - 1, 'seconds': 59}, ends_before={'minutes': validate.start_min, 'seconds': 11}) text = '' for t_slice in text_slices.data: text = text + t_slice.text + ' ' text = ' '.join(text.split()) print("For file : {} Movie Text is : {}".format(file_path, text)) if validate.validate(text): print("Found validated subtitle") self._final(True) return os.remove(file_path) else: continue self._final(False)
def pickRequest(self, dbUpdateObject, sessionObject, botResponse, item): print botResponse + "Response 8" validateObject = Validate() info = self.messageSplit(botResponse) print botResponse + "Response 9" req_fields = dictonary.required_fields[info[1]].split('&') bot_qry = dictonary.bot_query func_map = dictonary.function_map print botResponse + "Response 10" for i in range(0, (len(req_fields) - 2)): info[i + 2] = validateObject.validate(i, info[i + 2]) print botResponse + "Response 11" if str(info[i + 2]) == '0' or info[i + 2] == 0.0 or str( info[i + 2]) == '': print botResponse + "Response 12" print bot_qry[req_fields[i + 1]] print item[1] x = sessionObject.respond(bot_qry[req_fields[i + 1]], item[1]) print x return x temp = func_map[req_fields[len(req_fields) - 1]]( info, item[1], dbUpdateObject, sessionObject) ########## print "Naman Agarwal\n\n" + temp + "\n\n" dbUpdateObject.deletePendingRequest(item) return temp
def validate(): result = Validate.validate() return jsonify(result)