def move(self, user, room): UserHelper.move(user, processor=self.processor, building_id=room.building_id, level=room.level, room_number=room.number) session.session.refresh(user)
def _execute(self, task, parameters: UserMoveParams): from pycroft.lib import user as lib_user if task.user.room is None: self.errors.append("Tried to move in user, " "but user was already living in a dormitory.") return room = lib_user.get_room( room_number=parameters.room_number, level=parameters.level, building_id=parameters.building_id, ) if room is None: self.errors.append( "Tried to move user, but target room did not exist.") return lib_user.move( user=task.user, building_id=room.building.id, level=room.level, room_number=room.number, comment=parameters.comment, processor=task.creator, ) self.new_status = TaskStatus.EXECUTED
def test_0020_moves_into_other_dormitory(self): UserHelper.move(self.user, self.new_room_other_dormitory.dormitory, self.new_room_other_dormitory.level, self.new_room_other_dormitory.number, self.processing_user) self.assertEqual(self.user.room, self.new_room_other_dormitory) self.assertEqual(self.user.user_hosts[0].room, self.new_room_other_dormitory)
def test_0020_moves_into_other_building(self): UserHelper.move( self.user, self.new_room_other_building.building.id, self.new_room_other_building.level, self.new_room_other_building.number, self.processing_user, ) self.assertEqual(self.user.room, self.new_room_other_building) self.assertEqual(self.user.hosts[0].room, self.new_room_other_building)
def test_0020_moves_into_other_building(self): # whether old traffic groups get deleted is untested, # because adding a `default_traffic_group` is hard with our # fixture setup traffic_group = user.TrafficGroup.q.first() UserHelper.move( self.user, self.new_room_other_building.building, self.new_room_other_building.level, self.new_room_other_building.number, self.processing_user, traffic_group_id=traffic_group.id, ) self.assertEqual(self.user.room, self.new_room_other_building) self.assertEqual(self.user.hosts[0].room, self.new_room_other_building) self.assertIn(traffic_group, self.user.active_traffic_groups())
def test_move_scheduling(self): when = session.utcnow() + timedelta(days=1) UserHelper.move( self.user, building_id=self.new_room_other_building.building.id, level=self.new_room_other_building.level, room_number=self.new_room_other_building.number, processor=self.processing_user, when=when, ) tasks = self.session.query(Task).all() assert len(tasks) == 1 [task] = tasks assert isinstance(task, UserTask) assert task.user == self.user assert task.parameters == UserMoveParams( building_id=self.new_room_other_building.building.id, level=self.new_room_other_building.level, room_number=self.new_room_other_building.number, )
def _execute(self, task, parameters): from pycroft.lib import user as lib_user if task.user.room is not None: room = Room.q.filter_by( number=parameters['room_number'], level=parameters['level'], building_id=parameters['building_id']).first() if room is not None: lib_user.move(task.user, room.building.id, room.level, room.number, task.creator) self.new_status = TaskStatus.EXECUTED else: self.errors.append( "Tried to move user, but target room did not exist.") else: self.errors.append( "Tried to move in user, but user was already living in a dormitory." )
def test_room_history_move(self): session.session.refresh(self.room) old_room = self.user.room move(self.user, self.room.building_id, self.room.level, self.room.number, self.processor) found_old = False found_new = False for rhe in self.user.room_history_entries: self.assertIsNotNone(rhe.begins_at) if rhe.room == old_room: self.assertIsNotNone(rhe.ends_at) found_old = True elif rhe.room == self.room: self.assertIsNone(rhe.ends_at) found_new = True self.assertTrue(found_new, "Did not find new history entry") self.assertTrue(found_old, "Did not find old history entry")
def test_room_history_move(self): session.session.refresh(self.room) old_room = self.user.room move(self.user, self.room.building_id, self.room.level, self.room.number, self.processor) found_old = False found_new = False for rhe in self.user.room_history_entries: assert rhe.active_during.begin is not None if rhe.room == old_room: assert rhe.active_during.end is not None found_old = True elif rhe.room == self.room: assert rhe.active_during.end is None found_new = True assert found_new, "Did not find new history entry" assert found_old, "Did not find old history entry"