def test_calling_document_uris_from_dc_when_no_dc(self,
                                                      document_uris_from_dc):
        document_data = {}  # No 'dc' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_dc.assert_called_once_with({}, claimant)
    def test_calling_document_uris_from_highwire_pdf_when_no_highwire(
            self, document_uris_from_highwire_pdf):
        document_data = {}  # No 'highwire' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_highwire_pdf.assert_called_once_with({}, claimant)
    def test_calling_document_uris_from_links_when_no_links(
            self, document_uris_from_links):
        document_data = {}  # No 'link' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_links.assert_called_once_with([], claimant)
Beispiel #4
0
    def test_calling_document_uris_from_dc_when_no_dc(self,
                                                      document_uris_from_dc):
        document_data = {}  # No 'dc' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_dc.assert_called_once_with(
            {}, claimant)
Beispiel #5
0
    def test_calling_document_uris_from_highwire_pdf_when_no_highwire(
            self,
            document_uris_from_highwire_pdf):
        document_data = {}  # No 'highwire' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_highwire_pdf.assert_called_once_with(
            {}, claimant)
Beispiel #6
0
    def test_calling_document_uris_from_links_when_no_links(
            self,
            document_uris_from_links):
        document_data = {}  # No 'link' key.
        claimant = 'http://localhost:5000/docs/help'

        parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_links.assert_called_once_with(
            [], claimant)
    def test_it_gets_documents_uris_from_highwire_pdf(
            self,
            document_uris_from_highwire_pdf):
        document_data = {
            'highwire': {
                'pdf': [
                    'pdf_1',
                    'pdf_2',
                    'pdf_3',
                ]
            }
        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_highwire_pdf.return_value = [
            mock.Mock(), mock.Mock(), mock.Mock()]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_highwire_pdf.assert_called_once_with(
            document_data['highwire'], claimant)
        for document_uri in document_uris_from_highwire_pdf.return_value:
            assert document_uri in document_uris
    def test_it_gets_documents_uris_from_highwire_doi(
            self,
            document_uris_from_highwire_doi):
        document_data = {
            'highwire': {
                'doi': [
                    'doi_1',
                    'doi_2',
                    'doi_3',
                ]
            }
        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_highwire_doi.return_value = [
            {'uri': 'uri_1'}, {'uri': 'uri_2'}, {'uri': 'uri_3'}]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_highwire_doi.assert_called_once_with(
            document_data['highwire'], claimant)
        for document_uri in document_uris_from_highwire_doi.return_value:
            assert document_uri in document_uris
    def test_it_gets_documents_uris_from_highwire_pdf(
            self, document_uris_from_highwire_pdf):
        document_data = {
            'highwire': {
                'pdf': [
                    'pdf_1',
                    'pdf_2',
                    'pdf_3',
                ]
            }
        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_highwire_pdf.return_value = [
            mock.Mock(), mock.Mock(), mock.Mock()
        ]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_highwire_pdf.assert_called_once_with(
            document_data['highwire'], claimant)
        for document_uri in document_uris_from_highwire_pdf.return_value:
            assert document_uri in document_uris
    def test_it_gets_self_claim_document_uris(self, document_uri_self_claim):
        claimant = 'http://example.com/claimant'

        document_uris = parse_document_claims.document_uris_from_data(
            {}, claimant)

        document_uri_self_claim.assert_called_once_with(claimant)
        assert document_uri_self_claim.return_value in document_uris
    def test_it_ignores_whitespace_only_self_claim_uris(
            self, document_uri_self_claim):
        for uri in (' ', '\n ', '\r\n', ' \t'):
            document_uri_self_claim.return_value = {'uri': uri}

            document_uris = parse_document_claims.document_uris_from_data(
                {}, 'http://example.com/claimant')

            assert document_uris == []
    def test_it_strips_whitespace_from_self_claim_uris(
            self, document_uris_from_links, document_uri_self_claim):
        for uri in (' self_claim', 'self_claim ', ' self_claim '):
            document_uris_from_links.return_value = []
            document_uri_self_claim.return_value = {'uri': uri}

            document_uris = parse_document_claims.document_uris_from_data(
                {}, 'http://example.com/claimant')

            assert document_uris == [{'uri': uri.strip()}]
Beispiel #13
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 = parse_document_claims.document_uris_from_data(copy.deepcopy(document), claimant=claimant)
    document_meta_dicts = parse_document_claims.document_metas_from_data(copy.deepcopy(document), claimant=claimant)
    return {"document_uri_dicts": document_uri_dicts, "document_meta_dicts": document_meta_dicts}
    def test_it_ignores_whitespace_only_uris(self,
                                             document_uris_from_links,
                                             document_uris_from_highwire_pdf,
                                             document_uris_from_highwire_doi,
                                             document_uris_from_dc,
                                             document_uri_self_claim):
        uris = [' ', '\n ', '\r\n', ' \t']
        document_uris_from_links.return_value = [{'uri': u} for u in uris]
        document_uris_from_highwire_pdf.return_value = [{'uri': u} for u in uris]
        document_uris_from_highwire_doi.return_value = [{'uri': u} for u in uris]
        document_uris_from_dc.return_value = [{'uri': u} for u in uris]

        document_uris = parse_document_claims.document_uris_from_data(
            {}, 'http://example.com/claimant')

        assert document_uris == [document_uri_self_claim.return_value]
    def test_it_ignores_empty_string_uris(self,
                                          document_uris_from_links,
                                          document_uris_from_highwire_pdf,
                                          document_uris_from_highwire_doi,
                                          document_uris_from_dc,
                                          document_uri_self_claim):
        document_uris_from_links.return_value = [{'uri': ''}]
        document_uris_from_highwire_pdf.return_value = [{'uri': ''}]
        document_uris_from_highwire_doi.return_value = [{'uri': ''}]
        document_uris_from_dc.return_value = [{'uri': ''}]
        document_uri_self_claim.return_value = {'uri': ''}

        document_uris = parse_document_claims.document_uris_from_data(
            {}, 'http://example.com/claimant')

        assert document_uris == []
    def test_it_strips_whitespace_from_uris(self,
                                            document_uris_from_links,
                                            document_uris_from_highwire_pdf,
                                            document_uris_from_highwire_doi,
                                            document_uris_from_dc,
                                            document_uri_self_claim,
                                            matchers):
        document_uris_from_links.return_value = [
            {'uri': ' from_link_1'},
            {'uri': 'from_link_2 '},
            {'uri': ' from_link_3 '}
        ]
        document_uris_from_highwire_pdf.return_value = [
            {'uri': ' highwire_1'},
            {'uri': 'highwire_2 '},
            {'uri': ' highwire_3 '}
        ]
        document_uris_from_highwire_doi.return_value = [
            {'uri': ' doi_1'},
            {'uri': 'doi_2 '},
            {'uri': ' doi_3 '}
        ]
        document_uris_from_dc.return_value = [
            {'uri': ' dc_1'},
            {'uri': 'dc_2 '},
            {'uri': ' dc_3 '}
        ]

        document_uris = parse_document_claims.document_uris_from_data(
            {}, 'http://example.com/claimant')

        assert document_uris == matchers.unordered_list([
            {'uri': 'from_link_1'},
            {'uri': 'from_link_2'},
            {'uri': 'from_link_3'},
            {'uri': 'highwire_1'},
            {'uri': 'highwire_2'},
            {'uri': 'highwire_3'},
            {'uri': 'doi_1'},
            {'uri': 'doi_2'},
            {'uri': 'doi_3'},
            {'uri': 'dc_1'},
            {'uri': 'dc_2'},
            {'uri': 'dc_3'},
            document_uri_self_claim.return_value
        ])
Beispiel #17
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 = parse_document_claims.document_uris_from_data(
        copy.deepcopy(document), claimant=claimant)
    document_meta_dicts = parse_document_claims.document_metas_from_data(
        copy.deepcopy(document), claimant=claimant)
    return {
        'document_uri_dicts': document_uri_dicts,
        'document_meta_dicts': document_meta_dicts
    }
    def test_it_gets_document_uris_from_links(self, document_uris_from_links):
        document_data = {
            'link': [
                # In production these would be link dicts not strings.
                'link_dict_1',
                'link_dict_2',
                'link_dict_3',
            ]

        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_links.return_value = [
            {'uri': 'uri_1'}, {'uri': 'uri_2'}, {'uri': 'uri_3'}]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_links.assert_called_once_with(
            document_data['link'], claimant)
        for document_uri in document_uris_from_links.return_value:
            assert document_uri in document_uris
    def test_it_gets_documents_uris_from_dc(self,
                                            document_uris_from_dc):
        document_data = {
            'dc': {
                'identifier': [
                    'doi_1',
                    'doi_2',
                    'doi_3',
                ]
            }
        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_dc.return_value = [
            mock.Mock(), mock.Mock(), mock.Mock()]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_dc.assert_called_once_with(
            document_data['dc'], claimant)
        for document_uri in document_uris_from_dc.return_value:
            assert document_uri in document_uris
    def test_it_gets_documents_uris_from_dc(self, document_uris_from_dc):
        document_data = {
            'dc': {
                'identifier': [
                    'doi_1',
                    'doi_2',
                    'doi_3',
                ]
            }
        }
        claimant = 'http://localhost:5000/docs/help'
        document_uris_from_dc.return_value = [
            mock.Mock(), mock.Mock(), mock.Mock()
        ]

        document_uris = parse_document_claims.document_uris_from_data(
            document_data=document_data,
            claimant=claimant,
        )

        document_uris_from_dc.assert_called_once_with(document_data['dc'],
                                                      claimant)
        for document_uri in document_uris_from_dc.return_value:
            assert document_uri in document_uris