def construct_test_table_builder_page(driver, live_server, measure_version, rdu_user):
    driver_login(driver, live_server, rdu_user)
    """
    BROWSE TO POINT WHERE WE CAN ADD A MEASURE
    """
    home_page = HomePage(driver, live_server)
    home_page.click_topic_link(measure_version.measure.subtopic.topic)
    topic_page = TopicPage(driver, live_server, measure_version.measure.subtopic.topic)
    topic_page.expand_accordion_for_subtopic(measure_version.measure.subtopic)
    """
    SET UP A SIMPLE DIMENSION WE CAN BUILD TEST TABLES ON
    """
    topic_page.click_add_measure(measure_version.measure.subtopic)
    topic_page.wait_until_url_contains("/measure/new")
    create_measure(
        driver, live_server, measure_version, measure_version.measure.subtopic.topic, measure_version.measure.subtopic
    )
    topic_page.wait_until_url_contains("/edit")
    edit_measure_page = MeasureEditPage(driver)
    edit_measure_page.get()
    dimension = MinimalRandomDimension()
    edit_measure_page.click_add_dimension()
    edit_measure_page.wait_until_url_contains("/dimension/new")
    create_dimension_page = DimensionAddPage(driver)
    create_dimension_page.set_title(dimension.title)
    create_dimension_page.set_time_period(dimension.time_period)
    create_dimension_page.set_summary(dimension.summary)
    create_dimension_page.click_save()
    edit_dimension_page = DimensionEditPage(driver)
    edit_dimension_page.get()
    edit_dimension_page.wait_for_seconds(1)
    edit_dimension_page.click_create_table()
    edit_dimension_page.wait_until_url_contains("create-table")
    table_builder_page = TableBuilderPage(driver)
    return table_builder_page
def test_adding_an_existing_data_source(driver, app, live_server):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)

    topic = TopicFactory.create(title="Police and crime")
    subtopic = SubtopicFactory.create(title="Policing", topic=topic)
    DataSourceFactory.create(title="Police statistics 2019")

    existing_measure = MeasureFactory.create(subtopics=[subtopic])
    MeasureVersionFactory.create(status="APPROVED", measure=existing_measure)

    driver_login(driver, live_server, rdu_user)
    home_page = HomePage(driver, live_server)

    home_page.click_topic_link(topic)

    topic_page = TopicPage(driver, live_server, topic)
    topic_page.expand_accordion_for_subtopic(subtopic)

    topic_page.click_add_measure(subtopic)

    create_measure_page = MeasureEditPage(driver)
    create_measure_page.set_title("Arrests")
    create_measure_page.click_save()

    create_measure_page.click_add_primary_data_source()

    fill_in(driver,
            label_text="Search for an existing data source",
            with_text="Police statistics")
    click_button_with_text(driver, "Search")

    label_for_existing_data_source = driver.find_element_by_xpath(
        "//label[text()='Police statistics 2019']")

    label_for_existing_data_source.click()

    click_button_with_text(driver, "Select")

    assert "Successfully added the data source ‘Police statistics 2019’" in driver.page_source

    click_link_with_text(driver, "Preview this version")

    assert "Police statistics 2019" in driver.page_source
def test_secondary_source_can_be_added_and_removed(driver, live_server, government_departments, frequencies_of_release):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)
    approved_measure_version = MeasureVersionFactory(
        status="APPROVED",
        data_sources__publisher=random.choice(government_departments),
        data_sources__frequency_of_release=random.choice(frequencies_of_release),
    )
    sample_measure_version = MeasureVersionFactory.build(data_sources=[])
    sample_data_source = DataSourceFactory.build(
        publisher__name=random.choice(government_departments).name,
        frequency_of_release__description=random.choice(frequencies_of_release).description,
    )

    # GIVEN a setup with Topic and Subtopic
    driver_login(driver, live_server, rdu_user)
    navigate_to_topic_page(driver, live_server, approved_measure_version.measure.subtopic.topic)

    # WHEN an editor creates and saves a new measure page
    measure_edit_page, page = create_measure_starting_at_topic_page(
        driver,
        live_server,
        approved_measure_version.measure.subtopic.topic,
        approved_measure_version.measure.subtopic,
        sample_measure_version,
        sample_data_source,
    )

    # Add and save a secondary data source
    measure_edit_page.click_add_secondary_data_source()

    fill_in(driver, label_text="Search for an existing data source", with_text="My data source")

    click_button_with_text(driver, "Search")

    click_link_with_text(driver, "Create a new data source")

    data_source_page = CreateDataSourcePage(driver)
    data_source_page.fill_data_source(sample_data_source)
    data_source_page.click_save()
    data_source_page.click_back()

    # Remove the secondary source
    measure_edit_page.click_remove_secondary_data_source()
