def test_validatorStr(self): validator = Validator() valid = validator.validate('') self.assertFalse(valid) valid = validator.validate(' ') self.assertFalse(valid) valid = validator.validate('auqywsdsad') self.assertFalse(valid)
def test_validator(self): validator = Validator() valid = validator.validate('0898474635') self.assertTrue(valid) valid = validator.validate('0752781937') self.assertTrue(valid) validator = Validator() valid = validator.validate('0619871528') self.assertTrue(valid) valid = validator.validate('0549371528') self.assertFalse(valid)
def test_validator(self): validator = Validator() with open(self.abs_file_path) as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='|') index = 0 for row in reader: index = index + 1 # skip title row and only check in use postcodes if index > 1 and row[1] == "Yes": valid = validator.validate(row[0]) self.assertTrue(valid)
def quiz(): """ Gets requested Quiz :param id: Quiz id :return: A json representation of a Quiz class :rtype: str :exception QuizNotFoundException: Thrown when getting a quiz that does not exist in the database """ if request.method == 'GET': try: id = request.args.get('_id') mquiz = db.get_quiz(id) if mquiz is None: e = QuizNotFoundException() app.logger.error(str(e)) return BaseExceptionSchema().dump(e), 400 return jsonify(mquiz), 200 except Exception as e: app.logger.error(str(e)) return BaseExceptionSchema().dump(e), 500 elif request.method == 'POST': """ Posts requested quiz :param _id: Quiz id :type _id: str :param responses: An array of string representing user choices :type responses: List :return result: Score user achieved on the quiz :rtype result: str :exception QuizNotFoundException: Thrown when submitting responses for a quiz that does not exist :exception InvalidResponsesException: Thrown when responses have invalid structures or at least one response does not exist in the options """ try: id = request.get_json()['_id'] responses = request.get_json()['responses'] quiz = db.get_quiz_internal(id) if quiz is None: e = QuizNotFoundException() app.logger.error(str(e)) return BaseExceptionSchema().dump(e), 400 validator = Validator(quiz, responses) if validator.validate(): db.insert_quiz_response(id, responses, validator.get_result) return jsonify(validator.get_result), 200 else: e = InvalidResponsesException() app.logger.error(str(e)) return BaseExceptionSchema().dump(e), 400 except Exception as e: app.logger.error(str(e)) return BaseExceptionSchema().dump(e), 500
def test_validatorValid(self): validator = Validator() validator.validate(" 8711205106085") self.assertTrue(validator.isValid) validator = Validator() validator.validate("8711205106085 ") self.assertTrue(validator.isValid) validator = Validator() validator.validate("8711205106085") self.assertTrue(validator.isValid)
def test_validatorStrings(self): validator = Validator() validator.validate("") self.assertFalse(validator.isValid) validator = Validator() validator.validate(" ") self.assertFalse(validator.isValid) validator = Validator() validator.validate("8711a05v0f085") self.assertFalse(validator.isValid)
class ValidatorTests(unittest.TestCase): def setUp(self): self.validator = Validator() def test_validatorNone(self): self.validator.validate(None) self.assertFalse(self.validator.isValid) def test_validatorNum(self): self.validator.validate("None") self.assertFalse(self.validator.isValid) self.validator.validate("12a312") self.assertFalse(self.validator.isValid) self.validator.validate(True) self.assertFalse(self.validator.isValid) val = Validator() self.validator.validate(val) self.assertFalse(self.validator.isValid) self.validator.validate("1745438912") self.assertTrue(self.validator.isValid) def test_validatorTrim(self): self.validator.validate(" 1745438912") self.assertTrue(self.validator.isValid) self.validator.validate("1745438912 ") self.assertTrue(self.validator.isValid) def test_validatorLen(self): self.validator.validate(" 1745438912") self.assertTrue(self.validator.isValid) self.validator.validate(" 174543812") self.assertFalse(self.validator.isValid) self.validator.validate("745438912") self.assertFalse(self.validator.isValid) self.validator.validate("1745438912") self.assertTrue(self.validator.isValid) def test_validator(self): # test remainder 10 self.validator.validate("1645418912") self.assertFalse(self.validator.isValid) # test remainder 11 self.validator.validate("1645418822") self.assertFalse(self.validator.isValid) def tearDown(self): self.validator = None
import cv2 from src.validator import Validator Validator.init_angle_detector( '/home/lyan/PycharmProjects/face_detection/data/settings.json') camera_port = 0 ramp_frames = 30 camera = cv2.VideoCapture(camera_port) def get_image(): # read is the easiest way to get a full image out of a VideoCapture object. retval, im = camera.read() return im # Ramp the camera - these frames will be discarded and are only used to allow v4l2 # to adjust light levels, if necessary for i in xrange(ramp_frames): temp = get_image() print("Taking image...") while True: im = get_image() print Validator.validate(im) cv2.imshow('result', im) if cv2.waitKey(1) & 0xFF == ord('q'): break
def test_validatorClass(self): validator = Validator() valid = validator.validate(validator) self.assertFalse(valid)
def test_validatorNone(self): validator = Validator() valid = validator.validate(None) self.assertFalse(valid)
def test_validatorInvalid(self): validator = Validator() validator.validate("7711205106085") self.assertFalse(validator.isValid)