Ejemplo n.º 1
0
    def test_getklassen(self):
        jsonstr = get_json_resource('getklassen_mock.json')
        schoolyear_id = 123

        def getKlassen(url, jsondata, headers):
            if len(methods['getKlassen'].calls) == 2:
                self.assertEqual(jsondata['params']['schoolyearId'],
                                 schoolyear_id)

            self.assertFalse(len(methods['getKlassen'].calls) > 2)
            return {'result': jsonstr}

        methods = {'getKlassen': getKlassen}

        with mock_results(methods):
            klassen = self.session.klassen()
            for klasse_raw, klasse in raw_vs_object(jsonstr, klassen):
                self.assertEqual(klasse_raw['id'], klasse.id)
                self.assertEqual(klasse_raw['name'], klasse.name)
                self.assertEqual(klasse_raw['longName'], klasse.long_name)

            self.assertEqual(klassen.filter(id=129)[0].id, 129)
            self.assertEqual(
                [129, 130, 137],
                sorted(
                    kl.id for kl in
                    klassen.filter(id=set([129, 130, 137]))
                )
            )

            self.assertTrue({'id': 129} in klassen)
            self.assertTrue({'name': '6A'} in klassen)

            # calling a second time for validating the schoolyear
            self.session.klassen(schoolyear=schoolyear_id)
Ejemplo n.º 2
0
    def test_getrooms(self):
        jsonstr = get_json_resource('getrooms_mock.json')

        def getRooms(url, jsondata, headers):
            return {'result': jsonstr}

        methods = {'getRooms': getRooms}

        with mock_results(methods):
            for room_raw, room in raw_vs_object(jsonstr, self.session.rooms()):
                self.assertEqual(room_raw['longName'], room.long_name)
                self.assertEqual(room_raw['name'], room.name)
                self.assertEqual(room_raw['id'], room.id)
Ejemplo n.º 3
0
    def test_getteachers(self):
        jsonstr = get_json_resource('getteachers_mock.json')

        def getTeachers(url, jsondata, headers):
            return {'result': jsonstr}

        methods = {'getTeachers': getTeachers}

        with mock_results(methods):
            for t_raw, t in raw_vs_object(jsonstr, self.session.teachers()):
                self.assertEqual(t_raw['longName'], t.long_name)
                self.assertEqual(t_raw['longName'], t.surname)
                self.assertEqual(t_raw['foreName'], t.fore_name)
                self.assertEqual(t_raw['name'], t.name)
Ejemplo n.º 4
0
    def test_getsubjects(self):
        jsonstr = get_json_resource('getsubjects_mock.json')

        def getSubjects(url, jsondata, headers):
            return {'result': jsonstr}

        methods = {'getSubjects': getSubjects}

        with mock_results(methods):
            for subj_raw, subj in raw_vs_object(
                    jsonstr, self.session.subjects()):
                self.assertEqual(subj_raw['id'], subj.id)
                self.assertEqual(subj_raw['name'], subj.name)
                self.assertEqual(subj_raw['longName'], subj.long_name)
Ejemplo n.º 5
0
    def test_getdepartments(self):
        jsonstr = get_json_resource('getdepartments_mock.json')

        def getDepartments(url, jsondata, headers):
            return {'result': jsonstr}

        methods = {'getDepartments': getDepartments}

        with mock_results(methods):
            for dep_raw, dep in raw_vs_object(
                    jsonstr, self.session.departments()):
                self.assertEqual(dep_raw['id'], dep.id)
                self.assertEqual(dep_raw['longName'], dep.long_name)
                self.assertEqual(dep_raw['name'], dep.name)
Ejemplo n.º 6
0
    def test_getholidays(self):
        jsonstr = get_json_resource('getholidays_mock.json')

        def getHolidays(url, jsondata, headers):
            return {'result': jsonstr}

        methods = {'getHolidays': getHolidays}

        with mock_results(methods):
            for holiday_raw, holiday in raw_vs_object(
                    jsonstr, self.session.holidays()):
                self.assertEqual(holiday_raw['id'], holiday.id)
                self.assertEqual(holiday_raw['name'], holiday.short_name)
                self.assertEqual(holiday_raw['longName'], holiday.name)

                self.assertEqual(
                    holiday_raw['startDate'],
                    int(holiday.start.strftime('%Y%m%d'))
                )
                self.assertEqual(
                    holiday_raw['endDate'],
                    int(holiday.end.strftime('%Y%m%d'))
                )