def test_delete_a_draft_1_0_measure(driver, live_server):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)
    measure_version = MeasureVersionFactory(status="APPROVED")

    assert Measure.query.count() == 1

    # GIVEN we create a version 1.0 measure
    driver_login(driver, live_server, rdu_user)
    navigate_to_topic_page(driver, live_server,
                           measure_version.measure.subtopic.topic)
    measure = create_measure_with_minimal_content(
        driver, live_server, measure_version.measure.subtopic,
        measure_version.measure.subtopic.topic)

    assert Measure.query.count() == 2

    # WHEN we go to the topic page
    topic_page = TopicPage(driver, live_server,
                           measure_version.measure.subtopic.topic)
    topic_page.get()

    # No longer required; accordion remembers the expanded state from earlier in the test.
    # topic_page.expand_accordion_for_subtopic(measure_version.measure.subtopic)

    # THEN measure is listed
    assert topic_page.measure_is_listed(measure) is True

    driver.find_element_by_link_text(measure.title).click()

    # WHEN we walk through the delete process
    driver.find_element_by_xpath(
        f"//a[contains(., 'Delete page: {measure.title}')]").click()

    driver.find_element_by_xpath('//button[text()="Yes, delete"]').click()

    topic_page.get()
    # This test has been passing when the final .get() returned a 500 error page.
    # TODO: Check the page didn't error and is the actual page we expect to not find the thing in
    # TODO: Maybe assert 200 responses after all get()s in functional tests?
    assert topic_page.measure_is_listed(measure) is False

    assert Measure.query.count() == 1
示例#5
0
def test_can_reject_a_measure_in_review_as_editor(driver, live_server,
                                                  government_departments,
                                                  frequencies_of_release):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)
    approved_measure_version = MeasureVersionFactory(
        status="APPROVED",
        data_sources__publisher=random.choice(government_departments),
        data_sources__frequency_of_release=random.choice(
            frequencies_of_release),
    )
    sample_measure_version = MeasureVersionFactory.build(data_sources=[])
    sample_data_source = DataSourceFactory.build(
        publisher__name=random.choice(government_departments).name,
        frequency_of_release__description=random.choice(
            frequencies_of_release).description,
    )

    # GIVEN a setup with Topic and Subtopic
    driver_login(driver, live_server, rdu_user)
    navigate_to_topic_page(driver, live_server,
                           approved_measure_version.measure.subtopic.topic)

    # WHEN an editor creates and saves a new measure page
    measure_edit_page, page = create_measure_starting_at_topic_page(
        driver,
        live_server,
        approved_measure_version.measure.subtopic.topic,
        approved_measure_version.measure.subtopic,
        sample_measure_version,
        sample_data_source,
    )

    # THEN the status should be draft
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["draft"]

    # WHEN we save and send it to internal review
    measure_edit_page.click_save_and_send_to_review()

    # THEN the status should be internal review
    assert measure_edit_page.get_status(
    ) == EXPECTED_STATUSES["internal_review"]

    # WHEN we reject the page
    measure_edit_page.click_reject()

    # THEN the status should be rejected
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["rejected"]

    # WHEN we send it back to a draft
    measure_edit_page.click_send_back_to_draft()

    # THEN the status should be draft
    driver.implicitly_wait(2)
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["draft"]

    # WHEN we save and send it for department review
    measure_edit_page.click_save_and_send_to_review()
    measure_edit_page.click_department_review()

    # THEN the status should be department review
    driver.implicitly_wait(2)
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status(
    ) == EXPECTED_STATUSES["department_review"]

    # WHEN we reject the measure again
    measure_edit_page.click_reject()

    # THEN the status should be rejected
    driver.implicitly_wait(2)
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["rejected"]

    measure_edit_page.log_out()
