Exemple #1
0
    def test_document_metas_from_data_with_multiple_metadata_claims(self):
        """
        It should create one DocumentMeta for each metadata claim.

        If document_data contains multiple metadata claims it should init one
        DocumentMeta for each claim.

        """
        claimant = "http://example/claimant"
        document_data = {
            "title": "the title",
            "description": "the description",
            "site_title": "the site title",
        }

        document_metas = document_claims.document_metas_from_data(
            document_data, claimant
        )

        assert len(document_metas) == len(document_data.items())
        for key, value in document_data.items():
            assert {
                "type": key,
                "value": [value],
                "claimant": claimant,
            } in document_metas
Exemple #2
0
    def test_document_metas_from_data_ignores_links_list(self):
        """It should ignore the "link" list in the document_data."""
        document_data = {"link": [{"href": "http://example.com/link"}]}

        document_metas = document_claims.document_metas_from_data(
            document_data, "http://example/claimant"
        )

        assert document_metas == []
Exemple #3
0
    def test_document_metas_from_data_ignores_whitespace_only_titles(self):
        """It should ignore whitespace-only document titles."""
        for title in (" ", [" ", " "], "\n\n  \n"):
            document_data = {"title": title}

            document_metas = document_claims.document_metas_from_data(
                document_data, "http://example/claimant"
            )

            assert document_metas == []
Exemple #4
0
    def test_document_metas_from_data_ignores_empty_string_titles(self):
        """It should ignore empty document titles."""
        for title in ("", ["", ""]):
            document_data = {"title": title}

            document_metas = document_claims.document_metas_from_data(
                document_data, "http://example/claimant"
            )

            assert document_metas == []
Exemple #5
0
    def test_document_metas_from_data_ignores_null_titles(self):
        """It should ignore null document titles."""
        for title in (None, [None, None]):
            document_data = {"title": title}

            document_metas = document_claims.document_metas_from_data(
                document_data, "http://example/claimant"
            )

            assert document_metas == []
Exemple #6
0
    def test_document_metas_from_data(self, input_, output):
        claimant = "http://example.com/claimant/"

        document_metas = document_claims.document_metas_from_data(
            document_data=input_, claimant=claimant
        )

        assert document_metas == [
            {"type": output["type"], "value": output["value"], "claimant": claimant}
        ]
Exemple #7
0
    def test_document_metas_from_data_allows_whitespace_only_non_titles(self):
        """Whitespace-only strings are allowed if 'type' isn't 'title'."""
        for value in (" ", [" ", " "], "\n\n  \n"):
            document_data = {"foo": value}

            document_metas = document_claims.document_metas_from_data(
                document_data, "http://example/claimant"
            )

            if not isinstance(value, list):
                # We expect it to turn non-lists into length-1 lists.
                value = [value]

            assert document_metas == [
                {"type": "foo", "value": value, "claimant": "http://example/claimant"}
            ]
Exemple #8
0
    def test_document_metas_from_data_allows_null_non_titles(self):
        """Null values are allowed if 'type' isn't 'title'."""
        for value in (None, [None, None]):
            document_data = {"foo": value}

            document_metas = document_claims.document_metas_from_data(
                document_data, "http://example/claimant"
            )

            if not isinstance(value, list):
                # We expect it to turn non-lists into length-1 lists.
                value = [value]

            assert document_metas == [
                {"type": "foo", "value": value, "claimant": "http://example/claimant"}
            ]
Exemple #9
0
def _document(document, claimant):
    """
    Return document meta and document URI data from the given document dict.

    Transforms the "document" dict that the client posts into a convenient
    format for creating DocumentURI and DocumentMeta objects later.

    """
    document = document or {}
    document_uri_dicts = document_claims.document_uris_from_data(
        copy.deepcopy(document), claimant=claimant)
    document_meta_dicts = document_claims.document_metas_from_data(
        copy.deepcopy(document), claimant=claimant)
    return {
        "document_uri_dicts": document_uri_dicts,
        "document_meta_dicts": document_meta_dicts,
    }