示例#1
0
 def test_missing_parameters(self) -> None:
     """Test request with missing parameters."""
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("", "", "")
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("1801.00001", "", "")
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("1801.00001", "next", "")
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("1801.00001", "", "cs")
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("", "prev", "cs")
示例#2
0
    def test_missing_parameters(self) -> None:
        """Test request with missing parameters."""

        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('', '', '')
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('1801.00001', '', '')
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('1801.00001', 'next', '')
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('1801.00001', '', 'cs')
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('', 'prev', 'cs')
示例#3
0
文件: ui.py 项目: oacore/arxiv-browse
def previous_next() -> Union[str, Response]:
    """Previous/Next navigation used on /abs page."""
    if not request.args:
        raise BadRequest
    response, code, headers = prevnext.get_prevnext(request.args)
    if code == status.HTTP_301_MOVED_PERMANENTLY:
        return redirect(headers['Location'], code=code)  # type: ignore
    raise InternalServerError('Unexpected error')
示例#4
0
    def test_missing_parameters(self) -> None:
        """Test request with missing parameters."""
        request_data = MultiDict()
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({'id': '1801.00001'})
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({'id': '1801.00001', 'function': 'next'})
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({'id': '1801.00001', 'context': 'cs'})
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({'function': 'prev', 'context': 'cs'})
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)
示例#5
0
    def test_good_parameters(self, mock_url_for,
                             mock_get_sequential_id) -> None:  # type: ignore
        """Test parameters with good values."""
        request_data = MultiDict({
            'id': '1801.00001',
            'function': 'next',
            'context': 'all'
        })
        mock_get_sequential_id.return_value = '1801.00002'
        _, status, headers = prevnext.get_prevnext(request_data)
        self.assertEqual(status, 301)

        request_data = MultiDict({
            'id': '1801.00002',
            'function': 'prev',
            'context': 'cs.AI'
        })
        mock_get_sequential_id.return_value = '1801.00001'
        _, status, headers = prevnext.get_prevnext(request_data)
        self.assertEqual(status, 301)

        request_data = MultiDict({
            'id': '1701.00002',
            'function': 'next',
            'context': 'physics.gen-ph'
        })
        mock_get_sequential_id.return_value = None
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)
        mock_get_sequential_id.return_value = ''
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)
示例#6
0
    def test_bad_parameters(self) -> None:
        """Test parameters with bad values."""
        request_data = MultiDict({
            'id': 'foo',  # invalid
            'function': 'prev',  # valid
            'context': 'cs.AI'  # valid
        })
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({
            'id': 'cs/0001001',  # valid
            'function': 'bar',  # invalid
            'context': 'cs'  # valid
        })
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)

        request_data = MultiDict({
            'id': 'cs/0001001',  # valid
            'function': 'next',  # valid
            'context': 'baz'  # invalid
        })
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(request_data)
示例#7
0
 def test_bad_parameters(self) -> None:
     """Test parameters with bad values."""
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext("foo", "prev",
                               "cs.AI")  # invalid  # valid  # valid
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext(
             "cs/0001001",
             "bar",
             "cs"  # valid  # invalid
         )  # valid
     with self.assertRaises(BadRequest):
         prevnext.get_prevnext(
             "cs/0001001",
             "next",
             "baz"  # valid  # valid
         )  # invalid
示例#8
0
    def test_good_parameters(self, mock_url_for,
                             mock_get_sequential_id) -> None:  # type: ignore
        """Test parameters with good values."""
        mock_get_sequential_id.return_value = "1801.00002"
        _, status, headers = prevnext.get_prevnext("1801.00001", "next", "all")
        self.assertEqual(status, 301)

        mock_get_sequential_id.return_value = "1801.00001"
        _, status, headers = prevnext.get_prevnext("1801.00002", "prev",
                                                   "cs.AI")
        self.assertEqual(status, 301)

        mock_get_sequential_id.return_value = None
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext("1701.00002", "next", "physics.gen-ph")
        mock_get_sequential_id.return_value = ""
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext("1701.00002", "next", "physics.gen-ph")
示例#9
0
    def test_good_parameters(self, mock_url_for,
                             mock_get_sequential_id) -> None:  # type: ignore
        """Test parameters with good values."""
        mock_get_sequential_id.return_value = '1801.00002'
        _, status, headers = prevnext.get_prevnext('1801.00001', 'next', 'all')
        self.assertEqual(status, 301)

        mock_get_sequential_id.return_value = '1801.00001'
        _, status, headers = prevnext.get_prevnext('1801.00002', 'prev',
                                                   'cs.AI')
        self.assertEqual(status, 301)

        mock_get_sequential_id.return_value = None
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('1701.00002', 'next', 'physics.gen-ph')
        mock_get_sequential_id.return_value = ''
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext('1701.00002', 'next', 'physics.gen-ph')
示例#10
0
    def test_bad_parameters(self) -> None:
        """Test parameters with bad values."""

        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(
                'foo',  # invalid
                'prev',  # valid
                'cs.AI')  # valid
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(
                'cs/0001001',  # valid
                'bar',  # invalid
                'cs')  # valid
        with self.assertRaises(BadRequest):
            prevnext.get_prevnext(
                'cs/0001001',  # valid
                'next',  # valid
                'baz')  # invalid
示例#11
0
def previous_next() -> Tuple[Dict[str, Any], int, Dict[str, Any]]:
    """Previous/Next navigation used on /abs page."""
    return prevnext.get_prevnext(request.args.get('id', default=''),
                                 request.args.get('function', default=''),
                                 request.args.get('context', default=''))