def test_can_create_a_measure_page(driver, app, live_server):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)
    measure_version = MeasureVersionFactory(status="APPROVED")

    driver_login(driver, live_server, rdu_user)

    """
    BROWSE TO POINT WHERE WE CAN ADD A MEASURE
    """
    home_page = HomePage(driver, live_server)
    home_page.click_topic_link(measure_version.measure.subtopic.topic)

    topic_page = TopicPage(driver, live_server, measure_version.measure.subtopic.topic)
    topic_page.expand_accordion_for_subtopic(measure_version.measure.subtopic)

    """
    CREATE A NEW MEASURE
    """
    topic_page.click_add_measure(measure_version.measure.subtopic)
    topic_page.wait_until_url_contains("/measure/new")
    create_measure(
        driver, live_server, measure_version, measure_version.measure.subtopic.topic, measure_version.measure.subtopic
    )

    """
    EDIT THE MEASURE
    """
    topic_page.wait_until_url_contains("/edit")
    edit_measure_page = MeasureEditPage(driver)

    edit_measure_page.set_measure_summary(measure_version.measure_summary)
    edit_measure_page.set_summary(measure_version.summary)
    edit_measure_page.click_save()
    assert edit_measure_page.is_current()

    """
    PREVIEW CURRENT PROGRESS
    """
    edit_measure_page.click_preview()
    edit_measure_page.wait_until_url_does_not_contain("/cms/")

    preview_measure_page = MeasurePreviewPage(driver)
    assert preview_measure_page.is_current()

    assert_page_contains(preview_measure_page, measure_version.title)
    assert_page_contains(preview_measure_page, measure_version.measure_summary)
    assert_page_contains(preview_measure_page, measure_version.summary)

    """
    ADD A DIMENSION
    Save some dimension data
    """
    edit_measure_page.get()
    assert edit_measure_page.is_current()

    dimension = RandomDimension()

    edit_measure_page.click_add_dimension()
    edit_measure_page.wait_until_url_contains("/dimension/new")

    create_dimension_page = DimensionAddPage(driver)

    create_dimension_page.set_title(dimension.title)
    create_dimension_page.set_time_period(dimension.time_period)
    create_dimension_page.set_summary(dimension.summary)
    create_dimension_page.click_save()

    edit_dimension_page = DimensionEditPage(driver)
    assert edit_dimension_page.is_current()

    preview_measure_page.get()
    edit_dimension_page.wait_until_url_does_not_contain("/cms/")
    assert_page_contains(preview_measure_page, dimension.title)
    assert_page_contains(preview_measure_page, dimension.time_period)
    assert_page_contains(preview_measure_page, dimension.summary)

    """
    EDIT A DIMENSION
    """
    edit_dimension_page.get()
    assert edit_dimension_page.is_current()

    edit_dimension_page.set_summary("some updated text")
    edit_dimension_page.click_update()

    assert edit_dimension_page.is_current()

    preview_measure_page.get()
    edit_dimension_page.wait_until_url_does_not_contain("/cms/")
    assert_page_contains(preview_measure_page, "some updated text")

    """
    CHART BUILDER
    test content has been moved to a separate set of functional tests
    """

    """
    CREATE A SIMPLE TABLE
    """
    edit_dimension_page.get()
    assert edit_dimension_page.is_current()
    edit_dimension_page.click_create_table()
    edit_dimension_page.wait_until_url_contains("create-table")

    table_builder_page = TableBuilderPage(driver)
    assert table_builder_page.is_current()

    inject_data(driver, simple_data)
    table_builder_page.click_data_ok()
    table_builder_page.select_column(1, "Value")
    table_builder_page.click_save()
    table_builder_page.wait_for_seconds(1)

    """
    CREATE A TABLE WITH TWO COLUMNS
    """
    table_builder_page.get()
    table_builder_page.click_data_edit()
    inject_data(driver, ethnicity_by_gender_data)
    table_builder_page.click_data_ok()

    table_builder_page.select_data_style("Use ethnicity for rows")
    table_builder_page.select_columns_when_ethnicity_is_row("Gender")
    table_builder_page.select_column(1, "Value")
    table_builder_page.select_column(2, "Gender")

    table_builder_page.click_save()
