Skip to content

Commit

Permalink
Update 2020 (#28)
Browse files Browse the repository at this point in the history
* new calls

* bump version to 0.1.12
  • Loading branch information
AugustH committed Jul 18, 2020
1 parent eb5aefe commit 51aa2df
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 8 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='webuntis',
version='0.1.11',
version='0.1.12',
author='Markus Unterwaditzer',
author_email='markus@unterwaditzer.net',
packages=find_packages(),
Expand All @@ -35,6 +35,7 @@
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: PyPy'
]
)
68 changes: 67 additions & 1 deletion tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class CustomListResult(self.Result):
x = list(r.filter(two='zwoa'))
self.assert_strict_equal(x, [results[2]])


x = list(r.filter(id=[1, 2]))
self.assert_strict_equal(x, [results[1], results[2]])
x = list(r.filter(id=[2, 1]))
Expand Down Expand Up @@ -361,6 +360,11 @@ class StubSession(object):
session=sess
)

cat1 = webuntis.objects.ClassRegCategoryGroup(
data={u'id': 2, u"name": u"group2"},
session=sess
)

def klassen(self, *args, **kw):
return webuntis.objects.KlassenList(
[self.klasse1], session=self.sess)
Expand All @@ -381,6 +385,9 @@ def students(self, *args, **kw):
return webuntis.objects.StudentsList(
[self.student1], session=self.sess)

def class_reg_category_groups(self, *args, **kw):
return webuntis.objects.ClassRegCategoryGroupList([self.cat1], session=self.sess)


class PeriodTestsData(WebUntisTestCase):
def test_data(self):
Expand Down Expand Up @@ -813,3 +820,62 @@ def testClassRegEventList(self):
assert type(crel) == webuntis.objects.ClassRegEventList
assert len(crel) == 2
assert type(crel[0]) is webuntis.objects.ClassRegEvent


class ClassRegCategoryGroupTests(WebUntisTestCase):

def testClassRegCategoryGroupList(self):
crcg = webuntis.objects.ClassRegCategoryGroupList(
data=[
{
"id": 1,
"name": "group1"
},
{
"id": 2,
"name": "group2"
}
],
session=object()
)
assert type(crcg) == webuntis.objects.ClassRegCategoryGroupList
assert len(crcg) == 2
first = crcg[0]
assert type(first) == webuntis.objects.ClassRegCategoryGroup
assert first.name == "group1"


class ClassRegCategoryTests(WebUntisTestCase):

def testClassRegCategoryList(self):
crc = webuntis.objects.ClassRegCategoryList(
data=[
{
u"id": 1,
u"name": "disturbs",
u"longName": "disturbs a lot"
},
{
u"id": 6,
u"name": "late",
u"longName": "often late",
u"groupId": 2
}
],
session=StubSession()
)
assert type(crc) == webuntis.objects.ClassRegCategoryList
assert len(crc) == 2

first = crc[0]
assert type(first) == webuntis.objects.ClassRegCategory
assert first.name == "disturbs"
assert first.longname == "disturbs a lot"

second = crc[1]
print("second = ", second)
assert type(second) == webuntis.objects.ClassRegCategory
assert second.name == "late"
assert second.longname == "often late"

assert type(second.group) == webuntis.objects.ClassRegCategoryGroup
18 changes: 16 additions & 2 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def inner(url, jsondata, headers):

def test_timetableWithAbsences(self):
s = webuntis.Session(**stub_session_parameters)
with self.absences_result_mock('getTimetableWithAbsences'):
with self.absences_result_mock(u'getTimetableWithAbsences'):
ex = s.timetable_with_absences(start=1, end=2)
assert type(ex) is webuntis.objects.AbsencesList

Expand All @@ -316,6 +316,20 @@ def test_use_cache(self):

def test_class_reg_events(self):
s = webuntis.Session(**stub_session_parameters)
with self.noop_result_mock('getClassregEvents'):
with self.noop_result_mock(u'getClassregEvents'):
ex = s.class_reg_events(start=1, end=2)
assert type(ex) is webuntis.objects.ClassRegEventList

def test_class_reg_categories(self):
s = webuntis.Session(**stub_session_parameters)
with self.noop_result_mock(u'getClassregCategories'):
crc = s.class_reg_categories()
assert type(crc) is webuntis.objects.ClassRegCategoryList
assert len(crc) == 0

