Exemplo n.º 1
0
def see_a_single_step_component(step):
    for step_hash in step.hashes:
        component = step_hash['Component']
        assert_in(component, ['Discussion', 'Video'])
        component_css = '.xmodule_{}Module'.format(component)
        assert_true(world.is_css_present(component_css),
                    "{} couldn't be found".format(component))
Exemplo n.º 2
0
def css_click(css_selector, index=0, wait_time=GLOBAL_WAIT_FOR_TIMEOUT, dismiss_alert=False):
    """
    Perform a click on a CSS selector, first waiting for the element
    to be present and clickable.

    This method will return True if the click worked.

    If `dismiss_alert` is true, dismiss any alerts that appear.
    """
    wait_for_clickable(css_selector, timeout=wait_time)
    wait_for_visible(css_selector, index=index, timeout=wait_time)
    assert_true(
        css_visible(css_selector, index=index),
        msg="Element {}[{}] is present but not visible".format(css_selector, index)
    )

    retry_on_exception(lambda: css_find(css_selector)[index].click())

    # Dismiss any alerts that occur.
    # We need to do this before calling `wait_for_js_to_load()`
    # to avoid getting an unexpected alert exception
    if dismiss_alert:
        world.browser.get_alert().accept()

    wait_for_js_to_load()
    return True
Exemplo n.º 3
0
def see_a_single_step_component(step):
    for step_hash in step.hashes:
        component = step_hash['Component']
        assert_in(component, ['Discussion', 'Video'])
        component_css = '.xmodule_{}Module'.format(component)
        assert_true(world.is_css_present(component_css),
                    u"{} couldn't be found".format(component))
Exemplo n.º 4
0
def see_a_problem_component(step, category):
    component_css = '.xmodule_CapaModule'
    assert_true(world.is_css_present(component_css),
                'No problem was added to the unit.')

    problem_css = '.studio-xblock-wrapper .xblock-student_view'
    # This view presents the given problem component in uppercase. Assert that the text matches
    # the component selected
    assert_true(world.css_contains_text(problem_css, category))
Exemplo n.º 5
0
def see_a_problem_component(step, category):
    component_css = '.xmodule_CapaModule'
    assert_true(world.is_css_present(component_css),
                'No problem was added to the unit.')

    problem_css = '.studio-xblock-wrapper .xblock-student_view'
    # This view presents the given problem component in uppercase. Assert that the text matches
    # the component selected
    assert_true(world.css_contains_text(problem_css, category))
Exemplo n.º 6
0
def verify_high_level_source_links(step, visible):
    if visible:
        assert_true(world.is_css_present('.launch-latex-compiler'),
                    msg="Expected to find the latex button but it is not present.")
    else:
        assert_true(world.is_css_not_present('.launch-latex-compiler'),
                    msg="Expected not to find the latex button but it is present.")

    world.cancel_component(step)
Exemplo n.º 7
0
def check_lti_component_no_elem(_step, text):
    selector_map = {
        'a launch button': '.link_lti_new_window',
        'an provider iframe': '.ltiLaunchFrame',
        'feedback': '.problem-feedback',
        'progress': '.problem-progress',
    }
    assert_in(text, selector_map)
    assert_true(world.is_css_not_present(selector_map[text]))
Exemplo n.º 8
0
def check_lti_component_no_elem(_step, text):
    selector_map = {
        'a launch button': '.link_lti_new_window',
        'an provider iframe': '.ltiLaunchFrame',
        'feedback': '.problem-feedback',
        'progress': '.problem-progress',
    }
    assert_in(text, selector_map)
    assert_true(world.is_css_not_present(selector_map[text]))
Exemplo n.º 9
0
def see_elem_text(_step, elem, text):
    selector_map = {
        'progress': '.problem-progress',
        'feedback': '.problem-feedback',
        'module title': '.problem-header',
        'button': '.link_lti_new_window',
        'description': '.lti-description'
    }
    assert_in(elem, selector_map)
    assert_true(world.css_has_text(selector_map[elem], text))