def test_create_a_measure_as_editor(driver, live_server,
                                    government_departments,
                                    frequencies_of_release):
    rdu_user = UserFactory(user_type=TypeOfUser.RDU_USER, active=True)
    admin_user = UserFactory(user_type=TypeOfUser.ADMIN_USER, active=True)
    approved_measure_version = MeasureVersionFactory(
        status="APPROVED",
        data_sources__publisher=random.choice(government_departments),
        data_sources__frequency_of_release=random.choice(
            frequencies_of_release),
    )
    sample_measure_version = MeasureVersionFactory.build(
        version="1.1", data_sources=[], update_corrects_data_mistake=True)
    sample_data_source = DataSourceFactory.build(
        publisher__name=random.choice(government_departments).name,
        frequency_of_release__description=random.choice(
            frequencies_of_release).description,
    )

    # GIVEN a setup with Topic and Subtopic
    driver_login(driver, live_server, rdu_user)
    navigate_to_topic_page(driver, live_server,
                           approved_measure_version.measure.subtopic.topic)

    # WHEN an editor creates and saves a new measure page
    measure_edit_page, page = create_measure_starting_at_topic_page(
        driver,
        live_server,
        approved_measure_version.measure.subtopic.topic,
        approved_measure_version.measure.subtopic,
        sample_measure_version,
        sample_data_source,
    )

    # THEN the status should be draft
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["draft"]

    measure_edit_page.click_save_and_send_to_review()

    # THEN the status should be internal review
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status(
    ) == EXPECTED_STATUSES["internal_review"]

    # WHEN we send page to department review
    measure_edit_page.click_department_review()

    # THEN the status should be department review
    driver.implicitly_wait(2)
    assert measure_edit_page.is_current()
    assert measure_edit_page.get_status(
    ) == EXPECTED_STATUSES["department_review"]

    # AND the approve button should not be on page
    assert measure_edit_page.approved_is_visible() is False

    # GIVEN the department link
    review_link = measure_edit_page.get_review_link()

    # WHEN we log out and go to the review link
    measure_edit_page.log_out()
    driver.get(review_link)

    # THEN the preview page ought to have content
    assert page.title in driver.page_source

    # GIVEN the admin user
    driver_login(driver, live_server, admin_user)

    # WHEN we go to the edit page
    navigate_to_edit_page(
        driver,
        live_server,
        approved_measure_version.measure.subtopic.topic,
        approved_measure_version.measure.subtopic,
        page,
    )

    # THEN the approve button is visible
    assert measure_edit_page.approved_is_visible() is True

    # WHEN the admin user clicks approve
    measure_edit_page.click_approved()

    # THEN the status should be published
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["published"]

    # WHEN we create a minor update
    measure_edit_page.click_update()
    measure_create_version_page = MeasureCreateVersionPage(driver)
    measure_create_version_page.click_minor_update()
    measure_create_version_page.click_create()

    # THEN we are on the 1.1 measure version edit page
    assert driver.current_url.endswith("/1.1/edit")

    # WHEN we try to submit the minor update immediately
    measure_edit_page.click_save_and_send_to_review()

    # THEN we get validation errors (corrections radio+edit summary)
    assert "There is a problem" in driver.page_source

    # WHEN we fill in the required data
    measure_edit_page.fill_measure_page_minor_edit_fields(
        sample_measure_version)

    # THEN we can publish the new version.
    measure_edit_page.click_save_and_send_to_review()
    measure_edit_page.click_department_review()
    measure_edit_page.click_approved()

    # THEN the status should be published
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["published"]

    # WHEN we create a major update
    measure_edit_page.click_update()
    measure_create_version_page = MeasureCreateVersionPage(driver)
    measure_create_version_page.click_major_update()
    measure_create_version_page.click_create()

    # THEN we are on the 2.0 measure version edit page
    assert driver.current_url.endswith("/2.0/edit")

    # WHEN we try to submit the major update immediately
    measure_edit_page.click_save_and_send_to_review()

    # THEN we get validation errors (edit summary)
    assert "There is a problem" in driver.page_source

    # WHEN we add an upload file
    measure_edit_page.click_add_source_data()
    add_source_data_page = AddSourceDataPage(driver)
    add_source_data_page.fill_source_data_page(
        sample_measure_version.uploads[0])
    add_source_data_page.click_save()

    # AND provide an edit summary
    measure_edit_page.fill_measure_page_major_edit_fields(
        sample_measure_version)
    measure_edit_page.click_save()

    # AND add a new primary data source
    add_primary_data_source_to_measure(driver, sample_data_source)

    # AND approve the major edit
    measure_edit_page.click_save_and_send_to_review()
    measure_edit_page.click_department_review()
    measure_edit_page.click_approved()

    # THEN the status should be published
    assert measure_edit_page.get_status() == EXPECTED_STATUSES["published"]

    measure_edit_page.log_out()