Ejemplo n.º 7
0
    def test_getschoolyears(self):
        jsonstr = get_json_resource('getschoolyears_mock.json')
        current_json = jsonstr[3]

        def getSchoolyears(url, jsondata, headers):
            return {'result': jsonstr}

        def getCurrentSchoolyear(url, jsondata, headers):
            return {'result': current_json}

        methods = {
            'getSchoolyears': getSchoolyears,
            'getCurrentSchoolyear': getCurrentSchoolyear
        }

        with mock_results(methods):
            schoolyears = self.session.schoolyears()

            self.assertEqual(current_json['id'], schoolyears.current.id)
            self.assertTrue(schoolyears.current.is_current)
            current_count = 0
            for year_raw, year in raw_vs_object(jsonstr, schoolyears):
                self.assertEqual(year_raw['id'], year.id)
                self.assertEqual(year_raw['name'], year.name)

                self.assertEqual(
                    year_raw['startDate'],
                    int(year.start.strftime('%Y%m%d'))
                )
                self.assertEqual(
                    year_raw['endDate'],
                    int(year.end.strftime('%Y%m%d'))
                )
                if year.is_current:
                    self.assertEqual(year, schoolyears.current)
                    current_count += 1
                    self.assertEqual(current_count, 1)
Ejemplo n.º 8
0
    def test_gettimetables(self):
        jsonstr = get_json_resource('gettimetables_mock.json')
        jsonstr_kl = get_json_resource('getklassen_mock.json')
        jsonstr_te = get_json_resource('getteachers_mock.json')
        jsonstr_su = get_json_resource('getsubjects_mock.json')
        jsonstr_ro = get_json_resource('getrooms_mock.json')

        def getTimetable(url, jsondata, headers):
            return {'result': jsonstr}

        def getKlassen(url, jsondata, headers):
            return {'result': jsonstr_kl}

        def getTeachers(url, jsondata, headers):
            return {'result': jsonstr_te}

        def getSubjects(url, jsondata, headers):
            return {'result': jsonstr_su}

        def getRooms(url, jsondata, headers):
            return {'result': jsonstr_ro}

        methods = {
            'getTimetable': getTimetable,
            'getKlassen': getKlassen,
            'getTeachers': getTeachers,
            'getSubjects': getSubjects,
            'getRooms': getRooms
        }

        with mock_results(methods):
            tt = self.session.timetable(klasse=114, start='20120301', end='20120301')

            for period_raw, period in raw_vs_object(jsonstr, tt):
                self.assertEqual(
                    int(period.start.strftime('%H%M')),
                    period_raw['startTime']
                )
                self.assertEqual(
                    int(period.start.strftime('%Y%m%d')),
                    period_raw['date']
                )

                self.assertEqual(
                    int(period.end.strftime('%H%M')),
                    period_raw['endTime']
                )
                self.assertEqual(
                    int(period.end.strftime('%H%M')),
                    period_raw['endTime']
                )
                if 'code' in period_raw:
                    self.assertEqual(period_raw['code'], period.code)
                else:
                    self.assertEqual(period.code, None)

                if 'lstype' in period_raw:
                    self.assertEqual(period_raw['lstype'], period.type)
                else:
                    self.assertEqual(period.type, 'ls')

                self.assertEqual(len(period_raw['kl']), len(period.klassen))
                for klasse_raw, klasse in raw_vs_object(
                        period_raw['kl'], period.klassen):
                    self.assertEqual(klasse.id, klasse_raw['id'])

                self.assertEqual(len(period_raw['te']), len(period.teachers))
                for teacher_raw, teacher in raw_vs_object(
                        period_raw['te'], period.teachers):
                    self.assertEqual(teacher.id, teacher_raw['id'])

                self.assertEqual(len(period_raw['su']), len(period.subjects))
                for subject_raw, subject in raw_vs_object(
                        period_raw['su'], period.subjects):
                    self.assertEqual(subject.id, subject_raw['id'])

                self.assertEqual(len(period_raw['ro']), len(period.rooms))
                for room_raw, room in raw_vs_object(
                        period_raw['ro'], period.rooms):
                    self.assertEqual(room.id, room_raw['id'])

            def validate_table(periods, width=None):
                counter = 0
                table = periods.to_table(width=width)
                for time, row in table:
                    if width is not None:
                        row = list(row)
                        self.assertEqual(len(row), width)
                    for date, cell in row:
                        for hour in cell:
                            counter += 1

                self.assertEqual(counter, len(periods))

            validate_table(tt)
            validate_table(tt, width=999)
            self.assertRaises(ValueError, validate_table, tt, width=0)

            self.assertEqual(len(webuntis.utils.timetable_utils.table([])), 0)