Ejemplo n.º 1
0
def test_create_problem(driver):
    '''Tests creating a public problem and retrieving it.'''

    problem_alias = 'ut_problem_%s' % driver.generate_id()
    with driver.login_admin():
        util.create_problem(driver, problem_alias)

    with driver.login_user():
        prepare_run(driver, problem_alias)
        assert (problem_alias in driver.browser.find_element_by_xpath(
            '//h1[@class="title"]').get_attribute('innerText'))

        runs_before_submit = driver.browser.find_elements_by_css_selector(
            'td[data-run-status]')

        filename = 'Main.java'
        util.create_run(driver, problem_alias, filename)

        runs_after_submit = driver.browser.find_elements_by_css_selector(
            'td[data-run-status]')

        assert len(runs_before_submit) + 1 == len(runs_after_submit)

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH,
                 '//button[contains(@class, "details")]'))).click()

        driver.wait.until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, '[data-run-details-view]')))

        textarea = driver.browser.find_element_by_xpath(
            '//form[@data-run-details-view]//div[@class="CodeMirror-code"]')

        assert textarea.text is not None

        resource_path = os.path.join(util.OMEGAUP_ROOT,
                                     'frontend/tests/resources', filename)
        # The text of the CodeMirror editor contains the line number.
        # Non-exact match is needed.
        with open(resource_path, 'r') as f:
            for row in f.read().splitlines():
                if row is not None:
                    assert (row in textarea.text), row

        driver.browser.find_element_by_id('overlay').click()
        driver.update_score(problem_alias)

    with driver.login_user():
        prepare_run(driver, problem_alias)
        driver.wait.until(
            EC.visibility_of_element_located(
                (By.XPATH,
                 '//div[contains(concat(" ", normalize-space(@class), " "), '
                 '" qualitynomination-popup ")]/form[contains(concat(" ", '
                 'normalize-space(@class), " "), " popup ")]')))
Ejemplo n.º 2
0
def _setup_course(driver: conftest.Driver, course_alias: str, school_name: str,
                  assignment_alias: str, problem_alias: str) -> None:
    with driver.login_admin():
        util.create_problem(
            driver,
            problem_alias,
            resource_path='frontend/tests/resources/testproblem.zip')
        create_course(driver, course_alias, school_name)
        add_students_course(driver, [driver.user_username])
        add_assignment_with_problem(driver, assignment_alias, problem_alias)
Ejemplo n.º 3
0
def test_create_problem(driver):
    '''Tests creating a public problem and retrieving it.'''

    problem_alias = 'ut_problem_%s' % driver.generate_id()
    with driver.login_admin():
        util.create_problem(driver, problem_alias)

    with driver.login_user():
        prepare_run(driver, problem_alias)
        assert (problem_alias in driver.browser.find_element_by_xpath(
            '//h3[@data-problem-title]').get_attribute('innerText'))

        runs_before_submit = driver.browser.find_elements_by_xpath(
            '//div[contains(concat(" ", normalize-space(@class), " "), " '
            'active ")]/div/div/table[contains(concat(" ", normalize-space('
            '@class), " "), " runs ")]/tbody/tr/td[@data-run-status]')

        filename = 'Main.java'
        util.create_run(driver, problem_alias, filename)

        runs_after_submit = driver.browser.find_elements_by_xpath(
            '//div[contains(concat(" ", normalize-space(@class), " "), " '
            'active ")]/div/div/table[contains(concat(" ", normalize-space('
            '@class), " "), " runs ")]/tbody/tr/td[@data-run-status]')

        assert len(runs_before_submit) + 1 == len(runs_after_submit)

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH,
                 '//button[contains(concat(" ", normalize-space(@class), " "),'
                 ' " details ")]'))).click()

        driver.wait.until(
            EC.visibility_of_element_located(
                (By.XPATH,
                 '//div[contains(concat(" ", normalize-space(@class), " "), " '
                 'active ")]/div[@data-overlay]/div[@data-overlay-popup]/form['
                 '@data-run-details-view]')))

        textarea = driver.browser.find_element_by_xpath(
            '//div[contains(concat(" ", normalize-space(@class), " "), " '
            'active ")]/div[@data-overlay]/div[@data-overlay-popup]/form['
            '@data-run-details-view]//div[@class="CodeMirror-code"]')

        assert textarea.text is not None

        resource_path = os.path.join(util.OMEGAUP_ROOT,
                                     'frontend/tests/resources', filename)
        # The text of the CodeMirror editor contains the line number.
        # Non-exact match is needed.
        with open(resource_path, 'r') as f:
            for row in f.read().splitlines():
                if row is not None:
                    assert (row in textarea.text), row

        driver.browser.find_element_by_xpath(
            '//div[contains(concat(" ", normalize-space(@class), " "), " '
            'active ")]/div[@data-overlay]').click()
        driver.update_score(problem_alias)

    with driver.login_user():
        prepare_run(driver, problem_alias)
        driver.wait.until(
            EC.visibility_of_element_located(
                (By.XPATH,
                 '//div[contains(concat(" ", normalize-space(@class), " "), " '
                 'active ")]/div[@data-overlay]/div[@data-overlay-popup]/form['
                 '@data-promotion-popup]')))

    with driver.login_admin():
        prepare_run(driver, problem_alias)
        util.show_run_details(driver, code='java.util.Scanner')

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH,
                 '//div[contains(concat(" ", normalize-space(@class), " "), '
                 '" tab-content ")]/div[contains(concat(" ", '
                 'normalize-space(@class), " "), " show ")]/div[@data-overlay]'
                 '/div[@data-overlay-popup]/button'))).click()

        assert driver.browser.current_url.endswith('#runs')

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH,
                 '//table[contains(concat(" ", normalize-space(@class), " "), '
                 '" runs ")]/tbody/tr/td/div[contains(concat(" ", '
                 'normalize-space(@class), " "), " dropdown ")]/'
                 'button'))).click()

        driver.wait.until(
            EC.element_to_be_clickable(
                (By.XPATH,
                 '//table[contains(concat(" ", normalize-space(@class), " "), '
                 '" runs ")]/tbody/tr/td/div[contains(concat(" ", '
                 'normalize-space(@class), " "), " show ")]/div/button['
                 '@data-actions-rejudge]'))).click()

        global_run = driver.browser.find_element_by_xpath(
            '//table[contains(concat(" ", normalize-space(@class), " "), " '
            'runs ")]/tbody/tr/td[@data-run-status]/span')

        assert global_run.text in ('rejudging', 'AC')