コード例 #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()