| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | class ResultTests(WebUntisTestCase): | |
| 8 | 8 | Result = webuntis.objects.Result | |
| 9 | + | ||
| 9 | 10 | def test_initialization(self): | |
| 10 | 11 | r = self.Result(data={'id': 123}, session=object()) | |
| 11 | 12 | self.assert_strict_equal(r.id, int(r), 123) | |
@@ -89,12 +90,12 @@ class CustomListResult(self.Result): | |||
| 89 | 90 | x = list(r.filter(id=1)) | |
| 90 | 91 | self.assert_strict_equal(x, [results[1]]) | |
| 91 | 92 | ||
| 92 | - x = list(r.filter(id=set([1,2]))) | ||
| 93 | + x = list(r.filter(id=set([1, 2]))) | ||
| 93 | 94 | self.assert_strict_equal(x, [results[1], results[2]]) | |
| 94 | 95 | ||
| 95 | 96 | self.assert_strict_equal( | |
| 96 | - list(r.filter(id=set([1,2])).filter(one='eins')), | ||
| 97 | - list(r.filter(one='eins', id=set([1,2]))), | ||
| 97 | + list(r.filter(id=set([1, 2])).filter(one='eins')), | ||
| 98 | + list(r.filter(one='eins', id=set([1, 2]))), | ||
| 98 | 99 | [results[1]] | |
| 99 | 100 | ) | |
| 100 | 101 | ||
@@ -111,6 +112,7 @@ def test_basics(self): | |||
| 111 | 112 | self.assert_strict_equal(x.name, u'ZIMMER') | |
| 112 | 113 | self.assert_strict_equal(x.long_name, u'Das Zimmer') | |
| 113 | 114 | ||
| 115 | + | ||
| 114 | 116 | class HolidayTests(WebUntisTestCase): | |
| 115 | 117 | def test_basics(self): | |
| 116 | 118 | x = webuntis.objects.HolidayObject( | |
@@ -146,6 +148,7 @@ def test_basics(self): | |||
| 146 | 148 | ||
| 147 | 149 | class PeriodTests(WebUntisTestCase): | |
| 148 | 150 | Obj = webuntis.objects.PeriodObject | |
| 151 | + | ||
| 149 | 152 | def test_dates(self): | |
| 150 | 153 | x = self.Obj( | |
| 151 | 154 | data={ | |
@@ -181,7 +184,7 @@ def test_type(self): | |||
| 181 | 184 | self.assert_strict_equal(x.type, u'ls') | |
| 182 | 185 | ||
| 183 | 186 | for type in (u'ls', u'oh', u'sb', u'bs', u'ex'): | |
| 184 | - x = self.Obj(data={u'lstype':type}, session=object()) | ||
| 187 | + x = self.Obj(data={u'lstype': type}, session=object()) | ||
| 185 | 188 | self.assert_strict_equal(x.type, type) | |
| 186 | 189 | ||
| 187 | 190 | x = self.Obj(data={u'type': u'hoompaloompa'}, session=object()) | |
@@ -219,7 +222,6 @@ class parent(object): | |||
| 219 | 222 | assert x.end.strftime('%Y-%m-%d') == '2012-09-01' | |
| 220 | 223 | assert x.name == u'Holidayz' | |
| 221 | 224 | ||
| 222 | - | ||
| 223 | 225 | def test_list(self): | |
| 224 | 226 | class StubSession(object): | |
| 225 | 227 | def _request(s, method): | |
@@ -251,7 +253,7 @@ def test_basics(self): | |||
| 251 | 253 | session=object() | |
| 252 | 254 | ) | |
| 253 | 255 | ||
| 254 | - self.assert_strict_equal(x.name, u'Math') | ||
| 256 | + self.assert_strict_equal(x.name, u'Math') | ||
| 255 | 257 | self.assert_strict_equal(x.long_name, u'Mathematics') | |
| 256 | 258 | ||
| 257 | 259 | ||
@@ -270,6 +272,7 @@ def test_basics(self): | |||
| 270 | 272 | self.assert_strict_equal(x.long_name, x.surname, u'Gans') | |
| 271 | 273 | self.assert_strict_equal(x.name, u'Hans Gans') | |
| 272 | 274 | ||
| 275 | + | ||
| 273 | 276 | class TimeStampTests(WebUntisTestCase): | |
| 274 | 277 | def test_basics(self): | |
| 275 | 278 | x = webuntis.objects.TimeStampObject( | |
@@ -283,5 +286,18 @@ def test_basics(self): | |||
| 283 | 286 | self.assertEqual(x.date.time().hour, exp.time().hour) | |
| 284 | 287 | self.assertEqual(x.date.time().minute, exp.time().minute) | |
| 285 | 288 | self.assertEqual(x.date.time().second, exp.time().second) | |
| 286 | - | ||
| 287 | - | ||
| 289 | + | ||
| 290 | + | ||
| 291 | + class TimegridTests(WebUntisTestCase): | ||
| 292 | + def test_basics(self): | ||
| 293 | + x = webuntis.objects.TimegridObject( | ||
| 294 | + data=[{'day': 2, 'timeUnits': [{'startTime': 710, 'name': '0', 'endTime': 800}, | ||
| 295 | + {'startTime': 800, 'name': '1', 'endTime': 850}, | ||
| 296 | + {'startTime': 850, 'name': '2', 'endTime': 940}]}], | ||
| 297 | + session = object()) | ||
| 298 | + | ||
| 299 | + self.assertEqual(x[0].day, 2) | ||
| 300 | + self.assertEqual(x[0].dayname, "monday") | ||
| 301 | + self.assertEqual(x[0].timeUnits[0].name, "0") | ||
| 302 | + self.assertEqual(x[0].timeUnits[1].start, datetime.time(8, 0)) | ||
| 303 | + self.assertEqual(x[0].timeUnits[2].end, datetime.time(9, 40)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -631,3 +631,42 @@ class SubstitutionList(ListResult): | |||
| 631 | 631 | '''A list of substitutions in form of :py:class:`SubstitutionObject` instances.''' | |
| 632 | 632 | _itemclass = SubstitutionObject | |
| 633 | 633 | ||
| 634 | + | ||
| 635 | + class TimeUnitObject(Result): | ||
| 636 | + @lazyproperty | ||
| 637 | + def name(self): | ||
| 638 | + '''Name of Timeunit''' | ||
| 639 | + return self._data[u'name'] | ||
| 640 | + | ||
| 641 | + @lazyproperty | ||
| 642 | + def start(self): | ||
| 643 | + return datetime_utils.parse_time( | ||
| 644 | + self._data[u'startTime'] | ||
| 645 | + ).time() | ||
| 646 | + | ||
| 647 | + @lazyproperty | ||
| 648 | + def end(self): | ||
| 649 | + return datetime_utils.parse_time( | ||
| 650 | + self._data[u'endTime'] | ||
| 651 | + ).time() | ||
| 652 | + | ||
| 653 | + class TimegridDayObject(Result): | ||
| 654 | + @lazyproperty | ||
| 655 | + def day(self): | ||
| 656 | + return self._data[u'day'] | ||
| 657 | + | ||
| 658 | + @lazyproperty | ||
| 659 | + def dayname(self): | ||
| 660 | + names = { 1:"sunday", 2:"monday", 3:"tuesday", 4:"wednesday", 5:"thursday", 6: "friday", 7:"saturday" } | ||
| 661 | + return names[self._data[u'day']] | ||
| 662 | + | ||
| 663 | + @lazyproperty | ||
| 664 | + def timeUnits(self): | ||
| 665 | + return [ | ||
| 666 | + TimeUnitObject(parent=self, data=data) | ||
| 667 | + for data in self._data[u'timeUnits'] | ||
| 668 | + ] | ||
| 669 | + | ||
| 670 | + class TimegridObject(ListResult): | ||
| 671 | + _itemclass = TimegridDayObject | ||
| 672 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -309,6 +309,11 @@ def substitutions(self, start, end, departmentId=0): | |||
| 309 | 309 | return objects.SubstitutionList, 'getSubstitutions', parameters | |
| 310 | 310 | ||
| 311 | 311 | ||
| 312 | + @result_wrapper | ||
| 313 | + def TimegridUnits(self): | ||
| 314 | + return objects.TimegridObject, 'getTimegridUnits', {} | ||
| 315 | + | ||
| 316 | + | ||
| 312 | 317 | class Session(JSONRPCSession, ResultWrapperMixin): | |
| 313 | 318 | '''The origin of everything you want to do with the WebUntis API. Can be | |
| 314 | 319 | used as a context-manager to provide automatic log-out. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments