def validate_room_number(form, field): # pylint: disable=no-self-argument """ Checks whether room_number is unique. Args: form: The ManageRoomForm that was submitted. field: The room_number field. Raises: ValidationError: If the room_number already exists. """ room = RoomService.get_room_by_id(form.room_id.data) if room: number = room.number if (field.data != number) and RoomService.get_room_by_number( field.data) is not None: raise ValidationError('A room with that number already exists') else: raise ValidationError('Room does not exist')
def test_invalid_get_room_by_id(self): """ Tests that get_room_by_id returns None for an invalid room id """ room = RoomService.get_room_by_id(5) self.assertIsNone(room)
def test_get_room_by_id(self): """ Tests that get_room_by_id returns the correct room """ room = RoomService.get_room_by_id(self.test_room.id) self.assertEqual((room.number, room.status, room.type), self.test_room_info)