def create_component_instance(step, category, component_type=None, is_advanced=False):
    """
    Create a new component in a Unit.

    Parameters
    ----------
    category: component type (discussion, html, problem, video)
    component_type: for components with multiple templates, the link text in the menu
    is_advanced: for html and problem, is the desired component under the
                 advanced menu
    """
    assert_in(category, ['problem', 'html', 'video', 'discussion'])

    component_button_css = '.large-{}-icon'.format(category.lower())
    world.css_click(component_button_css)

    if category in ('problem', 'html'):
        world.wait_for_invisible(component_button_css)
        click_component_from_menu(category, component_type, is_advanced)

    if category == 'problem':
        expected_css = 'section.xmodule_CapaModule'
    else:
        expected_css = 'section.xmodule_{}Module'.format(category.title())

    assert_true(world.is_css_present(expected_css))
def create_component_instance(step, category, component_type=None, is_advanced=False):
    """
    Create a new component in a Unit.

    Parameters
    ----------
    category: component type (discussion, html, problem, video)
    component_type: for components with multiple templates, the link text in the menu
    is_advanced: for problems, is the desired component under the advanced menu?
    """
    assert_in(category, ["problem", "html", "video", "discussion"])

    component_button_css = "span.large-{}-icon".format(category.lower())
    if category == "problem":
        module_css = "section.xmodule_CapaModule"
    else:
        module_css = "section.xmodule_{}Module".format(category.title())

    # Count how many of that module is on the page. Later we will
    # assert that one more was added.
    # We need to use world.browser.find_by_css instead of world.css_find
    # because it's ok if there are currently zero of them.
    module_count_before = len(world.browser.find_by_css(module_css))

    # Disable the jquery animation for the transition to the menus.
    world.disable_jquery_animations()
    world.css_click(component_button_css)

    if category in ("problem", "html"):
        world.wait_for_invisible(component_button_css)
        click_component_from_menu(category, component_type, is_advanced)

    expected_count = module_count_before + 1
    world.wait_for(lambda _: len(world.css_find(module_css)) == expected_count, timeout=20)
Beispiel #3
0
def create_component_instance(step, category, component_type=None, is_advanced=False):
    """
    Create a new component in a Unit.

    Parameters
    ----------
    category: component type (discussion, html, problem, video)
    component_type: for components with multiple templates, the link text in the menu
    is_advanced: for problems, is the desired component under the advanced menu?
    """
    assert_in(category, ['problem', 'html', 'video', 'discussion'])

    component_button_css = 'span.large-{}-icon'.format(category.lower())
    if category == 'problem':
        module_css = 'section.xmodule_CapaModule'
    else:
        module_css = 'section.xmodule_{}Module'.format(category.title())

    # Count how many of that module is on the page. Later we will
    # assert that one more was added.
    # We need to use world.browser.find_by_css instead of world.css_find
    # because it's ok if there are currently zero of them.
    module_count_before =  len(world.browser.find_by_css(module_css))

    # Disable the jquery animation for the transition to the menus.
    world.disable_jquery_animations()
    world.css_click(component_button_css)

    if category in ('problem', 'html'):
        world.wait_for_invisible(component_button_css)
        click_component_from_menu(category, component_type, is_advanced)

    world.wait_for(lambda _: _is_expected_element_count(module_css,
        module_count_before + 1))
def create_component_instance(step, category, component_type=None, is_advanced=False):
    """
    Create a new component in a Unit.

    Parameters
    ----------
    category: component type (discussion, html, problem, video)
    component_type: for components with multiple templates, the link text in the menu
    is_advanced: for html and problem, is the desired component under the
                 advanced menu
    """
    assert_in(category, ['problem', 'html', 'video', 'discussion'])

    component_button_css = 'span.large-{}-icon'.format(category.lower())
    if category == 'problem':
        module_css = 'section.xmodule_CapaModule'
    else:
        module_css = 'section.xmodule_{}Module'.format(category.title())

    # Count how many of that module is on the page. Later we will
    # assert that one more was added.
    # We need to use world.browser.find_by_css instead of world.css_find
    # because it's ok if there are currently zero of them.
    module_count_before =  len(world.browser.find_by_css(module_css))

    world.css_click(component_button_css)

    if category in ('problem', 'html'):
        world.wait_for_invisible(component_button_css)
        click_component_from_menu(category, component_type, is_advanced)

    world.wait_for(lambda _: _is_expected_element_count(module_css,
        module_count_before + 1))
