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")
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')
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')
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)
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)
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)
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
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")
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')
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
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=''))