예제 #1
0
파일: test_rest.py 프로젝트: griffinb/simpl
 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
파일: test_rest.py 프로젝트: griffinb/simpl
 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
파일: test_rest.py 프로젝트: griffinb/simpl
 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
파일: test_rest.py 프로젝트: ryandub/simpl
 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
파일: test_rest.py 프로젝트: ryandub/simpl
 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
파일: test_rest.py 프로젝트: ryandub/simpl
 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
파일: test_rest.py 프로젝트: griffinb/simpl
 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
파일: test_rest.py 프로젝트: griffinb/simpl
 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
파일: test_rest.py 프로젝트: ryandub/simpl
 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
파일: test_rest.py 프로젝트: ryandub/simpl
 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()