コード例 #1
0
    def test_redirect_with_flash_if_measure_version_has_two_data_sources_already(
            self, test_app_client, logged_in_rdu_user, db):
        measure_version = MeasureVersionFactory()

        DataSourceFactory(measure_versions=[measure_version])
        third_data_source = DataSourceFactory()

        res = test_app_client.post(
            url_for(
                "cms.link_existing_data_source",
                topic_slug=measure_version.measure.subtopic.topic.slug,
                subtopic_slug=measure_version.measure.subtopic.slug,
                measure_slug=measure_version.measure.slug,
                version=measure_version.version,
            ),
            follow_redirects=False,
            data=ImmutableMultiDict(
                (("data_sources", third_data_source.id), )),
        )

        assert parse.urlparse(res.location).path == url_for(
            "cms.edit_measure_version",
            topic_slug=measure_version.measure.subtopic.topic.slug,
            subtopic_slug=measure_version.measure.subtopic.slug,
            measure_slug=measure_version.measure.slug,
            version=measure_version.version,
        )

        redirected_response = test_app_client.get(res.location,
                                                  follow_redirects=True)

        assert "Only two data sources can currently be linked to a measure version." in redirected_response.get_data(
            as_text=True)
コード例 #2
0
    def test_data_sources_already_linked_to_measure_version_are_excluded(self, test_app_client, logged_in_admin_user):
        measure_version = MeasureVersionFactory(data_sources__title="Data source 1")
        DataSourceFactory(title="Data source 2")
        DataSourceFactory(title="Data source 3")

        response = test_app_client.get(self.__search_url(measure_version) + "?q=data")
        page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")

        with pytest.raises(Exception):
            find_input_for_label_with_text(page, "Data source 1")

        assert find_input_for_label_with_text(page, "Data source 2")
        assert find_input_for_label_with_text(page, "Data source 3")
    def test_major_version_update_has_no_linked_data_sourceS(self):
        data_source_1 = DataSourceFactory()
        data_source_2 = DataSourceFactory()
        measure_version = MeasureVersionFactory(
            version="1.0", data_sources=[data_source_1, data_source_2])
        user = UserFactory(user_type=TypeOfUser.RDU_USER)

        assert len(measure_version.data_sources) == 2
        assert DataSource.query.count() == 2

        new_version = page_service.create_measure_version(
            measure_version, NewVersionType.MAJOR_UPDATE, user=user)

        assert DataSource.query.count() == 2
        assert new_version.data_sources == []
コード例 #4
0
    def test_404_if_data_source_not_associated_with_measure_version(
            self, test_app_client, logged_in_rdu_user):
        measure_version = MeasureVersionFactory(data_sources=[])
        data_source = DataSourceFactory()

        res = test_app_client.post(
            url_for(
                "cms.remove_data_source",
                topic_slug=measure_version.measure.subtopic.topic.slug,
                subtopic_slug=measure_version.measure.subtopic.slug,
                measure_slug=measure_version.measure.slug,
                version=measure_version.version,
                data_source_id=data_source.id,
            ),
            follow_redirects=True,
        )

        assert res.status_code == 404

        measure_version.data_sources = [data_source]

        res = test_app_client.post(
            url_for(
                "cms.remove_data_source",
                topic_slug=measure_version.measure.subtopic.topic.slug,
                subtopic_slug=measure_version.measure.subtopic.slug,
                measure_slug=measure_version.measure.slug,
                version=measure_version.version,
                data_source_id=data_source.id,
            ),
            follow_redirects=True,
        )

        assert res.status_code == 200
    def test_create_measure_version_other_than_major_creates_associations_rather_than_copies_of_existing_data_sources(
            self, version_type):
        data_source_1 = DataSourceFactory()
        data_source_2 = DataSourceFactory()
        measure_version = MeasureVersionFactory(
            version="1.0", data_sources=[data_source_1, data_source_2])
        user = UserFactory(user_type=TypeOfUser.RDU_USER)

        assert len(measure_version.data_sources) == 2
        assert DataSource.query.count() == 2

        new_version = page_service.create_measure_version(measure_version,
                                                          version_type,
                                                          user=user)

        assert DataSource.query.count() == 2
        assert measure_version.data_sources == new_version.data_sources