Beispiel #5
0
def is_hidden_button(_step, button, state):
    selector = VIDEO_BUTTONS[button]
    if state == "hidden":
        world.wait_for_invisible(selector)
        assert_false(world.css_visible(selector), "Button {0} is invisible, but should be visible".format(button))
    else:
        world.wait_for_visible(selector)
        assert_true(world.css_visible(selector), "Button {0} is visible, but should be invisible".format(button))
Beispiel #6
0
def add_video_to_course(course, parent_location=None, player_mode=None, data=None, display_name='Video'):
    if not parent_location:
        parent_location = add_vertical_to_course(course)
    kwargs = get_metadata(parent_location, player_mode, data, display_name=display_name)
    world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
    world.wait_for_present('.is-initialized')
    world.wait_for_invisible('.video-wrapper .spinner')
    world.wait_for_ajax_complete()
Beispiel #7
0
def i_created_a_video_component(step):
    world.create_course_with_unit()
    world.create_component_instance(step=step, category="video")

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present(".is-initialized")
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS["spinner"])
Beispiel #8
0
def add_video_to_course(course, parent_location=None, player_mode=None, data=None, display_name='Video'):

    assert_less(world.youtube.config['youtube_api_response'].status_code, 400, "Real Youtube server is unavailable")

    if not parent_location:
        parent_location = add_vertical_to_course(course)
    kwargs = get_metadata(parent_location, player_mode, data, display_name=display_name)
    world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
    world.wait_for_present('.is-initialized')
    world.wait_for_invisible('.video-wrapper .spinner')
    world.wait_for_ajax_complete()
Beispiel #9
0
def is_hidden_button(_step, button, state):
    selector = VIDEO_BUTTONS[button]
    if state == 'hidden':
        world.wait_for_invisible(selector)
        assert_false(
            world.css_visible(selector),
            'Button {0} is invisible, but should be visible'.format(button))
    else:
        world.wait_for_visible(selector)
        assert_true(
            world.css_visible(selector),
            'Button {0} is visible, but should be invisible'.format(button))
Beispiel #10
0
def i_created_a_video_component(step):
    step.given("I am in Studio editing a new unit")
    world.create_component_instance(step=step, category="video")

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present(".is-initialized")
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS["spinner"])
    if not world.youtube.config.get("youtube_api_blocked"):
        world.wait_for_visible(SELECTORS["controls"])
