def test_all_modules_ids_not_signed_in(): source = AdUnisHSR() with pytest.raises(AuthenticationException) as exceptionInfo: source.all_modules_ids() assert str(exceptionInfo.value) == "You must log in before you can query!"
def test_signin_invalid_credentials(): source = AdUnisHSR() with pytest.raises(AuthenticationException) as exceptionInfo: source.signin('user', 'password') assert str(exceptionInfo.value)[:27] == "Authentication has failed ("
def test_all_modules_ids_signed_in_happy_path(): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) modules = source.all_modules_ids() assert len(modules) > 20 assert modules['InfSys'] == '51677'
def test_lectures_times_happy_path(): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) if 'CN1' in source.all_modules_ids(): # Herbstsemester lectures_times = source.lectures_times(['CN1']) raise Exception("NOT TESTET YET! PLEASE IMPLEMENT ME!") else: # Fruehlungssemester lectures_times = source.lectures_times(['CN2'])['CN2'] # Uebungen uebungen = [lectures_times for lt in lectures_times if lt['type'] == 'u'] assert len(uebungen) >= 2 and len(uebungen) < len(lectures_times) # Praktikas praktikas = [lectures_times for lt in lectures_times if lt['type'] == 'u'] assert len(praktikas) >= 4 and len(uebungen) < len(lectures_times) # Vorlesungen vorlesungen = [lectures_times for lt in lectures_times if lt['type'] == 'v'] assert len(vorlesungen) >= 2 and len(uebungen) < len(lectures_times) # TODO: Test with other modules begin_first_lesson = time(7, 5) begin_last_lesson = time(20, 5) for lesson in lectures_times: assert re.match('^CN(1|2)(Prak)?-(u|v|p)[0-9][0-9]?$', lesson['name']) is not None assert re.match('^CN(1|2)(Prak)?$', lesson['abbrev']) is not None assert begin_first_lesson <= lesson['start_time'] <= begin_last_lesson assert re.match('^[A-Z]{3}( [A-Z]{3})*$', lesson['teacher']) is not None assert lesson['day'] in ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] assert lesson['class'] is not None assert lesson['team'] is None or re.match('^[0-9]$', lesson['class']) assert re.match('^[1-9]\.[0-9]*[a-z]?$', lesson['room']) is not None assert lesson['weeks'] is None or re.match('^([0-9]{1,2}(\,[0-9]{1,2})*)$', lesson['weeks']) is not None
with vcr.use_cassette('fixtures/demo', record_mode='new_episodes'): module_spec = {'MsTe': {'v': 2, 'u': 2}, 'AD2': {'v': 2, 'u': 2}, 'BuRe1': [ {'abbrev': 'ReIng', 'v': 2}, {'abbrev': 'BuPl', 'v': 1, 'u': 1}, ], 'CPl': {'v': 2, 'u': 2}, 'MGE': {'v': 2, 'u': 2}, 'SE1': {'v': 2, 'u': 2}, 'WED2': {'v': 2, 'u': 2}, 'PrFm': {'v': 2, 'u': 2} } source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) filters = [ restrictions.InTimeRange(time(7, 0), time(18, 00)), restrictions.MinChance(30), restrictions.FreeTime(3, range(5), time(12), time(23)), # restrictions.FreeTime(1, range(5), time(6), time(23)) ] planner = Planner(module_spec.keys(), source) solutions = planner.solve(filters) for solution in solutions: planner.verify(module_spec, solution)
}, 'SE1': { 'v': 2, 'u': 2 }, 'WED2': { 'v': 2, 'u': 2 }, 'PrFm': { 'v': 2, 'u': 2 } } source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) filters = [ restrictions.InTimeRange(time(7, 0), time(18, 00)), restrictions.MinChance(30), restrictions.FreeTime(3, range(5), time(12), time(23)), # restrictions.FreeTime(1, range(5), time(6), time(23)) ] planner = Planner(module_spec.keys(), source) solutions = planner.solve(filters) for solution in solutions: planner.verify(module_spec, solution)
from planner import AdUnisHSR from planner import utils import vcr with vcr.use_cassette('fixtures/demo_friends', record_mode='new_episodes'): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) friends = [ ('5012019', 'Jonas'), ('540793', 'Robin'), ('5011745', 'Nikola'), ('5011941', 'Fabian'), ('5011287', 'Marcel') # [...] ] my_id = '5011205' my_timetable = sorted(list(set((l['name'] for l in source.lessons_for_student(AdUnisHSR.NEXT_SEMESTER, my_id))))) friends_timetables = {} for friend_id, name in friends: friends_timetables[name] = set((l['name'] for l in source.lessons_for_student(AdUnisHSR.NEXT_SEMESTER, friend_id))) for module in my_timetable: print(module + ':') for name, friend_timetable in friends_timetables.items(): if module in friend_timetable: print(' ' + name)
def test_signin_valid_credentials(): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') source.signin(username, password)
def test_signin_valid_credentials(): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) assert len(response.text) > 100
from planner import AdUnisHSR from planner import utils from datetime import datetime from isoweek import Week import vcr with vcr.use_cassette('fixtures/demo_exort', record_mode='new_episodes'): source = AdUnisHSR() username, password = utils.parse_user_credentials('auth.cfg') response = source.signin(username, password) my_id = '5011205' my_timetable = source.lessons_for_student(AdUnisHSR.NEXT_SEMESTER, my_id) semester_start = datetime(2016, 9, 19) semester_end = datetime(2016, 12, 23) utils.export_to_ical('modules.ics', my_timetable, start=semester_start, end=semester_end) # Equivalent to: # utils.export_to_ical('modules.ics', my_timetable, year=2016, weeks=range(38, 52))