示例#1
0
 def test_default(self, mock_request):
     """Test default is returned (and schema is applied to it)."""
     mock_request.json = None
     mock_handler = mock.Mock()
     route = rest.body(default='100', schema=int)(mock_handler)
     route()
     mock_handler.assert_called_once_with(100)
示例#2
0
 def test_schema_fail(self, mock_request):
     """Test schema is enforced."""
     mock_request.json = 'ALPHA'
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()
示例#3
0
 def test_decoration(self):
     """Test decorated function is called."""
     mock_handler = mock.Mock(return_value='X')
     decorated = rest.body()(mock_handler)
     self.assertTrue(callable(decorated))
     self.assertEqual(decorated('arg', kwarg=2), 'X')
     mock_handler.assert_called_once_with(None, 'arg', kwarg=2)
示例#4
0
文件: test_rest.py 项目: gondoi/simpl
 def test_invalid_data(self, mock_request):
     """Test invalid data is handled gracefully."""
     type(mock_request).json = mock.PropertyMock(side_effect=ValueError)
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()
示例#5
0
 def test_schema_fail(self, mock_request):
     """Test schema is enforced."""
     mock_request.json = 'ALPHA'
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()
示例#6
0
 def test_default(self, mock_request):
     """Test default is returned (and schema is applied to it)."""
     mock_request.json = None
     mock_handler = mock.Mock()
     route = rest.body(default='100', schema=int)(mock_handler)
     route()
     mock_handler.assert_called_once_with(100)
示例#7
0
 def test_decoration(self):
     """Test decorated function is called."""
     mock_handler = mock.Mock(return_value='X')
     decorated = rest.body()(mock_handler)
     self.assertTrue(callable(decorated))
     self.assertEqual(decorated('arg', kwarg=2), 'X')
     mock_handler.assert_called_once_with(None, 'arg', kwarg=2)
示例#8
0
 def test_invalid_data(self, mock_request):
     """Test invalid data is handled gracefully."""
     type(mock_request).json = mock.PropertyMock(side_effect=ValueError)
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()
示例#9
0
 def test_required(self, mock_request):
     """Test required is enforced."""
     mock_request.json = None
     mock_handler = mock.Mock()
     route = rest.body(required=True)(mock_handler)
     with self.assertRaises(bottle.HTTPError) as context:
         route()
     self.assertEqual(context.exception.body, 'Call body cannot be empty')
示例#10
0
 def test_schema(self, mock_request):
     """Test schema callable is called."""
     data = "100"
     mock_request.json = data
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     route()
     mock_handler.assert_called_once_with(int(data))
示例#11
0
文件: test_rest.py 项目: gondoi/simpl
 def test_invalid_encoding(self, mock_request):
     """Test invalid encoding is handled gracefully."""
     type(mock_request).json = mock.PropertyMock(
         side_effect=UnicodeDecodeError('ascii', b'', 0, 1, 'bad'))
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()
示例#12
0
 def test_required(self, mock_request):
     """Test required is enforced."""
     mock_request.json = None
     mock_handler = mock.Mock()
     route = rest.body(required=True)(mock_handler)
     with self.assertRaises(bottle.HTTPError) as context:
         route()
     self.assertEqual(context.exception.body, 'Call body cannot be empty')
示例#13
0
 def test_schema(self, mock_request):
     """Test schema callable is called."""
     data = "100"
     mock_request.json = data
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     route()
     mock_handler.assert_called_once_with(int(data))
示例#14
0
 def test_invalid_encoding(self, mock_request):
     """Test invalid encoding is handled gracefully."""
     type(mock_request).json = mock.PropertyMock(
         side_effect=UnicodeDecodeError('ascii', b'', 0, 1, 'bad'))
     mock_handler = mock.Mock()
     route = rest.body(schema=int)(mock_handler)
     with self.assertRaises(bottle.HTTPError):
         route()