| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,10 @@ | |||
| 11 | 11 | ||
| 12 | 12 | dependencies = ['requests'] | |
| 13 | 13 | ||
| 14 | - if version_info < (2,6): | ||
| 14 | + if version_info < (2, 6): | ||
| 15 | 15 | dependencies.append('simplejson') | |
| 16 | 16 | ||
| 17 | - if version_info < (2,7): | ||
| 17 | + if version_info < (2, 7): | ||
| 18 | 18 | dependencies.append('ordereddict') | |
| 19 | 19 | ||
| 20 | 20 | setup( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ | |||
| 5 | 5 | :license: BSD, see LICENSE for more details. | |
| 6 | 6 | """ | |
| 7 | 7 | ||
| 8 | - | ||
| 9 | 8 | import re | |
| 10 | 9 | import unittest | |
| 11 | 10 | import mock | |
@@ -27,8 +26,8 @@ | |||
| 27 | 26 | ||
| 28 | 27 | ||
| 29 | 28 | def get_json_resource(name): | |
| 30 | - with open(os.path.join(data_path, name)) as f: | ||
| 31 | - return json.load(f) | ||
| 29 | + with open(os.path.join(data_path, name)) as f: | ||
| 30 | + return json.load(f) | ||
| 32 | 31 | ||
| 33 | 32 | ||
| 34 | 33 | class WebUntisTestCase(unittest.TestCase): | |
@@ -37,7 +36,7 @@ def cb(*args, **kwargs): # pragma: no cover | |||
| 37 | 36 | raise Exception('These are offline tests.') | |
| 38 | 37 | ||
| 39 | 38 | self.request_patcher = patcher = \ | |
| 40 | - mock.patch('webuntis.utils.remote._send_request', new=cb) | ||
| 39 | + mock.patch('webuntis.utils.remote._send_request', new=cb) | ||
| 41 | 40 | patcher.start() | |
| 42 | 41 | ||
| 43 | 42 | def tearDown(self): | |
@@ -64,7 +63,7 @@ def _assert_strict_equal_impl(self, x, y): | |||
| 64 | 63 | return | |
| 65 | 64 | assert x == y | |
| 66 | 65 | assert issubclass(type(x), type(y)) or issubclass(type(y), type(x)), \ | |
| 67 | - '%s != %s' % (type(x), type(y)) | ||
| 66 | + '%s != %s' % (type(x), type(y)) | ||
| 68 | 67 | if isinstance(x, (bytes, str)) or x is None: | |
| 69 | 68 | return | |
| 70 | 69 | elif isinstance(x, dict) or isinstance(y, dict): | |
@@ -81,7 +80,6 @@ def _assert_strict_equal_impl(self, x, y): | |||
| 81 | 80 | assert repr(x) == repr(y), repr((x, y))[:200] | |
| 82 | 81 | ||
| 83 | 82 | ||
| 84 | - | ||
| 85 | 83 | stub_session_parameters = { | |
| 86 | 84 | 'useragent': 'fooagent', | |
| 87 | 85 | 'school': 'fooschool', | |
@@ -98,7 +96,7 @@ def cb(*args, **kwargs): # pragma: no cover | |||
| 98 | 96 | raise Exception('These are offline tests.') | |
| 99 | 97 | ||
| 100 | 98 | self.request_patcher = patcher = \ | |
| 101 | - mock.patch('webuntis.utils.remote._send_request', new=cb) | ||
| 99 | + mock.patch('webuntis.utils.remote._send_request', new=cb) | ||
| 102 | 100 | patcher.start() | |
| 103 | 101 | ||
| 104 | 102 | self.session = webuntis.Session(**stub_session_parameters) | |
@@ -112,7 +110,6 @@ def tearDown(self): | |||
| 112 | 110 | ||
| 113 | 111 | self.session = None | |
| 114 | 112 | ||
| 115 | - | ||
| 116 | 113 | ||
| 117 | 114 | def mock_results(methods, swallow_not_found=False): | |
| 118 | 115 | """Mock API methods more easily. | |
@@ -124,6 +121,7 @@ def mock_results(methods, swallow_not_found=False): | |||
| 124 | 121 | :param swallow_not_found: Whether to return {'result': {}} on unmocked API | |
| 125 | 122 | methods. | |
| 126 | 123 | """ | |
| 124 | + | ||
| 127 | 125 | def new(url, jsondata, headers, http_session): | |
| 128 | 126 | method = jsondata['method'] | |
| 129 | 127 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ def test_repr(self): | |||
| 44 | 44 | r1 = self.Result(data={u'id': 124}, session=object()) | |
| 45 | 45 | assert repr(r1) == u"Result({u'id': 124})" or repr(r1) == u"Result({'id': 124})" | |
| 46 | 46 | ||
| 47 | + | ||
| 47 | 48 | class ListResultTests(WebUntisTestCase): | |
| 48 | 49 | Result = webuntis.objects.ListResult | |
| 49 | 50 | lazyproperty = webuntis.utils.misc.lazyproperty | |
@@ -81,7 +82,6 @@ class CustomListResult(self.Result): | |||
| 81 | 82 | assert 'CustomListResult' in s | |
| 82 | 83 | assert 'CustomItem' in s | |
| 83 | 84 | ||
| 84 | - | ||
| 85 | 85 | def test_filter(self): | |
| 86 | 86 | class CustomItem(webuntis.objects.ListItem): | |
| 87 | 87 | @self.lazyproperty | |
@@ -302,8 +302,7 @@ def test_basics(self): | |||
| 302 | 302 | data=1420202020202, | |
| 303 | 303 | session=object() | |
| 304 | 304 | ) | |
| 305 | - exp = datetime.datetime(2015, 1, 2, 13, 33, 40,tzinfo=None) | ||
| 306 | - | ||
| 305 | + exp = datetime.datetime(2015, 1, 2, 13, 33, 40, tzinfo=None) | ||
| 307 | 306 | ||
| 308 | 307 | self.assertEqual(x.date.date(), exp.date()) | |
| 309 | 308 | # some differences py2 vs. py3: | |
@@ -320,7 +319,7 @@ def test_basics(self): | |||
| 320 | 319 | data=[{'day': 2, 'timeUnits': [{'startTime': 710, 'name': '0', 'endTime': 800}, | |
| 321 | 320 | {'startTime': 800, 'name': '1', 'endTime': 850}, | |
| 322 | 321 | {'startTime': 850, 'name': '2', 'endTime': 940}]}], | |
| 323 | - session = object()) | ||
| 322 | + session=object()) | ||
| 324 | 323 | ||
| 325 | 324 | self.assertEqual(x[0].day, 2) | |
| 326 | 325 | self.assertEqual(x[0].dayname, "monday") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,8 @@ | |||
| 2 | 2 | import mock | |
| 3 | 3 | import webuntis | |
| 4 | 4 | from . import WebUntisTestCase, stub_session_parameters, \ | |
| 5 | - mock_results | ||
| 5 | + mock_results | ||
| 6 | + | ||
| 6 | 7 | ||
| 7 | 8 | class BasicUsage(WebUntisTestCase): | |
| 8 | 9 | def test_login_repeat_not_logged_in(self): | |
@@ -11,9 +12,9 @@ def test_login_repeat_not_logged_in(self): | |||
| 11 | 12 | calls = [] | |
| 12 | 13 | ||
| 13 | 14 | expected_calls = ( | |
| 14 | - ['getCurrentSchoolyear', 'logout', 'authenticate'] | ||
| 15 | - * (retry_amount + 1) | ||
| 16 | - )[:-2] | ||
| 15 | + ['getCurrentSchoolyear', 'logout', 'authenticate'] | ||
| 16 | + * (retry_amount + 1) | ||
| 17 | + )[:-2] | ||
| 17 | 18 | ||
| 18 | 19 | def authenticate(url, jsondata, headers): | |
| 19 | 20 | calls.append(jsondata['method']) | |
@@ -32,6 +33,7 @@ def logout(url, jsondata, headers): | |||
| 32 | 33 | return { | |
| 33 | 34 | 'result': {'bla': 'blub'} # shouldn't matter | |
| 34 | 35 | } | |
| 36 | + | ||
| 35 | 37 | methods = { | |
| 36 | 38 | 'authenticate': authenticate, | |
| 37 | 39 | 'getCurrentSchoolyear': getCurrentSchoolyear, | |
@@ -40,8 +42,8 @@ def logout(url, jsondata, headers): | |||
| 40 | 42 | ||
| 41 | 43 | with mock_results(methods): | |
| 42 | 44 | with mock.patch.dict( | |
| 43 | - s.config, | ||
| 44 | - {'login_repeat': retry_amount} | ||
| 45 | + s.config, | ||
| 46 | + {'login_repeat': retry_amount} | ||
| 45 | 47 | ): | |
| 46 | 48 | self.assertRaises(webuntis.errors.NotLoggedInError, | |
| 47 | 49 | s._request, | |
@@ -74,8 +76,8 @@ def test_login_successful(self): | |||
| 74 | 76 | s = webuntis.Session(**session_params) | |
| 75 | 77 | ||
| 76 | 78 | with mock.patch( | |
| 77 | - 'webuntis.Session._request', | ||
| 78 | - return_value={'sessionId': '123456'} | ||
| 79 | + 'webuntis.Session._request', | ||
| 80 | + return_value={'sessionId': '123456'} | ||
| 79 | 81 | ) as mock_obj: | |
| 80 | 82 | s.login() | |
| 81 | 83 | assert s.config['jsessionid'] == '123456' | |
@@ -88,8 +90,8 @@ def test_login_no_response(self): | |||
| 88 | 90 | s = webuntis.Session(**session_params) | |
| 89 | 91 | ||
| 90 | 92 | with mock.patch( | |
| 91 | - 'webuntis.Session._request', | ||
| 92 | - return_value={} | ||
| 93 | + 'webuntis.Session._request', | ||
| 94 | + return_value={} | ||
| 93 | 95 | ) as mock_obj: | |
| 94 | 96 | self.assertRaises(webuntis.errors.AuthError, s.login) | |
| 95 | 97 | ||
@@ -104,8 +106,8 @@ def test_context_manager(self): | |||
| 104 | 106 | ||
| 105 | 107 | sessionid = 'foobar_session' | |
| 106 | 108 | with mock.patch( | |
| 107 | - 'webuntis.Session._request', | ||
| 108 | - return_value={'sessionId': sessionid} | ||
| 109 | + 'webuntis.Session._request', | ||
| 110 | + return_value={'sessionId': sessionid} | ||
| 109 | 111 | ) as mock_obj: | |
| 110 | 112 | with s.login() as msg: | |
| 111 | 113 | assert mgr is s | |
@@ -115,11 +117,13 @@ def test_custom_cachelen(self): | |||
| 115 | 117 | s = webuntis.Session(cachelen=20, **stub_session_parameters) | |
| 116 | 118 | assert s.cache._maxlen == 20 | |
| 117 | 119 | ||
| 120 | + | ||
| 118 | 121 | class WrapperMethodTests(WebUntisTestCase): | |
| 119 | 122 | @staticmethod | |
| 120 | 123 | def noop_result_mock(methodname): | |
| 121 | 124 | def inner(url, jsondata, headers): | |
| 122 | 125 | return {'result': {}} | |
| 126 | + | ||
| 123 | 127 | return mock_results({methodname: inner}) | |
| 124 | 128 | ||
| 125 | 129 | def test_departments(self): | |
@@ -138,6 +142,7 @@ def test_holidays(self): | |||
| 138 | 142 | ||
| 139 | 143 | def test_klassen(self): | |
| 140 | 144 | s = webuntis.Session(**stub_session_parameters) | |
| 145 | + | ||
| 141 | 146 | def getKlassen(url, jsondata, headers): | |
| 142 | 147 | assert not jsondata['params'] | |
| 143 | 148 | return {'result': {}} | |
@@ -150,6 +155,7 @@ def getKlassen(url, jsondata, headers): | |||
| 150 | 155 | def test_klassen_with_schoolyear(self): | |
| 151 | 156 | s = webuntis.Session(**stub_session_parameters) | |
| 152 | 157 | yearid = 1232 | |
| 158 | + | ||
| 153 | 159 | def getKlassen(url, jsondata, headers): | |
| 154 | 160 | assert jsondata['params']['schoolyearId'] == yearid | |
| 155 | 161 | return {'result': {}} | |
@@ -163,19 +169,20 @@ def test_timetable(self): | |||
| 163 | 169 | s = webuntis.Session(**stub_session_parameters) | |
| 164 | 170 | ||
| 165 | 171 | startbase = 20120303 | |
| 166 | - endbase = 20120304 | ||
| 172 | + endbase = 20120304 | ||
| 167 | 173 | ||
| 168 | 174 | idbase = 12330 | |
| 169 | 175 | for i, name in enumerate(( | |
| 170 | - 'klasse', | ||
| 171 | - 'teacher', | ||
| 172 | - 'subject', | ||
| 173 | - 'room', | ||
| 174 | - 'student' | ||
| 176 | + 'klasse', | ||
| 177 | + 'teacher', | ||
| 178 | + 'subject', | ||
| 179 | + 'room', | ||
| 180 | + 'student' | ||
| 175 | 181 | ), start=1): | |
| 176 | 182 | id = idbase + i | |
| 177 | 183 | start = startbase + i | |
| 178 | 184 | end = endbase + i | |
| 185 | + | ||
| 179 | 186 | def getTimetable(url, jsondata, headers): | |
| 180 | 187 | assert jsondata['params']['type'] == i | |
| 181 | 188 | assert jsondata['params']['id'] == id | |
@@ -192,15 +199,15 @@ def getTimetable(url, jsondata, headers): | |||
| 192 | 199 | def test_timetable_start_later_than_end(self): | |
| 193 | 200 | s = webuntis.Session(**stub_session_parameters) | |
| 194 | 201 | start = 20120308 | |
| 195 | - end = 20120303 | ||
| 202 | + end = 20120303 | ||
| 196 | 203 | ||
| 197 | 204 | self.assertRaisesRegex(ValueError, 'later', s.timetable, | |
| 198 | 205 | start=start, end=end, klasse=123) | |
| 199 | 206 | ||
| 200 | 207 | def test_timetable_invalid_obj_given(self): | |
| 201 | 208 | s = webuntis.Session(**stub_session_parameters) | |
| 202 | 209 | start = 20120303 | |
| 203 | - end = 20120304 | ||
| 210 | + end = 20120304 | ||
| 204 | 211 | ||
| 205 | 212 | self.assertRaisesRegex(TypeError, 'by keyword', s.timetable, | |
| 206 | 213 | start=start, end=end) | |
@@ -255,9 +262,9 @@ def test_substitutions(self): | |||
| 255 | 262 | def getSubstitutions(url, jsondata, headers): | |
| 256 | 263 | return {'result': []} | |
| 257 | 264 | ||
| 258 | - with mock_results({'getSubstitutions': getSubstitutions }): | ||
| 265 | + with mock_results({'getSubstitutions': getSubstitutions}): | ||
| 259 | 266 | start = 20120303 | |
| 260 | - end = 20120304 | ||
| 267 | + end = 20120304 | ||
| 261 | 268 | st = s.substitutions(start=start, end=end) | |
| 262 | 269 | assert type(st) is webuntis.objects.SubstitutionList | |
| 263 | 270 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,19 +7,21 @@ def test_lazyproperty(self): | |||
| 7 | 7 | class FooBar(object): | |
| 8 | 8 | obj = 42 | |
| 9 | 9 | _already_called = False | |
| 10 | + | ||
| 10 | 11 | @webuntis.utils.misc.lazyproperty | |
| 11 | 12 | def yesplease(self): | |
| 12 | 13 | assert not self._already_called | |
| 13 | 14 | self._already_called = True | |
| 14 | 15 | return self.obj | |
| 15 | - | ||
| 16 | + | ||
| 16 | 17 | foobar = FooBar() | |
| 17 | 18 | assert foobar.yesplease == 42 | |
| 18 | 19 | foobar.obj = 43 | |
| 19 | 20 | assert foobar.yesplease == 42 | |
| 20 | 21 | ||
| 21 | 22 | def test_result_wrapper(self): | |
| 22 | 23 | wrapper = webuntis.utils.misc.result_wrapper | |
| 24 | + | ||
| 23 | 25 | class PseudoSession(object): | |
| 24 | 26 | def __init__(self): | |
| 25 | 27 | self.cache = {} | |
@@ -67,6 +69,7 @@ def test_cache_key(self): | |||
| 67 | 69 | assert hash(d) != hash(a) | |
| 68 | 70 | assert hash(d) != hash(c) | |
| 69 | 71 | ||
| 72 | + | ||
| 70 | 73 | class LruDictTests(WebUntisTestCase): | |
| 71 | 74 | def test_basic_interface(self): | |
| 72 | 75 | def test(Dict): | |
@@ -136,7 +139,7 @@ class FilterDictTests(WebUntisTestCase): | |||
| 136 | 139 | def test_basics(self): | |
| 137 | 140 | d = webuntis.utils.misc.FilterDict({ | |
| 138 | 141 | 'foo': lambda x: 'whoopdeedoo', | |
| 139 | - 'bar': lambda x: 1/0, | ||
| 142 | + 'bar': lambda x: 1 / 0, | ||
| 140 | 143 | 'alwaysnone': lambda x: None | |
| 141 | 144 | }) | |
| 142 | 145 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | from webuntis.utils.third_party import json | |
| 4 | 4 | from .. import WebUntisTestCase, BytesIO | |
| 5 | 5 | ||
| 6 | + | ||
| 6 | 7 | class BasicUsage(WebUntisTestCase): | |
| 7 | 8 | def test_parse_result(self): | |
| 8 | 9 | x = webuntis.utils.remote._parse_result | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,11 +2,13 @@ | |||
| 2 | 2 | from webuntis.utils.timetable_utils import table | |
| 3 | 3 | from .. import WebUntisTestCase | |
| 4 | 4 | ||
| 5 | + | ||
| 5 | 6 | class StubPeriod(object): | |
| 6 | 7 | def __init__(self, start, end): | |
| 7 | 8 | self.start = datetime.datetime.strptime(start, '%Y-%m-%d %H:%M') | |
| 8 | 9 | self.end = datetime.datetime.strptime(end, '%Y-%m-%d %H:%M') | |
| 9 | 10 | ||
| 11 | + | ||
| 10 | 12 | class BasicUsage(WebUntisTestCase): | |
| 11 | 13 | def test_empty(self): | |
| 12 | 14 | assert table([]) == [] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments