Esempio n. 1
0
 def test_simple_json_endpoint_get_ioerror(self, flat_file_mock):
     """ Test a GET scenario where an IO error occurs """
     flat_file_mock.load.side_effect = IOError()
     with app.test_request_context(method='GET'):
         rv = common.simple_json_endpoint('---some--path--')
         self.assertEqual(rv[1], 500)
         self.assertEqual(len(flat_file_mock.method_calls), 1)
Esempio n. 2
0
 def test_simple_json_endpoint_post_ioerror(self, flat_file_mock, from_json_mock):
     """ Test a POST scenario where an IO error occurs """
     m = mock.Mock(spec=common.SimpleContentForm)
     m.data = {'content': 'some-content'}
     from_json_mock.return_value = m
     flat_file_mock.return_value.save.side_effect = IOError()
     with app.test_request_context(method='POST'):
         rv = common.simple_json_endpoint('---some--path--')
         self.assertEqual(rv[1], 500)
         self.assertEqual(len(flat_file_mock.method_calls), 0)
         self.assertEqual(len(flat_file_mock.mock_calls), 2)
Esempio n. 3
0
 def test_simple_json_endpoint_post_invalid_form(self, flat_file_mock, from_json_mock):
     """ Test a POST scenario where the submitted payload is invalid """
     m = mock.Mock(spec=common.SimpleContentForm)
     m.data = {'content': 'some-content'}
     m.validate = mock.Mock(return_value=False)
     from_json_mock.return_value = m
     with app.test_request_context(method='POST'):
         rv = common.simple_json_endpoint('---some--path--')
         self.assertEqual(rv[1], 403)
         self.assertEqual(len(flat_file_mock.method_calls), 0)
         self.assertEqual(len(flat_file_mock.mock_calls), 0)
Esempio n. 4
0
 def test_simple_json_endpoint_post_normal(self, flat_file_mock, from_json_mock):
     """ Test a POST scenario where everything goes well """
     m = mock.Mock(spec=common.SimpleContentForm)
     m.data = {'content': 'some-content'}
     from_json_mock.return_value = m
     with app.test_request_context(method='POST'):
         rv = common.simple_json_endpoint('---some--path--')
         self.assertEqual(json.loads(rv.data), {'status': 'success', 'form': m.data})
         flat_file_mock.return_value.save.assert_has_calls([mock.call('---some--path--')])
         self.assertEqual(len(flat_file_mock.method_calls), 0)
         self.assertEqual(len(flat_file_mock.return_value.method_calls), 1)
         self.assertEqual(len(flat_file_mock.mock_calls), 2)
         self.assertEqual(m.validate.call_count, 1)
Esempio n. 5
0
def post_template_json():
    pth = os.path.join(current_app.config['POSTS_TEMPLATE_DIR'], 'post.html')
    return simple_json_endpoint(pth)
Esempio n. 6
0
def style_json():
    pth = os.path.join(current_app.root_path, 'static', 'css', 'style.css')
    return simple_json_endpoint(pth)
Esempio n. 7
0
def template_json():
    pth = os.path.join(current_app.config['TEMPLATE_DIR'], 'base.html')
    return simple_json_endpoint(pth)
Esempio n. 8
0
 def test_simple_json_endpoint_get_normal(self, load_mock):
     """ Test a GET scenario where everything goes well """
     load_mock.return_value = common.FlatFile('--file-contents--')
     with app.test_request_context(method='GET'):
         rv = common.simple_json_endpoint('---some--path--')
         self.assertEqual({'content': '--file-contents--'}, json.loads(rv.data))