def test_class_reg_category_groups(self):
s = webuntis.Session(**stub_session_parameters)
with self.noop_result_mock(u'getClassregCategoryGroups'):
crcg = s.class_reg_category_groups()
assert type(crcg) is webuntis.objects.ClassRegCategoryGroupList
assert len(crcg) == 0
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist=
py27,py34,py35,py36,py37,pypy
py27,py34,py35,py36,py37,py38,pypy2,pypy3
[testenv]
deps = pytest
mock
Expand Down
2 changes: 1 addition & 1 deletion webuntis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:copyright: (c) 2012 by Markus Unterwaditzer.
:license: BSD, see LICENSE for more details.
"""
__version__ = '0.1.11'
__version__ = '0.1.12'
from webuntis.session import Session

from webuntis import errors
48 changes: 47 additions & 1 deletion webuntis/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ def time_units(self):


class TimegridObject(ListResult):
"""A list of TimegridDayObjects"""
"""A list of TimegridDayObjects
"""
_itemclass = TimegridDayObject


Expand Down Expand Up @@ -1010,7 +1011,52 @@ def subject(self):
"""the subject of the classregevent."""
return self._data[u'subject']

@lazyproperty
def category(self):
"""which category"""
return self._session.class_reg_categories(from_cache=True).filter(
id=set(self._data[u'categoryId'])
)[0]


class ClassRegEventList(ListResult):
"""A list of ClassRegEvents."""
_itemclass = ClassRegEvent


class ClassRegCategory(Result):
"""Represents an ClassRegCategory."""

@lazyproperty
def name(self):
"""name of category"""
return self._data[u'name']

@lazyproperty
def longname(self):
"""longname of category"""
return self._data[u'longName']

@lazyproperty
def group(self):
"""group"""
return self._session.class_reg_category_groups().filter(id=self._data[u'groupId'])[0]


class ClassRegCategoryList(ListResult):
"""A list of ClassRegCategories."""
_itemclass = ClassRegCategory


class ClassRegCategoryGroup(Result):
"""Represents an ClassRegCategoryGroup."""

@lazyproperty
def name(self):
"""name of group"""
return self._data[u'name']


class ClassRegCategoryGroupList(ListResult):
"""A list of ClassRegCategoriesGroups."""
_itemclass = ClassRegCategoryGroup
40 changes: 40 additions & 0 deletions webuntis/objects.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,43 @@ class ClassRegEventList(ListResult):

def __getitem__(self, i: int) -> ClassRegEvent:
...


class ClassRegCategoryGroup(Result):
@property
def name(self):
...


class ClassRegCategory(Result):
@property
def name(self) -> str:
...

@property
def longname(self) -> str:
...

@property
def group(self) -> ClassRegCategoryGroup:
...


class ClassRegCategoryList(ListResult):
_itemclass = ClassRegCategory

def filter(self, **criterions) -> ClassRegCategoryList:
...

def __getitem__(self, i: int) -> ClassRegCategory:
...


class ClassRegCategoryGroupList(ListResult):
_itemclass = ClassRegCategoryGroup

def filter(self, **criterions) -> ClassRegCategoryGroupList:
...

def __getitem__(self, i: int) -> ClassRegCategoryGroup:
...
76 changes: 75 additions & 1 deletion webuntis/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def exams(self, start, end, exam_type_id=0):
:type end: :py:class:`datetime.datetime` or :py:class:`datetime.date` or int
:param end: The end of the time period.
:param exam_type_id: int, ??
:param exam_type_id: int - id of Exam, @TODO: allow examtype id/name
:rtype: :py:class:`webuntis.objects.ExamsList`
"""
Expand Down Expand Up @@ -364,6 +364,80 @@ def class_reg_events(self, start, end):
parameters = self._create_date_param(end, start)
return objects.ClassRegEventList, 'getClassregEvents', parameters

# @TODO this is a copy of timetable()

@result_wrapper
def class_reg_event_for_id(self, start, end, **type_and_id):
"""Get the Information about the ClassRegEvents for a specific school class and time period.
:type start: :py:class:`datetime.datetime` or :py:class:`datetime.date` or int
:param start: The beginning of the time period.
:type end: :py:class:`datetime.datetime` or :py:class:`datetime.date` or int
:param end: The end of the time period.
:rtype: :py:class:`webuntis.objects.ClassRegEventList`
see timetable for the type_and_id parameter
:raises: :exc:`ValueError`, :exc:`TypeError`
"""
element_type_table = {
'klasse': 1,
'teacher': 2,
'subject': 3,
'room': 4,
'student': 5
}

invalid_type_error = TypeError(
'You have to specify exactly one of the following parameters by '
'keyword: ' +
(', '.join(element_type_table.keys()))
)

if len(type_and_id) != 1:
raise invalid_type_error

element_type, element_id = list(type_and_id.items())[0]

element_type = utils.userinput.string(element_type)

if element_type not in element_type_table:
raise invalid_type_error

# if we have to deal with an object in element_id,
# its id gets placed here anyway

parameters = self._create_date_param(end, start,
id=int(element_id), type=element_type_table[element_type])
return objects.ClassRegEventList, 'getClassregEvents', parameters

@result_wrapper
def class_reg_categories(self):
"""Information about the Request remark categories
:rtype: :py:class:`webuntis.objects.ClassRegClassRegCategoryList`
"""
return objects.ClassRegCategoryList, 'getClassregCategories', {}

@result_wrapper
def class_reg_category_groups(self):
"""Information about the Request remark categories groups
:rtype: :py:class:`webuntis.objects.ClassRegClassRegCategoryGroupList`
"""
return objects.ClassRegCategoryGroupList, 'getClassregCategoryGroups', {}

@result_wrapper
def class_reg_categories(self):
return objects.ClassRegCategoryList, 'getClassregCategories', {}

@result_wrapper
def class_reg_category_groups(self):
return objects.ClassRegCategoryGroupList, 'getClassregCategoryGroups', {}


@staticmethod
def _create_date_param(end, start, **kwargs):
json_start = utils.datetime_utils.format_date(start)
Expand Down

0 comments on commit 51aa2df

Please sign in to comment.