Exemplo n.º 10
0
def see_elem_text(_step, elem, text):
    selector_map = {
        'progress': '.problem-progress',
        'feedback': '.problem-feedback',
        'module title': '.problem-header',
        'button': '.link_lti_new_window',
        'description': '.lti-description'
    }
    assert_in(elem, selector_map)
    assert_true(world.css_has_text(selector_map[elem], text))
Exemplo n.º 11
0
def see_value_in_the_gradebook(_step, label, text):
    table_selector = '.grade-table'
    index = 0
    table_headers = world.css_find('{0} thead th'.format(table_selector))

    for i, element in enumerate(table_headers):
        if element.text.strip() == label:
            index = i
            break

    assert_true(world.css_has_text('{0} tbody td'.format(table_selector), text, index=index))
Exemplo n.º 12
0
def verify_high_level_source_links(step, visible):
    if visible:
        assert_true(
            world.is_css_present('.launch-latex-compiler'),
            msg="Expected to find the latex button but it is not present.")
    else:
        assert_true(
            world.is_css_not_present('.launch-latex-compiler'),
            msg="Expected not to find the latex button but it is present.")

    world.cancel_component(step)
Exemplo n.º 13
0
def see_value_in_the_gradebook(_step, label, text):
    table_selector = '.grade-table'
    index = 0
    table_headers = world.css_find('{0} thead th'.format(table_selector))

    for i, element in enumerate(table_headers):
        if element.text.strip() == label:
            index = i
            break

    assert_true(
        world.css_has_text('{0} tbody td'.format(table_selector),
                           text,
                           index=index))
Exemplo n.º 14
0
    def setUp(self):

        super(TestDirectMessage, self).setUp()

        # create a course
        self.course = CourseFactory.create(
            org='mss', course='999', display_name='eol directmessage course')

        # Patch the comment client user save method so it does not try
        # to create a new cc user when creating a django user
        with patch('student.models.cc.User.save'):
            uname = 'student'
            email = '*****@*****.**'
            password = '******'

            # Create the student
            self.main_student = UserFactory(username=uname,
                                            password=password,
                                            email=email)

            # Enroll the student in the course
            CourseEnrollmentFactory(user=self.main_student,
                                    course_id=self.course.id)

            # Log the student in
            self.main_client = Client()
            assert_true(
                self.main_client.login(username=uname, password=password))

            # Create and Enroll staff user
            self.staff_user = UserFactory(username='******',
                                          password='******',
                                          email='*****@*****.**',
                                          is_staff=True)
            CourseEnrollmentFactory(user=self.staff_user,
                                    course_id=self.course.id)

            role_staff = CourseStaffRole(self.course.id)
            role_staff.add_users(self.staff_user)

            # Log the user staff in
            self.staff_client = Client()
            assert_true(
                self.staff_client.login(username='******',
                                        password='******'))

        # Create users and enroll
        self.users = [UserFactory.create() for _ in range(USER_COUNT)]
        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
Exemplo n.º 15
0
def retry_on_exception(func, max_attempts=5, ignored_exceptions=(StaleElementReferenceException, InvalidElementStateException)):
    """
    Retry the interaction, ignoring the passed exceptions.
    By default ignore StaleElementReferenceException, which happens often in our application
    when the DOM is being manipulated by client side JS.
    Note that ignored_exceptions is passed directly to the except block, and as such can be
    either a single exception or multiple exceptions as a parenthesized tuple.
    """
    attempt = 0
    while attempt < max_attempts:
        try:
            return func()
        except ignored_exceptions:
            world.wait(1)
            attempt += 1

    assert_true(attempt < max_attempts, 'Ran out of attempts to execute {}'.format(func))