def test_merging_two_data_sources(driver, live_server):

    # Setup
    DataSourceFactory.create(title="Police statistics 2019")
    DataSourceFactory.create(title="Police stats 2019")
    admin_user = UserFactory(user_type=TypeOfUser.ADMIN_USER, active=True)

    driver_login(driver, live_server, admin_user)

    # When I go to the admin page
    driver.get(f"http://localhost:{live_server.port}/admin")

    # Then there should be a link to Data sources
    data_sources_link = driver.find_element_by_link_text("Data sources")
    assert data_sources_link

    # When I click the link
    data_sources_link.click()

    # Then I should be on the data sources page
    assert "Data sources" == driver.find_element_by_tag_name("h1").text

    assert "Select all options that represent the same data source" == driver.find_element_by_tag_name(
        "legend").text

    data_source_1_label = driver.find_element_by_xpath(
        "//label[text() = 'Police statistics 2019']")

    assert data_source_1_label

    data_source_2_label = driver.find_element_by_xpath(
        "//label[text() = 'Police stats 2019']")

    assert data_source_2_label

    submit_button = driver.find_element_by_xpath(
        "//button[text() = 'Continue']")

    assert submit_button

    # When I select the two data sources and click continue
    data_source_1_label.click()
    data_source_2_label.click()
    submit_button.click()

    # Then I should be on the merge data sources page

    assert "Merge 2 data sources" == driver.find_element_by_tag_name("h1").text
    assert "Which one would you like to keep?" == driver.find_element_by_tag_name(
        "legend").text

    data_source_1_label = driver.find_element_by_xpath(
        "//label[text() = 'Police statistics 2019']")

    assert data_source_1_label

    data_source_2_label = driver.find_element_by_xpath(
        "//label[text() = 'Police stats 2019']")

    assert data_source_2_label

    submit_button = driver.find_element_by_xpath("//button[text() = 'Merge']")

    assert submit_button

    # When I select the first data source and click merge
    data_source_1_label.click()
    submit_button.click()

    # Then I should be back on the Data sources page
    assert "Data sources" == driver.find_element_by_tag_name("h1").text

    data_source_1_label = driver.find_element_by_xpath(
        "//label[text() = 'Police statistics 2019']")

    assert data_source_1_label

    with pytest.raises(NoSuchElementException):
        data_source_2_label = driver.find_element_by_xpath(
            "//label[text() = 'Police stats 2019']")