Beispiel #11
0
def i_created_a_video_component(_step):
    world.create_course_with_unit()
    world.create_component_instance(
        step=_step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #12
0
def i_created_a_video_component(step):
    world.create_course_with_unit()
    world.create_component_instance(
        step=step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #13
0
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')
Beispiel #14
0
def add_video_to_course(course,
                        parent_location=None,
                        player_mode=None,
                        data=None,
                        display_name='Video'):
    if not parent_location:
        parent_location = add_vertical_to_course(course)
    kwargs = get_metadata(parent_location,
                          player_mode,
                          data,
                          display_name=display_name)
    world.scenario_dict['VIDEO'] = world.ItemFactory.create(**kwargs)
    world.wait_for_present('.is-initialized')
    world.wait_for_invisible('.video-wrapper .spinner')
    world.wait_for_ajax_complete()
Beispiel #15
0
def i_created_a_video_component(step):
    step.given('I am in Studio editing a new unit')
    world.create_component_instance(
        step=step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
    if not world.youtube.config.get('youtube_api_blocked'):
        world.wait_for_visible(SELECTORS['controls'])
Beispiel #16
0
def i_created_a_video_component(step):
    step.given('I am in Studio editing a new unit')
    world.create_component_instance(
        step=step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
    if not world.youtube.config.get('youtube_api_blocked'):
        world.wait_for_visible(SELECTORS['controls'])
Beispiel #17
0
def i_created_a_video_with_subs_with_name(_step, sub_id):
    _step.given('I have created a Video component')

    # Store the current URL so we can return here
    video_url = world.browser.url

    # Upload subtitles for the video using the upload interface
    _step.given('I have uploaded subtitles "{}"'.format(sub_id))

    # Return to the video
    world.visit(video_url)

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #18
0
def i_created_a_video_with_subs_with_name(_step, sub_id):
    _step.given('I have created a Video component')

    # Store the current URL so we can return here
    video_url = world.browser.url

    # Upload subtitles for the video using the upload interface
    _step.given('I have uploaded subtitles "{}"'.format(sub_id))

    # Return to the video
    world.visit(video_url)

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #19
0
def i_created_a_video_component(_step):

    assert_less(world.youtube.config['youtube_api_response'].status_code, 400,  "Real Youtube server is unavailable")

    world.create_course_with_unit()
    world.create_component_instance(
        step=_step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
    if not world.youtube.config.get('youtube_api_blocked'):
        world.wait_for_visible(SELECTORS['controls'])
Beispiel #20
0
def add_a_multi_step_component(step, is_advanced, category):
    def click_advanced():
        css = 'ul.problem-type-tabs a[href="#tab2"]'
        world.css_click(css)
        my_css = 'ul.problem-type-tabs li.ui-state-active a[href="#tab2"]'
        assert (world.css_find(my_css))

    def find_matching_link():
        """
        Find the link with the specified text. There should be one and only one.
        """
        # The tab shows links for the given category
        links = world.css_find('div.new-component-{} a'.format(category))

        # Find the link whose text matches what you're looking for
        matched_links = [
            link for link in links if link.text == step_hash['Component']
        ]

        # There should be one and only one
        assert_equal(len(matched_links), 1)
        return matched_links[0]

    def click_link():
        link.click()

    category = category.lower()
    for step_hash in step.hashes:
        css_selector = 'a[data-type="{}"]'.format(category)
        world.css_click(css_selector)
        world.wait_for_invisible(css_selector)

        if is_advanced:
            # Sometimes this click does not work if you go too fast.
            world.retry_on_exception(click_advanced,
                                     max_attempts=5,
                                     ignored_exceptions=AssertionError)

        # Retry this in case the list is empty because you tried too fast.
        link = world.retry_on_exception(func=find_matching_link,
                                        ignored_exceptions=AssertionError)

        # Wait for the link to be clickable. If you go too fast it is not.
        world.retry_on_exception(click_link)
Beispiel #21
0
def i_created_a_video_component(_step):

    assert_less(world.youtube.config['youtube_api_response'].status_code, 400,
                "Real Youtube server is unavailable")

    world.create_course_with_unit()
    world.create_component_instance(
        step=_step,
        category='video',
    )

    world.wait_for_xmodule()
    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait(DELAY)
    world.wait_for_invisible(SELECTORS['spinner'])
    if not world.youtube.config.get('youtube_api_blocked'):
        world.wait_for_visible(SELECTORS['controls'])
def create_component_instance(step, category, component_type=None, is_advanced=False, advanced_component=None):
    """
    Create a new component in a Unit.

    Parameters
    ----------
    category: component type (discussion, html, problem, video, advanced)
    component_type: for components with multiple templates, the link text in the menu
    is_advanced: for problems, is the desired component under the advanced menu?
    advanced_component: for advanced components, the related value of policy key 'advanced_modules'
    """
    assert_in(category, ['advanced', 'problem', 'html', 'video', 'discussion'])

    component_button_css = 'span.large-{}-icon'.format(category.lower())
    if category == 'problem':
        module_css = 'div.xmodule_CapaModule'
    elif category == 'advanced':
        module_css = 'div.xmodule_{}Module'.format(advanced_component.title())
    elif category == 'discussion':
        module_css = 'div.xblock-author_view-{}'.format(category.lower())
    else:
        module_css = 'div.xmodule_{}Module'.format(category.title())

    # Count how many of that module is on the page. Later we will
    # assert that one more was added.
    # We need to use world.browser.find_by_css instead of world.css_find
    # because it's ok if there are currently zero of them.
    module_count_before = len(world.browser.find_by_css(module_css))

    # Disable the jquery animation for the transition to the menus.
    world.disable_jquery_animations()
    world.css_click(component_button_css)

    if category in ('problem', 'html', 'advanced'):
        world.wait_for_invisible(component_button_css)
        click_component_from_menu(category, component_type, is_advanced)

    expected_count = module_count_before + 1
    world.wait_for(
        lambda _: len(world.css_find(module_css)) == expected_count,
        timeout=20
    )
Beispiel #23
0
def add_a_multi_step_component(step, is_advanced, category):
    def click_advanced():
        css = 'ul.problem-type-tabs a[href="#tab2"]'
        world.css_click(css)
        my_css = 'ul.problem-type-tabs li.ui-state-active a[href="#tab2"]'
        assert(world.css_find(my_css))

    def find_matching_link():
        """
        Find the link with the specified text. There should be one and only one.
        """
        # The tab shows links for the given category
        links = world.css_find('div.new-component-{} a'.format(category))

        # Find the link whose text matches what you're looking for
        matched_links = [link for link in links if link.text == step_hash['Component']]

        # There should be one and only one
        assert_equal(len(matched_links), 1)
        return matched_links[0]

    def click_link():
        link.click()

    world.wait_for_xmodule()
    category = category.lower()
    for step_hash in step.hashes:
        css_selector = 'a[data-type="{}"]'.format(category)
        world.css_click(css_selector)
        world.wait_for_invisible(css_selector)

        if is_advanced:
            # Sometimes this click does not work if you go too fast.
            world.retry_on_exception(click_advanced, max_attempts=5, ignored_exceptions=AssertionError)

        # Retry this in case the list is empty because you tried too fast.
        link = world.retry_on_exception(func=find_matching_link, ignored_exceptions=AssertionError)

        # Wait for the link to be clickable. If you go too fast it is not.
        world.retry_on_exception(click_link)
Beispiel #24
0
def i_created_a_video_with_subs_with_name(_step, sub_id):
    _step.given('I have created a Video component')

    # Store the current URL so we can return here
    video_url = world.browser.url

    # Upload subtitles for the video using the upload interface
    _step.given('I have uploaded subtitles "{}"'.format(sub_id))

    # Return to the video
    world.visit(video_url)

    world.wait_for_xmodule()

    # update .sub filed with proper subs name (which mimics real Studio/XML behavior)
    # this is needed only for that videos which are created in acceptance tests.
    _step.given('I edit the component')
    world.wait_for_ajax_complete()
    _step.given('I save changes')

    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #25
0
def i_created_a_video_with_subs_with_name(_step, sub_id):
    _step.given('I have created a Video component')

    # Store the current URL so we can return here
    video_url = world.browser.url

    # Upload subtitles for the video using the upload interface
    _step.given('I have uploaded subtitles "{}"'.format(sub_id))

    # Return to the video
    world.visit(video_url)

    world.wait_for_xmodule()

    # update .sub filed with proper subs name (which mimics real Studio/XML behavior)
    # this is needed only for that videos which are created in acceptance tests.
    _step.given('I edit the component')
    world.wait_for_ajax_complete()
    _step.given('I save changes')

    world.disable_jquery_animations()

    world.wait_for_present('.is-initialized')
    world.wait_for_invisible(SELECTORS['spinner'])
Beispiel #26
0
def wait_for_video():
    world.wait_for_present('.is-initialized')
    world.wait_for_present('div.vidtime')
    world.wait_for_invisible('.video-wrapper .spinner')
    world.wait_for_ajax_complete()
Beispiel #27
0
def wait_for_video():
    world.wait_for_present(".is-initialized")
    world.wait_for_present("div.vidtime")
    world.wait_for_invisible(".video-wrapper .spinner")
    world.wait_for_ajax_complete()
Beispiel #28
0
def wait_for_video():
    world.wait_for_present('.is-initialized')
    world.wait_for_present('div.vidtime')
    world.wait_for_invisible('.video-wrapper .spinner')
    world.wait_for_ajax_complete()