def test_create_resident(self): """ Tests that residents can be created """ resident = Resident.query.filter( Resident.user_id == self.test_user.id).first() self.assertIsNotNone(resident) old_room = RoomService.get_room_by_number('') self.assertTrue(resident in old_room.occupants)
def validate_room_number(form, field): # pylint: disable=no-self-argument, no-self-use """ Validates that room number does not already exist Args: form: The RegisterRoomForm that was submitted. field: The room_number field. Raises: ValidationError: If room number already exists. """ if RoomService.get_room_by_number(field.data) is not None: raise ValidationError('A room with that number already exists')
def validate_room_number(form, field): # pylint: disable=no-self-argument, no-self-use """ Checks whether room number exists. Args: form: The ManageResidentsForm that was submitted. field: The room_number field. Raises: ValidationError: If room_number does not exist. """ if field.data != '' and RoomService.get_room_by_number( field.data) is None: raise ValidationError("Room doesn't exist")
def test_add_resident_to_room(self): """ Tests that residents can be added to a room """ test_user_info = ('*****@*****.**', 'Bob', 'Ross', 'RESIDENT') test_user = UserService.create_user(*test_user_info) resident = ResidentService.get_resident_by_id(test_user.id) old_room = RoomService.get_room_by_number('') self.assertTrue(resident in old_room.occupants) RoomService.add_resident_to_room(test_user.email, self.test_room.number) self.assertEqual(resident.room_number, self.test_room.number) self.assertTrue(resident in self.test_room.occupants) self.assertFalse(resident in old_room.occupants)
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_number(self): """ Tests that get_room_by_number returns None for an invalid room number """ room = RoomService.get_room_by_number('429') self.assertIsNone(room)
def test_get_room_by_number(self): """ Tests that get_room_by_number returns the correct room """ room = RoomService.get_room_by_number(self.test_room.number) self.assertEqual((room.number, room.status, room.type), self.test_room_info)
def test_edit_room_invalid(self): """ Tests that rooms can be edited""" self.assertRaises(AttributeError, RoomService.edit_room, self.test_room.id + 3, '6', 'Bad', 'Double') self.assertIsNone(RoomService.get_room_by_number('6'))