def step_impl( context, date, time, new_date, new_time, new_course, new_duration, new_canceled, client, new_attendancestate, new_paid, new_note, ): new_attendances = [ attendance_dict(context.api_client, client, new_attendancestate, new_paid, new_note) ] # nacteni dat lekce do kontextu load_data_to_context(context, new_course, new_date, new_time, new_duration, new_canceled, new_attendances) # najdi lekci lecture_to_update = helpers.find_lecture_with_start( context.api_client, common_helpers.prepare_start(date, time)) assert lecture_to_update # uloz puvodni pocet lekci save_old_lectures_cnt_to_context(context) # vlozeni lekce context.resp = context.api_client.put( f"{helpers.API_LECTURES}{lecture_to_update['id']}/", lecture_dict(context, lecture_to_update), )
def step_impl(context, client, date, time, new_paid): # nacteni dat lekce do kontextu load_id_data_to_context(context, date, time) # najdi lekci lecture_to_update = helpers.find_lecture_with_start( context.api_client, common_helpers.prepare_start(date, time)) assert lecture_to_update # najdi id attendance attendance_id = lecture_to_update["attendances"][0]["id"] # vlozeni lekce content = attendance_dict_patch(attendance_id, paid=new_paid) context.resp = context.api_client.patch( f"{helpers.API_ATTENDANCES}{attendance_id}/", content) # uloz ocekavany novy stav do kontextu context.new_paid = common_helpers.to_bool(new_paid)
def step_impl(context, client, date, time, new_attendancestate): new_attendancestate = helpers.find_attendancestate_with_name( context.api_client, new_attendancestate) # nacteni dat lekce do kontextu load_id_data_to_context(context, date, time) # najdi lekci lecture_to_update = helpers.find_lecture_with_start( context.api_client, common_helpers.prepare_start(date, time)) assert lecture_to_update # najdi id attendance attendance_id = lecture_to_update["attendances"][0]["id"] attendancestate_id = lecture_to_update["attendances"][0]["attendancestate"] # uloz puvodni pocet lekci save_old_lectures_cnt_to_context(context) # vlozeni lekce content = attendance_dict_patch(attendance_id, attendancestate=new_attendancestate["id"]) context.resp = context.api_client.patch( f"{helpers.API_ATTENDANCES}{attendance_id}/", content) # uloz ocekavany novy a aktualni stav do kontextu context.new_attendancestate = new_attendancestate context.cur_attendancestate = helpers.find_attendancestate_with_id( context.api_client, attendancestate_id)
def find_lecture(context, date, time, validate_context=False): all_courses = context.browser.find_elements_by_css_selector( "[data-qa=card_course]") # hledej mezi vsemi kurzy for course in all_courses: found_course = course.find_element_by_css_selector( "[data-qa=card_course_name]").text all_course_lectures = course.find_elements_by_css_selector( "[data-qa=lecture]") # najdi lekci s danym zacatkem for lecture in all_course_lectures: found_start = lecture.find_element_by_css_selector( "[data-qa=lecture_start]").text found_duration = helpers.get_tooltip( context.browser, lecture.find_element_by_css_selector( "[data-qa=lecture_start]")).text found_canceled = helpers.check_class_included( lecture.get_attribute("class"), "lecture-canceled") # srovnej identifikatory start = common_helpers.prepare_start(date, time) start = f"{start.day}. {start.month}. {start.year} – {start.hour}:{start.minute:02}" # je to substring (v UI je pred datumem i nazev dne)? if start in found_start: # prohledej a zvaliduj attendances (jen kdyz jsou k dispozici) found_attendances_cnt = 0 found_old_attendances = [] if "attendances" in context: for attendance in context.attendances: # najdi attendance prislusici danemu klientovi found_attendance = find_attendance_in_card( context, lecture, attendance["client"]) found_note = found_attendance.find_element_by_css_selector( "[data-qa=lecture_attendance_note]").text found_old_attendances.append( attendance_dict( attendance["client"], get_attendancestate_state(found_attendance), get_paid_state(found_attendance), found_note, )) if (found_note == attendance["note"] and verify_paid( found_attendance, attendance["paid"]) and verify_attendancestate( found_attendance, attendance["attendancestate"])): found_attendances_cnt += 1 # identifikatory sedi, otestuj pripadna dalsi data z kontextu (pokud nesedi, hledej dal) # nebo rovnou vrat nalezeny prvek if validate_context and ( found_attendances_cnt != len(context.attendances) or duration_title(context.duration) != found_duration): continue if ( # poznamka: uz vime, ze se attendances i duration sedi (jinak predchozi podminka zaridi continue) not validate_context or validate_context and ( # jeste over spravnou hodnotu canceled context.canceled == found_canceled # pro single lekce srovnej kurz, pro skupiny ho neres and (not context.is_group and found_course == context.course) or context.is_group)): # uloz stara data do kontextu pro pripadne overeni spravnosti context.old_attendances = found_old_attendances context.old_course = found_course context.old_date = date context.old_time = time context.old_duration = found_duration context.old_canceled = found_canceled return lecture return False
def load_id_data_to_context(context, date, time): context.start = common_helpers.prepare_start(date, time)