コード例 #1
0
def tb(arxiv_id: str) -> Response:
    """Get trackbacks associated with an article."""
    response, code, headers = tb_page.get_tb_page(arxiv_id)

    if code == status.HTTP_200_OK:
        return render_template('tb/tb.html', **response), code, headers  # type: ignore
    elif code == status.HTTP_301_MOVED_PERMANENTLY:
        return redirect(headers['Location'], code=code)  # type: ignore
    raise InternalServerError('Unexpected error')
コード例 #2
0
 def test_good_id_with_trackbacks(self, mock_get_paper_trackback_pings, mock_metadata) -> None:
     """Test requests with good arXiv identifiers known to the corpus."""
     mock_get_paper_trackback_pings.return_value = list()
     mock_metadata.get_abs.return_value = {}
     response_data, code, _ = tb_page.get_tb_page(arxiv_id='1901.99999')
     self.assertEqual(code, status.HTTP_200_OK, 'Response should be OK.')
     for key in ('arxiv_identifier', 'trackback_pings'):
         self.assertIn(key, response_data,
                       f"Response data should include '{key}'")
     for key in ('abs_meta', 'author_links'):
         self.assertNotIn(key, response_data,
                          f"Response data should not include '{key}'")
コード例 #3
0
 def test_bad_or_unknown_id(self) -> None:
     """Test requests with bad arXiv identifiers."""
     with self.assertRaises(TrackbackNotFound):
         for bad_or_unknown_id in ('foo', '1901.99999'):
             tb_page.get_tb_page(arxiv_id=bad_or_unknown_id)