def test_resolve_with_doi(self, mock_get):
     """When DOI is available, returns a redirect to dx.doi.org."""
     data = {
         'identifiers': [{
             'identifier_type': 'isbn',
             'identifier': '9999999999999'
         }],
         'doi':
         '10.12345/5444',
         'title':
         'Camelot',
         'year':
         1999,
         'source':
         'Journal of Bardistry',
         'authors': [{
             'forename': 'Sir',
             'surname': 'Robin'
         }]
     }
     mock_get.return_value = (data, 200, {})
     content, status_code, _ = extracted_references.resolve(
         '5432.6789', 'asdf1234')
     self.assertEqual(status_code, status.HTTP_303_SEE_OTHER)
     self.assertTrue(content.get('url').startswith('https://dx.doi.org/'))
예제 #2
0
def resolve_reference(doc_id: str, ref_id: str) -> Union[tuple, Response]:
    """
    Forward a user to a resource for a specific reference.

    Parameters
    ----------
    doc_id : str
    ref_id : str

    Returns
    -------
    :class:`flask.Response`
        JSON response.
    int
        HTTP status code. See :mod:`references.status` for details.
    """
    content, status_code, _ = extr.resolve(doc_id, ref_id)
    if status_code != status.HTTP_303_SEE_OTHER:
        response: Response = jsonify(content, status_code=status_code)
    else:
        response = redirect(content.get('url'), code=status_code)
    return response
 def test_resolve_with_meta(self, mock_get):
     """If no identifier is available, redirects to Google Scholar."""
     data = {
         'title': 'Camelot',
         'year': 1999,
         'source': 'Journal of Bardistry',
         'authors': [{
             'forename': 'Sir',
             'surname': 'Robin'
         }]
     }
     mock_get.return_value = (data, 200, {})
     content, status_code, _ = extracted_references.resolve(
         '5432.6789', 'asdf1234')
     url = parse.urlparse(content.get('url'))
     self.assertEqual(status_code, status.HTTP_303_SEE_OTHER)
     self.assertEqual(url.netloc, 'scholar.google.com')
     self.assertEqual(url.path, '/scholar')
     query = parse.parse_qs(url.query)
     self.assertEqual(query['as_q'], ['Camelot'])
     self.assertEqual(query['as_sauthors'], ['"Sir Robin"'])
     self.assertEqual(query['as_yhi'], ['1999'])
     self.assertEqual(query['as_ylo'], ['1999'])
     self.assertEqual(query['as_publication'], ['Journal of Bardistry'])