Exemplo n.º 16
0
def delete_components(step, number):
    world.wait_for_xmodule()
    delete_btn_css = '.delete-button'
    prompt_css = '#prompt-warning'
    btn_css = u'{} .action-primary'.format(prompt_css)
    saving_mini_css = '#page-notification .wrapper-notification-mini'
    for _ in range(int(number)):
        world.css_click(delete_btn_css)
        assert_true(world.is_css_present('{}.is-shown'.format(prompt_css)),
                    msg='Waiting for the confirmation prompt to be shown')

        # Pressing the button via css was not working reliably for the last component
        # when run in Chrome.
        if world.browser.driver_name == 'Chrome':
            world.browser.execute_script("$('{}').click()".format(btn_css))
        else:
            world.css_click(btn_css)

        # Wait for the saving notification to pop up then disappear
        if world.is_css_present('{}.is-shown'.format(saving_mini_css)):
            world.css_find('{}.is-hiding'.format(saving_mini_css))
Exemplo n.º 17
0
def delete_components(step, number):
    world.wait_for_xmodule()
    delete_btn_css = '.delete-button'
    prompt_css = '#prompt-warning'
    btn_css = '{} .action-primary'.format(prompt_css)
    saving_mini_css = '#page-notification .wrapper-notification-mini'
    for _ in range(int(number)):
        world.css_click(delete_btn_css)
        assert_true(
            world.is_css_present('{}.is-shown'.format(prompt_css)),
            msg='Waiting for the confirmation prompt to be shown')

        # Pressing the button via css was not working reliably for the last component
        # when run in Chrome.
        if world.browser.driver_name == 'Chrome':
            world.browser.execute_script("$('{}').click()".format(btn_css))
        else:
            world.css_click(btn_css)

        # Wait for the saving notification to pop up then disappear
        if world.is_css_present('{}.is-shown'.format(saving_mini_css)):
            world.css_find('{}.is-hiding'.format(saving_mini_css))
Exemplo n.º 18
0
    def setUp(self):
        super(TestStaffView, self).setUp()
        # create a course
        self.course = CourseFactory.create(org='mss',
                                           course='999',
                                           display_name='eol feedback course')

        # Now give it some content
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(
                parent_location=self.course.location,
                category="sequential",
            )
            section = ItemFactory.create(parent_location=chapter.location,
                                         category="sequential",
                                         metadata={
                                             'graded': True,
                                             'format': 'Homework'
                                         })
            self.items = [
                ItemFactory.create(
                    parent_location=section.location,
                    category="problem",
                    data=StringResponseXMLFactory().build_xml(answer='foo'),
                    metadata={'rerandomize': 'always'})
                for __ in range(USER_COUNT - 1)
            ]

        # Create users, enroll and set grades
        self.users = [UserFactory.create() for _ in range(USER_COUNT)]
        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
        for i, item in enumerate(self.items):
            for j, user in enumerate(self.users):
                StudentModuleFactory.create(grade=1 if i < j else 0,
                                            max_grade=1,
                                            student=user,
                                            course_id=self.course.id,
                                            module_state_key=item.location)
        task_compute_all_grades_for_course.apply_async(
            kwargs={'course_key': text_type(self.course.id)})

        # Patch the comment client user save method so it does not try
        # to create a new cc user when creating a django user
        with patch('student.models.cc.User.save'):
            # Create the student
            self.student = UserFactory(username='******',
                                       password='******',
                                       email='*****@*****.**')
            # Enroll the student in the course
            CourseEnrollmentFactory(user=self.student,
                                    course_id=self.course.id)

            # Create and Enroll staff user
            self.staff_user = UserFactory(username='******',
                                          password='******',
                                          email='*****@*****.**',
                                          is_staff=True)
            CourseEnrollmentFactory(user=self.staff_user,
                                    course_id=self.course.id)

            # Log the student in
            self.client = Client()
            assert_true(self.client.login(username='******', password='******'))

            # Log the user staff in
            self.staff_client = Client()
            assert_true(
                self.staff_client.login(username='******',
                                        password='******'))