예제 #1
0
    def test_serialization_contains_required_keys(self):
        schedule_item = ScheduleItem(
            day="Monday",
            start="Start",
            end="End",
            room="Canteen",
        )

        serialized_schedule_item = schedule_item.serialize()
        self.assert_serialization_contains_keys(
            keys=["day", "start", "end", "room"],
            serialized_object=serialized_schedule_item,
        )
예제 #2
0
    def test_serialization_values(self):
        schedule_item = ScheduleItem(
            day="Monday",
            start="Start",
            end="End",
            room="Canteen",
        )

        serialized_schedule_item = schedule_item.serialize()

        assert serialized_schedule_item["day"] == schedule_item.day
        assert serialized_schedule_item["start"] == schedule_item.start
        assert serialized_schedule_item["end"] == schedule_item.end
        assert serialized_schedule_item["room"] == schedule_item.room
예제 #3
0
 def generate_random_schedule_item(cls):
     return ScheduleItem(
         day=cls.get_random_string(16),
         start=cls.get_random_string(16),
         end=cls.get_random_string(16),
         room=cls.get_random_string(64),
     )
예제 #4
0
    def test_schedule_item_fields_validation(self):
        test_cases = [
            {"day": "Monday" * 10, "start": "Start", "end": "End", "room": "Room"},
            {"day": "Monday" * 10, "start": "Start" * 5, "end": "End", "room": "Room"},
            {
                "day": "Monday" * 10,
                "start": "Start" * 5,
                "end": "End" * 10,
                "room": "Room",
            },
            {
                "day": "Monday" * 10,
                "start": "Start" * 5,
                "end": "End" * 10,
                "room": "Room" * 20,
            },
        ]

        for case in test_cases:
            with pytest.raises(ValidationError):
                ScheduleItem(
                    day=case["day"],
                    start=case["start"],
                    end=case["end"],
                    room=case["room"],
                ).validate()
예제 #5
0
    def create_period(self, major_id):
        """Create dummy period with its course and class"""

        class_obj = Class(
            name='Anum - A',
            schedule_items=[
                ScheduleItem(
                    day='Senin',
                    start='09.40',
                    end='08.00',
                    room='A6.09 (Ged Baru)',
                ),
            ],
            lecturer=['Nama Dosen 1', 'Nama Dosen 2'],
        )

        course = Course(
            name=self.COURSE['name'],
            credit=self.COURSE['credit'],
            term=self.COURSE['term'],
            classes=[class_obj],
        )

        period = Period.objects().create(
            major_id=major_id,
            name=app.config["ACTIVE_PERIOD"],
            is_detail=True,
            courses=[course],
        )

        return period
예제 #6
0
 def generate_random_class_item(cls):
     return Class(
         name=cls.get_random_string(128),
         schedule_items=[
             ScheduleItem(
                 day=cls.get_random_string(6),
                 start=cls.get_random_string(6),
                 end=cls.get_random_string(6),
                 room=cls.get_random_string(4),
             )
         ],
         lecturer=[cls.get_random_string(5)],
     )
예제 #7
0
def create_courses(html, is_detail=False):
    soup = BeautifulSoup(html, 'html.parser')
    if is_detail:
        classes = soup.find_all('th', class_='sub border2 pad2')
    else:
        classes = soup.find_all('th', class_='sub border2 pad1')

    courses = []
    for class_ in classes:
        course_name = class_.strong.text
        m = re.search('([0-9]+) SKS, Term ([0-9]+)', class_.text)
        if m:
            credit, term = m.group().split(' SKS, Term ')

        classes = []
        for sib in class_.parent.find_next_siblings('tr'):
            if (sib.get('class') == None):
                break

            class_name = sib.a.text
            try:
                schedules = str(sib.contents[9]).split('<br/>')
                schedules[0] = schedules[0].replace('<td nowrap="">', '')
                schedules[-1] = schedules[-1].replace('</td>', '')

                rooms = str(sib.contents[11]).split('<br/>')
                if is_detail:
                    rooms[0] = rooms[0].replace('<td>', '')
                else:
                    rooms[0] = rooms[0].replace('<td class="ce">', '')
                rooms[-1] = rooms[-1].replace('</td>', '')

                lecturers = str(sib.contents[13]).split('<br/>')
                lecturers[0] = lecturers[0].replace('<td>', '')
                lecturers[-1] = lecturers[-1].replace('</td>', '')
                lecturers = [l.lstrip('-') for l in lecturers]

                result = []
                schedules = zip(schedules, rooms)
                for schedule, room in schedules:
                    day, time = schedule.split(', ')
                    start, end = time.split('-')
                    result.append(
                        ScheduleItem(day=day, start=start, end=end, room=room))

                classes.append(
                    Class(name=class_name,
                          schedule_items=result,
                          lecturer=lecturers))

            except (IndexError, ValueError) as e:
                pass

        if classes:
            courses.append(
                Course(name=course_name,
                       credit=credit,
                       term=term,
                       classes=classes))

    return courses