def test_convert_schedule_oneDictInListLekciaAll(self): input_value = [{ 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': 'Лобацкая Раиса Моисеевна ', 'auditories_verbose': 'И-311', 'day': 1, 'nt': 1, 'title': 'История искусств', 'ngroup': None }] expected = [{ 'group': 'ТХб-18-2', 'schedule': [{ 'day': 'понедельник', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'История искусств', 'aud': 'И-311', 'info': '( Лекция )', 'prep': 'Лобацкая Раиса Моисеевна', }] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_oneDictInListLabaEven(self): input_value = [{ 'obozn': 'ТХб-18-1', 'begtime': '11:45', 'everyweek': 1, 'preps': 'Юрьева Лена Валерьевна ', 'auditories_verbose': 'Е-215б', 'day': 2, 'nt': 3, 'title': 'Минералогия ювелирных камней', 'ngroup': 1 }] expected = [{ 'group': 'ТХб-18-1', 'schedule': [{ 'day': 'вторник', 'lessons': [{ 'time': '11:45', 'week': 'even', 'name': 'Минералогия ювелирных камней', 'aud': 'Е-215б', 'info': '( Лаб. раб. подгруппа 1 )', 'prep': 'Юрьева Лена Валерьевна', }] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_ListWithDictWithOboznAndInfo_returnListWithDictWithGroupAndSchedule( self): input_value = [ { 'obozn': '', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 1, 'nt': 1, 'title': '', 'ngroup': None }, ] example_expected_list = [{'group': '', 'schedule': []}] result = convert_schedule(input_value) # Проверяем, что содержит словарь из двух элементов expected = 2 self.assertEqual(len(result[0]), expected) # Проверяем, что есть ключ group self.assertIsNotNone(result[0].get('group')) # Проверяем, что есть ключ schedule self.assertIsNotNone(result[0].get('schedule'))
def test_convert_schedule_pqScheduleList_returnLessonDictWithTimeWeekNameAudInfoPrep( self): input_value = [ { 'obozn': '', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 1, 'nt': 1, 'title': '', 'ngroup': None }, ] example_expected_list = [{ 'group': '', 'schedule': [{ 'day': '', 'lessons': [{ 'time': '', 'week': '', 'name': '', 'aud': '', 'info': '', 'prep': '', }] }] }] result = convert_schedule(input_value) # Проверяем, что lessons содержит словарь из двух элементов expected = 6 self.assertEqual(len(result[0]['schedule'][0]['lessons'][0]), expected) # Проверяем, что есть ключ time self.assertIsNotNone( result[0]['schedule'][0]['lessons'][0].get('time')) # Проверяем, что есть ключ week self.assertIsNotNone( result[0]['schedule'][0]['lessons'][0].get('week')) # Проверяем, что есть ключ name self.assertIsNotNone( result[0]['schedule'][0]['lessons'][0].get('name')) # Проверяем, что есть ключ aud self.assertIsNotNone(result[0]['schedule'][0]['lessons'][0].get('aud')) # Проверяем, что есть ключ info self.assertIsNotNone( result[0]['schedule'][0]['lessons'][0].get('info')) # Проверяем, что есть ключ prep self.assertIsNotNone( result[0]['schedule'][0]['lessons'][0].get('prep'))
def test_convert_schedule_pqScheduleList_returnDictWithDayAndLessos(self): input_value = [ { 'obozn': '', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 1, 'nt': 1, 'title': '', 'ngroup': None }, ] example_expected_list = [{ 'group': '', 'schedule': [{ 'day': '', 'lessons': [] }] }] result = convert_schedule(input_value) # Проверяем, что schedule содержит словарь из двух элементов expected = 2 self.assertEqual(len(result[0]['schedule'][0]), expected) # Проверяем, что есть ключ day self.assertIsNotNone(result[0]['schedule'][0].get('day')) # Проверяем, что есть ключ lessons self.assertIsNotNone(result[0]['schedule'][0].get('lessons'))
def test_convert_schedule_aFewDictInListOneDay_RightPrepAndAud(self): input_value = [{ 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': 'Пупкин Вася', 'auditories_verbose': 'Ж-313', 'day': 6, 'nt': 1, 'title': 'les_1', 'ngroup': None }] expected = [{ 'group': 'ТХб-18-2', 'schedule': [{ 'day': 'суббота', 'lessons': [ { 'time': '10:00', 'week': 'all', 'name': 'les_1', 'aud': 'Ж-313', 'info': '( Лекция )', 'prep': 'Пупкин Вася', }, ] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_pqScheduleList_returnRightDay(self): input_value = [ { 'obozn': '', 'begtime': '10:00', 'everyweek': 1, 'preps': '', 'auditories_verbose': '', 'day': 2, 'nt': 1, 'title': '', 'ngroup': None }, ] expected = 'вторник' result = convert_schedule(input_value)[0]['schedule'][0]['day'] self.assertEqual(result, expected)
def test_convert_schedule_pqScheduleList_returnIsScheduleList(self): input_value = [ { 'obozn': '', 'begtime': '10:00', 'everyweek': 1, 'preps': '', 'auditories_verbose': '', 'day': 2, 'nt': 1, 'title': '', 'ngroup': None }, ] expected = type([]) result = type(convert_schedule(input_value)[0]['schedule']) self.assertEqual(result, expected)
def test_convert_schedule_pqScheduleList_returnMgListWithRightGroup(self): input_value = [ { 'obozn': 'АРбв-17-1', 'begtime': '10:00', 'everyweek': 1, 'preps': '', 'auditories_verbose': '', 'day': 2, 'nt': 1, 'title': '', 'ngroup': None }, ] expected = 'АРбв-17-1' result = convert_schedule(input_value)[0]['group'] self.assertEqual(result, expected)
def processing_schedule(): """Обработка расписания""" print('Start processing_schedule...') start_time = time.time() try: pg_schedule = postgre_storage.get_schedule() mongo_schedule = data_conversion.convert_schedule(pg_schedule) mongo_storage.save_schedule(mongo_schedule) end_time = time.time() print('Processing_schedule successful.', f'Operation time: {end_time - start_time} seconds.') except PyMongoError as e: print('Mongo error:\n', e) except psycopg2.OperationalError as e: print('Postgre error:\n', e) except Exception as e: print('convert_schedule error:\n', e)
def processing_schedule(): """Обработка расписания""" logger.info('Start processing_schedule...') start_time1 = time.time() pg_schedule = postgre_storage.get_schedule() # Расписание студентов try: mongo_schedule = data_conversion.convert_schedule(pg_schedule) if mongo_schedule: mongo_storage.save_schedule(mongo_schedule) else: mongo_storage.delete_schedule() end_time1 = time.time() logger.info(f'Processing_schedule successful. Operation time: {end_time1 - start_time1} seconds.') except PyMongoError as e: logger.error(f'Mongo error:\n{e}') except psycopg2.OperationalError as e: logger.error(f'Postgre error:\n{e}') except Exception as e: logger.error(f'convert_schedule error:\n{e}') # Расписание преподавателей logger.info('Start processing_teachers_schedule...') start_time2 = time.time() try: mongo_teachers_schedule = data_conversion.convert_teachers_schedule(pg_schedule) if mongo_teachers_schedule: mongo_storage.save_teachers_schedule(mongo_teachers_schedule) else: mongo_storage.delete_teachers_schedule() end_time2 = time.time() logger.info(f'Processing_teachers_schedule successful. Operation time: {end_time2 - start_time2} seconds.') except PyMongoError as e: logger.error(f'Mongo error:\n{e}') except psycopg2.OperationalError as e: logger.error(f'Postgre error:\n{e}') except Exception as e: logger.error(f'convert_teachers_schedule error:\n{e}') # Расписание аудиторий logger.info('Start processing_auditories_schedule...') start_time3 = time.time() try: mongo_auditories_schedule = data_conversion.convert_auditories_schedule(pg_schedule) if mongo_auditories_schedule: mongo_storage.save_auditories_schedule(mongo_auditories_schedule) else: mongo_storage.delete_auditories_schedule() end_time3 = time.time() logger.info(f'Processing_auditories_schedule successful. Operation time: {end_time3 - start_time3} seconds.') except PyMongoError as e: logger.error(f'Mongo error:\n{e}') except psycopg2.OperationalError as e: logger.error(f'Postgre error:\n{e}') except Exception as e: logger.error(f'convert_auditories_schedule error:\n{e}')
def test_convert_schedule_aFewDictInListOneDay_RightInfo(self): input_value = [ { 'obozn': 'ТХб-18-2', 'begtime': '10:01', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_1', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:03', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 2, 'title': 'les_3', 'ngroup': 2 }, { 'obozn': 'ТХб-18-2', 'begtime': '10:02', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 2, 'title': 'les_2', 'ngroup': 1 }, { 'obozn': 'ТХб-18-2', 'begtime': '10:04', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 2, 'title': 'les_4', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:05', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 3, 'title': 'les_5', 'ngroup': 1 }, { 'obozn': 'ТХб-18-2', 'begtime': '10:06', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 3, 'title': 'les_6', 'ngroup': 2 }, { 'obozn': 'ТХб-18-2', 'begtime': '10:07', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 3, 'title': 'les_7', 'ngroup': None }, ] expected = [{ 'group': 'ТХб-18-2', 'schedule': [{ 'day': 'среда', 'lessons': [{ 'time': '10:01', 'week': 'all', 'name': 'les_1', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '10:02', 'week': 'all', 'name': 'les_2', 'aud': '', 'info': '( Практ. подгруппа 1 )', 'prep': '', }, { 'time': '10:03', 'week': 'all', 'name': 'les_3', 'aud': '', 'info': '( Практ. подгруппа 2 )', 'prep': '', }, { 'time': '10:04', 'week': 'all', 'name': 'les_4', 'aud': '', 'info': '( Практ. )', 'prep': '', }, { 'time': '10:05', 'week': 'all', 'name': 'les_5', 'aud': '', 'info': '( Лаб. раб. подгруппа 1 )', 'prep': '', }, { 'time': '10:06', 'week': 'all', 'name': 'les_6', 'aud': '', 'info': '( Лаб. раб. подгруппа 2 )', 'prep': '', }, { 'time': '10:07', 'week': 'all', 'name': 'les_7', 'aud': '', 'info': '( Лаб. раб. )', 'prep': '', }] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_aFewDictInListOneDay_LessonsInRightOrder(self): input_value = [ { 'obozn': 'ТХб-18-2', 'begtime': '18:45', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_4', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_2', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '11:45', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_3', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '8:15', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_1', 'ngroup': None }, ] expected = [{ 'group': 'ТХб-18-2', 'schedule': [{ 'day': 'среда', 'lessons': [{ 'time': '8:15', 'week': 'all', 'name': 'les_1', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '10:00', 'week': 'all', 'name': 'les_2', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '11:45', 'week': 'all', 'name': 'les_3', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '18:45', 'week': 'all', 'name': 'les_4', 'aud': '', 'info': '( Лекция )', 'prep': '', }] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_aFewDictInListOneGroup_DaysInRightOrder(self): input_value = [{ 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_4', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 1, 'nt': 1, 'title': 'les_1', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 1, 'preps': '', 'auditories_verbose': '', 'day': 10, 'nt': 1, 'title': 'les_5', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 1, 'nt': 1, 'title': 'les_2', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 4, 'nt': 1, 'title': 'les_6', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 6, 'nt': 1, 'title': 'les_8', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 5, 'nt': 1, 'title': 'les_7', 'ngroup': None }, { 'obozn': 'ТХб-18-2', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 2, 'nt': 1, 'title': 'les_3', 'ngroup': None }] expected = [{ 'group': 'ТХб-18-2', 'schedule': [{ 'day': 'понедельник', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_1', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '10:00', 'week': 'all', 'name': 'les_2', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }, { 'day': 'вторник', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_3', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }, { 'day': 'среда', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_4', 'aud': '', 'info': '( Лекция )', 'prep': '', }, { 'time': '10:00', 'week': 'odd', 'name': 'les_5', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }, { 'day': 'четверг', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_6', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }, { 'day': 'пятница', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_7', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }, { 'day': 'суббота', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_8', 'aud': '', 'info': '( Лекция )', 'prep': '', }], }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)
def test_convert_schedule_aFewDictInListOneDay_returnDuplicateLessonsRemoved( self): input_value = [ { 'obozn': 'ИБб-18-1', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 2, 'title': 'les_1', 'ngroup': 1 }, { 'obozn': 'ИБб-18-1', 'begtime': '11:45', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 1, 'title': 'les_2', 'ngroup': None }, { 'obozn': 'ИБб-18-1', 'begtime': '10:00', 'everyweek': 2, 'preps': '', 'auditories_verbose': '', 'day': 3, 'nt': 2, 'title': 'les_1', 'ngroup': 1 }, ] expected = [{ 'group': 'ИБб-18-1', 'schedule': [{ 'day': 'среда', 'lessons': [{ 'time': '10:00', 'week': 'all', 'name': 'les_1', 'aud': '', 'info': '( Практ. подгруппа 1 )', 'prep': '', }, { 'time': '11:45', 'week': 'all', 'name': 'les_2', 'aud': '', 'info': '( Лекция )', 'prep': '', }] }] }] result = convert_schedule(input_value) self.assertEqual(result, expected)