Пример #1
0
    def test_it_ignores_highwire_pdf_links(self):
        pdf_url = 'http://example.com/example.pdf'
        link_dicts = [{'href': pdf_url, 'type': 'application/pdf'}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant='http://localhost:5000/docs/help',
        )

        assert document_uris == []
Пример #2
0
    def test_it_uses_link_types_as_document_uri_content_types(self):
        """
        Link types get converted to document URI content_types.

        The value of the 'type' key in link dicts ends up as the value of the
        'content_type' key in the returned document URI dicts.

        """
        link_dicts = [{'href': 'http://example.com/example.html',
                       'type': 'text/html'}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant='http://example.com/example.html',
        )

        assert one(
            [d for d in document_uris if d.get('content_type') == 'text/html'])
Пример #3
0
    def test_it_returns_rel_alternate_document_uris_for_rel_alternate_links(
            self):
        alternate_url = 'http://example.com/alternate'
        link_dicts = [{'href': alternate_url, 'rel': 'alternate'}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant='http://localhost:5000/docs/help',
        )

        alternate_document_uri = one(
            [d for d in document_uris if d['type'] == 'rel-alternate'])
        assert alternate_document_uri == {
            'type': 'rel-alternate',
            'claimant': 'http://localhost:5000/docs/help',
            'content_type': '',
            'uri': alternate_url,
        }
Пример #4
0
    def test_it_ignores_doi_links(self):
        """
        Links containing only an href that starts with doi should be ignored.

        If document.link contains a link dict with just an "href" and no other
        keys, and the value of the "href" key begins with "doi:", then the link
        dict should be ignored and not produce a document URI dict in the
        output.

        This is because document URI dicts for doi: URIs are generate
        separately from other metadata in the document dict outside of the
        "link" list.

        """
        link_dicts = [{'href': 'doi:10.3389/fenvs.2014.00003'}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts, claimant='http://localhost:5000/docs/help')

        assert document_uris == []
Пример #5
0
    def test_it_ignores_href_links_that_match_the_claimant_uri(self):
        """
        Links containing only the claimant URI should be ignored.

        If document.link contains a link dict with just an "href" and no other
        keys, and the value of the "href" key is the same as the claimant URI,
        then this link dict should be ignored and not produce an additional
        document URI dict in the output (since the document URI that it would
        generate would be the same as the "self-claim" claimant URI one that is
        always generated anyway).

        """
        claimant = 'http://localhost:5000/docs/help'
        link_dicts = [{'href': claimant}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant,
        )

        assert document_uris == []
Пример #6
0
    def test_it_ignores_doi_links(self):
        """
        Links containing only an href that starts with doi should be ignored.

        If document.link contains a link dict with just an "href" and no other
        keys, and the value of the "href" key begins with "doi:", then the link
        dict should be ignored and not produce a document URI dict in the
        output.

        This is because document URI dicts for doi: URIs are generate
        separately from other metadata in the document dict outside of the
        "link" list.

        """
        link_dicts = [{'href': 'doi:10.3389/fenvs.2014.00003'}]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant='http://localhost:5000/docs/help'
        )

        assert document_uris == []
Пример #7
0
    def test_it_returns_multiple_document_URI_dicts(self):
        """If there are multiple claims it should return multiple dicts."""
        link_dicts = [
            {
                'href': 'http://example.com/example.html',
                'type': 'text/html'
            },
            {
                'href': 'http://example.com/alternate.html',
                'rel': 'alternate'
            },
            {
                'href': 'http://example.com/example2.html',
                'type': 'text/html'
            },
        ]

        document_uris = parse_document_claims.document_uris_from_links(
            link_dicts,
            claimant='http://example.com/claimant.html',
        )

        assert len(document_uris) == 3