示例#1
0
文件: data.py 项目: a-deda/rooster
    def __init__(self):
        # Put csv in dataframe object
        dfStudents = pd.read_csv("files/studentenenvakken.csv",
                                 encoding="ISO-8859-1")
        dfCourses = pd.read_csv("files/courses.csv")

        students = []
        for index, row in dfStudents.iterrows():
            newStudent = Student(row[2])
            students.append(newStudent)

        self.courses = []
        for index, row in dfCourses.iterrows():
            newCourse = Course(row[0], students, row[3])
            self.courses.append(newCourse)

        # Set rooms with sizes
        room1 = Room(1, 41)
        room2 = Room(2, 22)
        room3 = Room(3, 20)
        room4 = Room(4, 56)
        room5 = Room(5, 48)
        room6 = Room(6, 117)
        room7 = Room(7, 60)
        self.rooms = [room1, room2, room3, room4, room5, room6, room7]

        # Set timeblocks
        timeblock1 = TimeBlock(1, 9)
        timeblock2 = TimeBlock(2, 11)
        timeblock3 = TimeBlock(3, 13)
        timeblock4 = TimeBlock(4, 15)
        self.timeblocks = [timeblock1, timeblock2, timeblock3, timeblock4]
示例#2
0
 def load_rooms_from_file(self):
     try:
         file = open(self.__rooms_filename, "r")
         line = file.readline().strip()
         while len(line) > 0:
             line = line.split(", ")
             room = Room(int(line[0]), line[1])
             self.__rooms.append(room)
             line = file.readline().strip()
         file.close()
     except IOError as io_error:
         print(str(io_error))
    def all(self, room_id, begin_at_or_after=None, begin_at_or_before=None):
        room = Room(self.room_service.find(room_id))
        if not begin_at_or_after and not begin_at_or_before:
            return room.schedules

        result = []
        for entry in room.schedules:
            schedule = Schedule(entry)
            if begin_at_or_after and schedule.begin.date() < begin_at_or_after:
                continue
            if begin_at_or_before and schedule.begin.date(
            ) > begin_at_or_before:
                continue
            result.append(schedule.__dict__)
        return result
    def edit(self,
             room_id,
             schedule_id,
             title=None,
             participants=[],
             begin=None,
             end=None):
        room = Room(self.room_service.find(room_id))
        schedule = self.find(room_id, schedule_id)
        schedule.title = title or schedule.title
        schedule.participants = participants or schedule.participants
        if begin: schedule.set_begin(begin)
        if end: schedule.set_end(end)

        room.remove_schedule(str(schedule._id))
        room.add_schedule(schedule)

        self.room_service.edit(room)
 def delete(self, room_id, schedule_id):
     room = Room(self.room_service.find(str(room_id)))
     room.remove_schedule(schedule_id)
     self.room_service.edit(room)
 def add(self, room_id, schedule):
     room = Room(self.room_service.find(str(room_id)))
     room.add_schedule(schedule)
     self.room_service.edit(room)
示例#7
0
def edit_room(room_id, name, capacity):
    room = Room(request.json)
    room.set_id(room_id)
    room_service.edit(room)
    return (dumps({'message': 'Edited Room'}), 204)
示例#8
0
def create_room(name, capacity):
    room = Room(request.json)
    room_service.create(room)
    return (dumps({'message': 'Room created'}), 201)
示例#9
0
import json
from unittest import mock
from domain.room import Room
from response_objects import response_objects as res

room_dict = {
    'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33',
    'size': 200,
    'price': 10,
    'longitude': -0.09998975,
    'latitude': 51.75436293
}
room = Room.from_dict(room_dict)
rooms = [room]


@mock.patch('use_cases.room_list_use_case.RoomListUseCase')
def test_get(mock_use_case, client):
    mock_use_case().execute.return_value = res.ResponseSuccess(rooms)
    http_response = client.get('/rooms')
    assert json.loads(http_response.data.decode('UTF-8')) == [room_dict]
    mock_use_case().execute.assert_called()
    args, kwargs = mock_use_case().execute.call_args
    assert args[0].filters == {}
    assert http_response.status_code == 200
    assert http_response.mimetype == 'application/json'


@mock.patch('use_cases.room_list_use_case.RoomListUseCase')
def test_get_with_filters(mock_use_case, client):
    mock_use_case().execute.return_value = res.ResponseSuccess(rooms)