コード例 #6
0
    def test_search_returning_zero_results_shows_no_results_message_and_link_to_create_data_source(
        self, test_app_client, logged_in_admin_user
    ):
        measure_version = MeasureVersionFactory(data_sources__title="Data source 1")
        DataSourceFactory(title="Data source 2")
        DataSourceFactory(title="Data source 3")

        response = test_app_client.get(
            self.__search_url(measure_version) + "?q=definitely-not-going-to-appear-in-a-data-source"
        )
        doc = html.fromstring(response.get_data(as_text=True))

        assert (
            "No results found. Try again with different words or a less specific search, or create a new data source."
            in response.get_data(as_text=True)
        )

        assert doc.xpath("//a[text()='Create a new data source']")
コード例 #7
0
    def test_csrf_protection(self, test_app_client, logged_in_rdu_user,
                             isolated_app_config):
        current_app.config["WTF_CSRF_ENABLED"] = True
        measure_version = MeasureVersionFactory(data_sources=[])
        data_source = DataSourceFactory()

        res = test_app_client.post(
            url_for(
                "cms.remove_data_source",
                topic_slug=measure_version.measure.subtopic.topic.slug,
                subtopic_slug=measure_version.measure.subtopic.slug,
                measure_slug=measure_version.measure.slug,
                version=measure_version.version,
                data_source_id=data_source.id,
            ),
            follow_redirects=True,
        )

        assert res.status_code == 400
        assert "The CSRF token is missing." in res.get_data(as_text=True)
コード例 #8
0
def test_view_measure_page(test_app_client, logged_in_rdu_user):
    data_source = DataSourceFactory(
        title="DWP Stats",
        source_url="http://dwp.gov.uk",
        note_on_corrections_or_updates="Note on corrections or updates",
        publication_date="15th May 2017",
        publisher__name="Department for Work and Pensions",
        type_of_data=[TypeOfData.SURVEY],
        type_of_statistic__external="National",
        frequency_of_release__description="Quarterly",
        purpose="Purpose of data source",
    )
    measure_version = MeasureVersionFactory(
        status="DRAFT",
        title="Test Measure Page",
        area_covered=[UKCountry.ENGLAND],
        lowest_level_of_geography__name="UK",
        time_covered="4 months",
        need_to_know="Need to know this",
        measure_summary="Unemployment measure summary",
        ethnicity_definition_summary=
        "This is a summary of ethnicity definitions",
        methodology="how we measure unemployment",
        suppression_and_disclosure="Suppression rules and disclosure control",
        data_sources=[data_source],
    )

    resp = test_app_client.get(
        url_for(
            "static_site.measure_version",
            topic_slug=measure_version.measure.subtopic.topic.slug,
            subtopic_slug=measure_version.measure.subtopic.slug,
            measure_slug=measure_version.measure.slug,
            version=measure_version.version,
        ))

    assert resp.status_code == 200
    page = BeautifulSoup(resp.data.decode("utf-8"), "html.parser")

    assert page.h1.text.strip() == measure_version.title

    # check that the status bar is shown
    assert page.find("div", class_="status")

    things_to_know = page.select_one("#things-you-need-to-know summary")
    assert things_to_know.text.strip() == "Things you need to know"

    what_measured = page.select_one("#what-the-data-measures summary")
    assert what_measured.text.strip() == "What the data measures"

    categories_used = page.select_one(
        "#the-ethnic-categories-used-in-this-data summary")
    assert categories_used.text.strip(
    ) == "The ethnic categories used in this data"

    # methodology section
    methodology = page.find("h2", attrs={"id": "methodology"})
    assert methodology.text.strip() == "2. Methodology"
    methodology_headings = methodology.parent.parent.find_all("h3")
    assert methodology_headings[0].text.strip(
    ) == "Suppression rules and disclosure control"
    assert methodology_headings[1].text.strip() == "Rounding"
    assert methodology_headings[2].text.strip() == "Related publications"

    data_source_heading = page.find("h2", attrs={"id": "data-sources"})
    assert data_source_heading.text.strip() == "3. Data sources"
    data_source_subheadings = data_source_heading.parent.find_all("h3")
    assert data_source_subheadings[0].text.strip() == "Source"
    assert data_source_subheadings[1].text.strip() == "Type of data"
    assert data_source_subheadings[2].text.strip() == "Type of statistic"
    assert data_source_subheadings[3].text.strip() == "Publisher"
    assert data_source_subheadings[4].text.strip(
    ) == "Note on corrections or updates"
    assert data_source_subheadings[5].text.strip() == "Publication frequency"
    assert data_source_subheadings[6].text.strip() == "Purpose of data source"

    download_the_data = page.find("h2", attrs={"id": "download-the-data"})
    assert download_the_data
    assert download_the_data.text.strip() == "4. Download the data"
