def test_get_json_data(self, mock_test, mock_jsonify): """Try to get json data.""" from mod_test.controllers import get_json_data result = get_json_data(1) mock_test.query.filter.assert_called_once_with(mock_test.id == 1) mock_jsonify.assert_called_once()
def test_get_json_data_no_test(self, mock_test): """Try to get json data when Test not present.""" from mod_test.controllers import get_json_data mock_test.query.filter.return_value.first.return_value = None expected = b'{"error":"Test not found","status":"failure"}\n' result = get_json_data(1) self.assertEqual(result.data, expected) mock_test.query.filter.assert_called_once_with(mock_test.id == 1)