def add_video_to_course(course, player_mode, display_name='Video'): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': display_name } if player_mode == 'html5': kwargs.update({ 'metadata': { 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES } }) if player_mode == 'youtube_html5': kwargs.update({'metadata': {'html5_sources': HTML5_SOURCES}}) if player_mode == 'youtube_html5_unsupported_video': kwargs.update({'metadata': {'html5_sources': HTML5_SOURCES_INCORRECT}}) if player_mode == 'html5_unsupported_video': kwargs.update({ 'metadata': { 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT } }) world.ItemFactory.create(**kwargs)
def add_problem_to_course(course, problem_type, extra_meta=None): ''' Add a problem to the course we have created using factories. ''' assert(problem_type in PROBLEM_DICT) # Generate the problem XML using capa.tests.response_xml_factory factory_dict = PROBLEM_DICT[problem_type] problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs']) metadata = {'rerandomize': 'always'} if not 'metadata' in factory_dict else factory_dict['metadata'] if extra_meta: metadata = dict(metadata, **extra_meta) # Create a problem item using our generated XML # We set rerandomize=always in the metadata so that the "Reset" button # will appear. category_name = "problem" return world.ItemFactory.create( parent_location=section_location(course), category=category_name, display_name=str(problem_type), data=problem_xml, metadata=metadata )
def inputfield(course, problem_type, choice=None, input_num=1): """ Return the css selector for `problem_type`. For example, if problem_type is 'string', return the text field for the string problem in the test course. `choice` is the name of the checkbox input in a group of checkboxes. """ section_loc = section_location(course) ptype = problem_type.replace(" ", "_") # this is necessary due to naming requirement for this problem type if problem_type in ("radio_text", "checkbox_text"): selector_template = "input#{}_2_{input}" else: selector_template = "input#input_{}_2_{input}" sel = selector_template.format( section_loc.course_key.make_usage_key('problem', ptype).html_id(), input=input_num, ) if choice is not None: base = "_choice_" if problem_type == "multiple choice" else "_" sel = sel + base + str(choice) # If the input element doesn't exist, fail immediately assert world.is_css_present(sel) # Retrieve the input element return sel
def add_video_to_course(course, player_mode): category = "video" kwargs = {"parent_location": section_location(course), "category": category, "display_name": "Video"} if player_mode == "html5": kwargs.update( { "metadata": { "youtube_id_1_0": "", "youtube_id_0_75": "", "youtube_id_1_25": "", "youtube_id_1_5": "", "html5_sources": HTML5_SOURCES, } } ) if player_mode == "youtube_html5": kwargs.update({"metadata": {"html5_sources": HTML5_SOURCES}}) if player_mode == "youtube_html5_unsupported_video": kwargs.update({"metadata": {"html5_sources": HTML5_SOURCES_INCORRECT}}) if player_mode == "html5_unsupported_video": kwargs.update( { "metadata": { "youtube_id_1_0": "", "youtube_id_0_75": "", "youtube_id_1_25": "", "youtube_id_1_5": "", "html5_sources": HTML5_SOURCES_INCORRECT, } } ) world.ItemFactory.create(**kwargs)
def add_problem_to_course(course, problem_type, extraMeta=None): ''' Add a problem to the course we have created using factories. ''' assert (problem_type in PROBLEM_DICT) # Generate the problem XML using capa.tests.response_xml_factory factory_dict = PROBLEM_DICT[problem_type] problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs']) metadata = { 'rerandomize': 'always' } if not 'metadata' in factory_dict else factory_dict['metadata'] if extraMeta: metadata = dict(metadata, **extraMeta) # Create a problem item using our generated XML # We set rerandomize=always in the metadata so that the "Reset" button # will appear. category_name = "problem" return world.ItemFactory.create(parent_location=section_location(course), category=category_name, display_name=str(problem_type), data=problem_xml, metadata=metadata)
def add_video_to_course(course, player_mode, hashes, display_name='Video'): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': display_name, 'metadata': {}, } if player_mode == 'html5': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5_unsupported_video': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES_INCORRECT }) if player_mode == 'html5_unsupported_video': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT }) if hashes: kwargs['metadata'].update(hashes[0]) course_location =world.scenario_dict['COURSE'].location conversions = { 'transcripts': json.loads, 'download_track': json.loads, 'download_video': json.loads, } for key in kwargs['metadata']: if key in conversions: kwargs['metadata'][key] = conversions[key](kwargs['metadata'][key]) if 'sub' in kwargs['metadata']: filename = _get_sjson_filename(kwargs['metadata']['sub'], 'en') _upload_file(filename, course_location) if 'transcripts' in kwargs['metadata']: for lang, filename in kwargs['metadata']['transcripts'].items(): _upload_file(filename, course_location) world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
def add_video_to_course(course, player_mode, hashes, display_name='Video'): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': display_name, 'metadata': {}, } if hashes: kwargs['metadata'].update(hashes[0]) conversions = { 'transcripts': json.loads, 'download_track': json.loads, 'download_video': json.loads, } for key in kwargs['metadata']: if key in conversions: kwargs['metadata'][key] = conversions[key](kwargs['metadata'][key]) if player_mode == 'html5': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES, }) if player_mode == 'youtube_html5_unsupported_video': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES_INCORRECT }) if player_mode == 'html5_unsupported_video': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT }) world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs) world.wait_for_present('.is-initialized') world.wait_for_invisible('.video-wrapper .spinner')
def add_video_to_course(course, player_mode, hashes, display_name='Video'): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': display_name, 'metadata': {}, } if player_mode == 'html5': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5_unsupported_video': kwargs['metadata'].update({ 'html5_sources': HTML5_SOURCES_INCORRECT }) if player_mode == 'html5_unsupported_video': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT }) if hashes: kwargs['metadata'].update(hashes[0]) if 'transcripts' in kwargs['metadata']: kwargs['metadata']['transcripts'] = json.loads(kwargs['metadata']['transcripts']) if 'sub' in kwargs['metadata']: _upload_file(kwargs['metadata']['sub'], 'en', world.scenario_dict['COURSE'].location) for lang, videoId in kwargs['metadata']['transcripts'].items(): _upload_file(videoId, lang, world.scenario_dict['COURSE'].location) world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
def add_video_to_course(course, player_mode, hashes, display_name='Video'): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': display_name, 'metadata': {}, } if player_mode == 'html5': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES }) if player_mode == 'youtube_html5': kwargs['metadata'].update({'html5_sources': HTML5_SOURCES}) if player_mode == 'youtube_html5_unsupported_video': kwargs['metadata'].update({'html5_sources': HTML5_SOURCES_INCORRECT}) if player_mode == 'html5_unsupported_video': kwargs['metadata'].update({ 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT }) if hashes: kwargs['metadata'].update(hashes[0]) if 'transcripts' in kwargs['metadata']: kwargs['metadata']['transcripts'] = json.loads( kwargs['metadata']['transcripts']) if 'sub' in kwargs['metadata']: _upload_file(kwargs['metadata']['sub'], 'en', world.scenario_dict['COURSE'].location) for lang, videoId in kwargs['metadata']['transcripts'].items(): _upload_file(videoId, lang, world.scenario_dict['COURSE'].location) world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
def add_video_to_course(course, player_mode): category = 'video' kwargs = { 'parent_location': section_location(course), 'category': category, 'display_name': 'Video' } if player_mode == 'html5': kwargs.update({ 'metadata': { 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES } }) if player_mode == 'youtube_html5': kwargs.update({ 'metadata': { 'html5_sources': HTML5_SOURCES } }) if player_mode == 'youtube_html5_unsupported_video': kwargs.update({ 'metadata': { 'html5_sources': HTML5_SOURCES_INCORRECT } }) if player_mode == 'html5_unsupported_video': kwargs.update({ 'metadata': { 'youtube_id_1_0': '', 'youtube_id_0_75': '', 'youtube_id_1_25': '', 'youtube_id_1_5': '', 'html5_sources': HTML5_SOURCES_INCORRECT } }) world.ItemFactory.create(**kwargs)
def add_problem_to_course(course, problem_type): ''' Add a problem to the course we have created using factories. ''' assert (problem_type in PROBLEM_FACTORY_DICT) # Generate the problem XML using capa.tests.response_xml_factory factory_dict = PROBLEM_FACTORY_DICT[problem_type] problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs']) # Create a problem item using our generated XML # We set rerandomize=always in the metadata so that the "Reset" button # will appear. template_name = "i4x://edx/templates/problem/Blank_Common_Problem" world.ItemFactory.create(parent_location=section_location(course), template=template_name, display_name=str(problem_type), data=problem_xml, metadata={'rerandomize': 'always'})
def add_problem_to_course(course, problem_type): ''' Add a problem to the course we have created using factories. ''' assert(problem_type in PROBLEM_FACTORY_DICT) # Generate the problem XML using capa.tests.response_xml_factory factory_dict = PROBLEM_FACTORY_DICT[problem_type] problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs']) # Create a problem item using our generated XML # We set rerandomize=always in the metadata so that the "Reset" button # will appear. template_name = "i4x://edx/templates/problem/Blank_Common_Problem" world.ItemFactory.create(parent_location=section_location(course), template=template_name, display_name=str(problem_type), data=problem_xml, metadata={'rerandomize': 'always'})
def add_video_to_course(course): world.ItemFactory.create(parent_location=section_location(course), category='video', display_name='Video')
def answer_problem(course, problem_type, correctness): # Make sure that the problem has been completely rendered before # starting to input an answer. world.wait_for_ajax_complete() section_loc = section_location(course) if problem_type == "drop down": select_name = "input_{}_2_1".format( section_loc.course_key.make_usage_key('problem', 'drop_down').html_id() ) option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check(inputfield(course, 'multiple choice', choice='choice_2')) else: world.css_check(inputfield(course, 'multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield(course, 'checkbox', choice='choice_0')) world.css_check(inputfield(course, 'checkbox', choice='choice_2')) else: world.css_check(inputfield(course, 'checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield(course, 'radio', choice='choice_2')) else: world.css_check(inputfield(course, 'radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield(course, 'string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str(random.randint(-2, 2)) world.css_fill(inputfield(course, 'numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield(course, 'formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield(course, 'script', input_num=1), str(first_addend)) world.css_fill(inputfield(course, 'script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass elif problem_type == 'radio_text' or problem_type == 'checkbox_text': input_value = "8" if correctness == 'correct' else "5" choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc" world.css_fill( inputfield( course, problem_type, choice="choiceinput_0_numtolerance_input_0" ), input_value ) world.css_check(inputfield(course, problem_type, choice=choice)) elif problem_type == 'image': offset = 25 if correctness == "correct" else -25 def try_click(): problem_html_loc = section_loc.course_key.make_usage_key('problem', 'image').html_id() image_selector = "#imageinput_{}_2_1".format(problem_html_loc) input_selector = "#input_{}_2_1".format(problem_html_loc) world.browser.execute_script('$("body").on("click", function(event) {console.log(event);})') initial_input = world.css_value(input_selector) world.wait_for_visible(image_selector) image = world.css_find(image_selector).first (image.action_chains .move_to_element(image._element) .move_by_offset(offset, offset) .click() .perform()) world.wait_for(lambda _: world.css_value(input_selector) != initial_input) world.retry_on_exception(try_click)
def add_videoalpha_to_course(course): category = 'videoalpha' world.ItemFactory.create(parent_location=section_location(course), category=category, display_name='Video Alpha')
def add_videoalpha_to_course(course): template_name = 'i4x://edx/templates/videoalpha/Video_Alpha' world.ItemFactory.create(parent_location=section_location(course), template=template_name, display_name='Video Alpha')
def add_video_to_course(course): template_name = 'i4x://edx/templates/video/default' world.ItemFactory.create(parent_location=section_location(course), template=template_name, display_name='Video')
def add_word_cloud_to_course(course): category = 'word_cloud' world.ItemFactory.create(parent_location=section_location(course), category=category, display_name='Word Cloud')
def answer_problem(course, problem_type, correctness): # Make sure that the problem has been completely rendered before # starting to input an answer. world.wait_for_ajax_complete() section_loc = section_location(course) if problem_type == "drop down": select_name = "input_{}_2_1".format( section_loc.course_key.make_usage_key('problem', 'drop_down').html_id()) option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check( inputfield(course, 'multiple choice', choice='choice_2')) else: world.css_check( inputfield(course, 'multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield(course, 'checkbox', choice='choice_0')) world.css_check(inputfield(course, 'checkbox', choice='choice_2')) else: world.css_check(inputfield(course, 'checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield(course, 'radio', choice='choice_2')) else: world.css_check(inputfield(course, 'radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield(course, 'string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str( random.randint(-2, 2)) world.css_fill(inputfield(course, 'numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield(course, 'formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield(course, 'script', input_num=1), str(first_addend)) world.css_fill(inputfield(course, 'script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass elif problem_type == 'radio_text' or problem_type == 'checkbox_text': input_value = "8" if correctness == 'correct' else "5" choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc" world.css_fill( inputfield(course, problem_type, choice="choiceinput_0_numtolerance_input_0"), input_value) world.css_check(inputfield(course, problem_type, choice=choice)) elif problem_type == 'image': offset = 25 if correctness == "correct" else -25 def try_click(): problem_html_loc = section_loc.course_key.make_usage_key( 'problem', 'image').html_id() image_selector = "#imageinput_{}_2_1".format(problem_html_loc) input_selector = "#input_{}_2_1".format(problem_html_loc) world.browser.execute_script( '$("body").on("click", function(event) {console.log(event);})') initial_input = world.css_value(input_selector) world.wait_for_visible(image_selector) image = world.css_find(image_selector).first (image.action_chains.move_to_element( image._element).move_by_offset(offset, offset).click().perform()) world.wait_for( lambda _: world.css_value(input_selector) != initial_input) world.retry_on_exception(try_click)
def add_video_to_course(course): template_name = "i4x://edx/templates/video/default" world.ItemFactory.create(parent_location=section_location(course), template=template_name, display_name="Video")