コード例 #9
0
def test_view_export_page(test_app_client, logged_in_rdu_user):
    data_source = DataSourceFactory(
        title="DWP Stats",
        source_url="http://dwp.gov.uk",
        note_on_corrections_or_updates="Note on corrections or updates",
        publication_date="15th May 2017",
        publisher__name="Department for Work and Pensions",
        type_of_data=[TypeOfData.SURVEY],
        type_of_statistic__external="National",
        frequency_of_release__description="Quarterly",
        purpose="There is no purpose",
    )
    measure_version = MeasureVersionFactory(
        status="DRAFT",
        title="Test Measure Page",
        area_covered=[UKCountry.ENGLAND],
        lowest_level_of_geography__name="UK",
        time_covered="4 months",
        need_to_know="Need to know this",
        measure_summary="Unemployment measure summary",
        ethnicity_definition_summary=
        "This is a summary of ethnicity definitions",
        methodology="how we measure unemployment",
        suppression_and_disclosure="Suppression and disclosure",
        data_sources=[data_source],
        measure__slug="test-measure-page-slug",
    )

    resp = test_app_client.get(
        url_for(
            "static_site.measure_version_markdown",
            topic_slug=measure_version.measure.subtopic.topic.slug,
            subtopic_slug=measure_version.measure.subtopic.slug,
            measure_slug=measure_version.measure.slug,
            version=measure_version.version,
        ))

    assert resp.status_code == 200
    page = BeautifulSoup(resp.data.decode("utf-8"), "html.parser")

    assert page.h1.text.strip() == "Test Measure Page"
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-publisher_id"
        }).text,
        "Source data published by Department for Work and Pensions",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "area_covered"
        }).text, "Areas covered England")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "lowest_level_of_geography_id"
        }).text, "Geographic breakdown UK")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "time_covered"
        }).text, "Time period covered 4 months")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "need_to_know"
        }).text, "Things you need to know Need to know this")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "measure_summary"
        }).text, "What the data measures Unemployment measure summary")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "ethnicity_definition_summary"
        }).text,
        "The ethnic categories used in this data This is a summary of ethnicity definitions",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "methodology"
        }).text, "Methodology how we measure unemployment")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "suppression_and_disclosure"
        }).text,
        "Suppression rules and disclosure control (optional) Suppression and disclosure",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-source-url"
        }).text, "Link to data source http://dwp.gov.uk")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-title"
        }).text, "Title of data source DWP Stats")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-type_of_data"
        }).text, "Type of data Survey data")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-type_of_statistic_id"
        }).text, "Type of statistic National")
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-publisher_id"
        }).text,
        "Source data published by Department for Work and Pensions",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-publication_date"
        }).text,
        "Source data publication date 15th May 2017",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div",
                  attrs={
                      "id": "data-source-1-note_on_corrections_or_updates"
                  }).text,
        "Corrections or updates (optional) Note on corrections or updates",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-frequency_of_release_id"
        }).text,
        "How often is the source data published? Quarterly",
    )
    assert_strings_match_ignoring_whitespace(
        page.find("div", attrs={
            "id": "data-source-1-purpose"
        }).text, "Purpose of data source There is no purpose")