def validate(g, studentRepo, disciplineRepo): _errors = "" try: g.grade[0] = int(g.grade[0]) except ValueError: raise ValidatorException("Grade must be an integer!") if g.studentId not in studentRepo._entities: _errors = "Student's id not found!\n" if g.disciplineId not in disciplineRepo._entities: _errors += "Discipline's id not found\n" if (g.grade[0] < 1 or g.grade[0] > 10) and g.grade[0] != 0: _errors += "Grade can't be smaller than 1/ higher than 10!\n" if len(_errors) > 0: raise ValidatorException(_errors)
def validateTitle(self, title): self._errors = [] if len(title) == 0: self._errors.append("Error! The book must have a title.") if len(self._errors) != 0: raise ValidatorException(self._errors) return True
def validate(self, client): _errors = [] if type(client.id) != int or client.id <= 0: _errors.append("Wrong Id type or value!") if len(client.name) == 0: _errors.append("The name field can not be empty!") if len(_errors) != 0: raise ValidatorException(_errors)
def validate(d): _errors = "" if d.name == None or any(char.isdigit() for char in d.name) == True or d.name == "": _errors = "Discipline's name can't be empty or contain digits!" if len(_errors) > 0: raise ValidatorException(_errors)
def validate(self, rental): _errorList = [] now = datetime.date.today() if rental.rentedDate < now: _errorList.append("The rental starts in the past!") if rental.rentedDate == rental.dueDate: _errorList.append("Rental must be at least one day!") if len(_errorList) != 0: raise ValidatorException(_errorList)
def validate(self, student): ''' Validates a student ''' _errors = "" if student.name == None or any(char.isdigit() for char in student.name) == True or student.name == "": _errors = "Student's name can't be empty or contain digits!" if len(_errors) > 0: raise ValidatorException(_errors)
def validate(self, rental): if isinstance(rental, Rental) == False: raise TypeError("Not a Rental") _errorList = [] now = date(2000, 1, 1) if rental.start < now: _errorList.append("Rental starts in past;") if len(rental) < 1: _errorList.append("Rental must be at least 1 day;") if len(_errorList) > 0: raise ValidatorException(_errorList)
def validate(self, grade): if isinstance(grade, Grade): raise TypeError("Not a Grade") _errors = [] try: if int(grade) < 1 or int(grade) > 10: _errors.append("Invalid grade") except TypeError: _errors.append("Grade should be a number") if len(_errors) > 0: raise ValidatorException(_errors)
def validate(self, movie): errors = [] if type(movie.id) != int or movie.id <= 0: errors.append("Wrong Id type or value!") if len(movie.title) == 0: errors.append("The field title can not be empty!") if len(movie.description) == 0: errors.append("The field description can not be empty!") if len(movie.genre) == 0: errors.append("The field genre can not be empty!") if len(errors) != 0: raise ValidatorException(errors)
def validate(self, book): ''' Validates the provided Book instance Output: - a list of validation errors None, if book is a valid Book ''' if isinstance(book, Book) == False: raise TypeError( "Error! The validator can validate only Book objects.") self._errors = [] self.validateTitle(book.getTitle()) if len(self._errors) != 0: raise ValidatorException(self._errors) return True
def validate(self, client): """ Validate if provided Client instance is valid client - Instance of Client type Return List of validation errors. An empty list if instance is valid. """ if isinstance(client, Client) == False: raise TypeError("Not x Client") _errors = [] if self._isCNPValid(client.cnp) == False: _errors.append("CNP not valid.;") if len(client.name) == 0: _errors.append("Name not valid.") if len(_errors) != 0: raise ValidatorException(_errors)
def validate(self, car): """ Validate if provided Car instance is valid car - Instance of Car type Return List of validation errors. An empty list if instance is valid. """ if isinstance(car, Car) == False: raise TypeError("Can only validate Car objects!") _errors = [] if len(car.getMake()) == 0: _errors.append("Car must have a make") if len(car.getModel()) == 0: _errors.append("Car must have a model;") if self._licensePlateValid(car.getId()) == False: _errors.append("Bad license plate number;") if len(self._errors) > 0: raise ValidatorException(_errors)
def validate(self, assignment): if isinstance(assignment, Assignment) == False: raise TypeError("Can only validate Assignment objects") _errors = [] if len(assignment.getId()) == 0: _errors.append("No ID provided") if len(assignment.getDeadline()) == 0: _errors.append("No deadline provided") if len(assignment.getDescription()) == 0: _errors.append("No description provided") if self._assIdValid(assignment.getId()) == False: _errors.append("Invalid ID") if self._deadlineValid(assignment.getDeadline()) == False: _errors.append("Invalid Deadline") if self._descriptionValid(assignment.getDescription()) == False: _errors.append("Invalid Description") if len(_errors) > 0: raise ValidatorException(_errors) return True
def validate(self, student): if isinstance(student, Student) == False: raise TypeError("Can only validate Student objects") _errors = [] if (len(student.getId())) == 0: _errors.append("No ID given") if (len(student.getGroup())) == 0: _errors.append("No group given") if (len(student.getName())) == 0: _errors.append("No name given") if self._studIdValid(student.getId()) == False: _errors.append("ID not valid") if self._studGroupValid(student.getGroup()) == False: _errors.append("Group not valid") if self._studNameValid(student.getName()) == False: _errors.append("Name not valid") if len(_errors) > 0: raise ValidatorException(_errors) return True