예제 #1
0
def test_user_ranking_course(driver):
    '''Creates a course and students to participate make submits to problems'''

    run_id = driver.generate_id()
    course_alias = 'ut_rank_course_%s' % run_id
    school_name = 'ut_rank_school_%s' % run_id
    assignment_alias = 'ut_rank_hw_%s' % run_id
    problem = 'sumas'

    with driver.login_admin():
        create_course(driver, course_alias, school_name)
        add_students_course(driver, [driver.user_username])
        add_assignment(driver, assignment_alias)
        add_problem_to_assignment(driver, assignment_alias, problem)

    with driver.login_user():
        enter_course(driver, course_alias, assignment_alias)

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, ('//a[contains(text(), "%s")]/parent::div' %
                            problem.title())))).click()

        util.create_run(driver, problem, 'Main.cpp17-gcc')
        driver.update_score_in_course(problem, assignment_alias)

        # When user has tried or solved a problem, feedback popup will be shown
        with util.dismiss_status(driver):
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.CSS_SELECTOR, '.popup button.close'))).click()
            driver.wait.until(
                EC.invisibility_of_element_located(
                    (By.CSS_SELECTOR, '.popup button.close')))

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, ('//a[contains(text(), "%s")]/parent::div' %
                            problem.title())))).click()
        driver.wait.until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR, 'button[data-run-details]'))).click()

        assert (('show-run:')
                in driver.browser.current_url), driver.browser.current_url

    update_scoreboard_for_assignment(driver, assignment_alias, course_alias)

    with driver.login_admin():
        enter_course_assignments_page(driver, course_alias)
        with driver.page_transition():
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH,
                     '//a[contains(@href, "/assignment/%s/scoreboard/")]' %
                     assignment_alias))).click()

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, '//input[@class = "toggle-contestants"]'))).click()

        run_user = driver.browser.find_element_by_xpath(
            '//td[contains(@class, "accepted")]/preceding-sibling::td[@class='
            '"user"]')
        assert run_user.text == driver.user_username, run_user

        url = '/course/%s/assignment/%s/scoreboard' % (course_alias,
                                                       assignment_alias)

        enter_course_assignments_page(driver, course_alias)
        util.check_scoreboard_events(driver,
                                     assignment_alias,
                                     url,
                                     num_elements=1,
                                     scoreboard='Public')

        enter_course_assignments_page(driver, course_alias)
        util.check_scoreboard_events(driver,
                                     assignment_alias,
                                     url,
                                     num_elements=1,
                                     scoreboard='Admin')

        enter_course_assignments_page(driver, course_alias)
        with driver.page_transition():
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH, '//a[contains(@href, "/course/%s/edit/")]' %
                     course_alias))).click()

        driver.wait.until(
            EC.element_to_be_clickable((
                By.XPATH,
                '//input[@name = "show-scoreboard"][@value="true"]'))).click()

        driver.browser.find_element_by_tag_name('form').submit()
        assert (('/course/%s/edit/' % course_alias)
                in driver.browser.current_url), driver.browser.current_url

    with driver.login_user():
        enter_course(driver, course_alias, assignment_alias, first_time=False)

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, ('//a[contains(@href, "#ranking")]')))).click()
        assert (('#ranking')
                in driver.browser.current_url), driver.browser.current_url
예제 #2
0
def test_user_ranking_course(driver):
    '''Creates a course and students to participate make submits to problems'''

    run_id = driver.generate_id()
    course_alias = f'ut_rank_course_{run_id}'
    school_name = f'ut_rank_school_{run_id}'
    assignment_alias = f'ut_rank_hw_{run_id}'
    problem = 'ut_rc_problem_%s' % driver.generate_id()

    _setup_course(driver, course_alias, school_name, assignment_alias, problem)

    with driver.login_user():
        enter_course(driver, course_alias, assignment_alias)
        _click_on_problem(driver, problem)

        util.create_run(driver, problem, 'Main.cpp17-gcc')
        driver.update_score_in_course(problem, assignment_alias)

        # Refresh the current page.
        with driver.page_transition():
            driver.browser.get(driver.browser.current_url.split('#')[0])

        _click_on_problem(driver, problem)

        # When user has tried or solved a problem, feedback popup will be shown
        with util.dismiss_status(driver):
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.CSS_SELECTOR, '.popup button.close'))).click()
            driver.wait.until(
                EC.invisibility_of_element_located(
                    (By.CSS_SELECTOR, '.popup button.close')))

        _click_on_problem(driver, problem)
        driver.wait.until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR, 'button[data-run-details]'))).click()

        assert (('show-run:')
                in driver.browser.current_url), driver.browser.current_url

    update_scoreboard_for_assignment(driver, assignment_alias, course_alias)

    with driver.login_admin():
        enter_course_assignments_page(driver, course_alias)
        with driver.page_transition():
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH,
                     '//a[contains(@href, "/assignment/%s/scoreboard/")]' %
                     assignment_alias))).click()

        toggle_contestants_element = driver.wait.until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR, 'input.toggle-contestants')))
        for _ in range(10):
            toggle_contestants_element.click()
            if not toggle_contestants_element.is_selected():
                break
        else:
            logging.error('Failed to toggle contestants')

        run_user = driver.browser.find_element_by_xpath(
            '//td[contains(@class, "accepted")]/preceding-sibling::td[@class='
            '"user"]')
        assert run_user.text == driver.user_username, run_user

        url = '/course/{}/assignment/{}/scoreboard'.format(
            course_alias, assignment_alias)

        enter_course_assignments_page(driver, course_alias)
        util.check_scoreboard_events(driver,
                                     assignment_alias,
                                     url,
                                     num_elements=1,
                                     scoreboard='Scoreboard')

        enter_course_assignments_page(driver, course_alias)
        with driver.page_transition():
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH, '//a[contains(@href, "/course/%s/edit/")]' %
                     course_alias))).click()

        driver.wait.until(
            EC.element_to_be_clickable((
                By.XPATH,
                '//input[@name = "show-scoreboard"][@value="true"]'))).click()

        driver.browser.find_element_by_css_selector(
            'form[data-course-form]').submit()
        assert (('/course/%s/edit/' % course_alias)
                in driver.browser.current_url), driver.browser.current_url

    with driver.login_user():
        enter_course(driver, course_alias, assignment_alias, first_time=False)

        for _ in range(10):
            driver.wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH, ('//a[contains(@href, "#ranking")]')))).click()
            if driver.browser.current_url.endswith('#ranking'):
                break
        assert (('#ranking')
                in driver.browser.current_url), driver.browser.current_url