openlp/tests/functional/openlp_core_api_http/test_error.py

60 lines
2.7 KiB
Python
Raw Normal View History

2016-06-11 18:50:39 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2017-03-04 19:17:59 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2016-06-11 18:50:39 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
Functional tests to test the API Error Class.
"""
from unittest import TestCase
2016-06-16 20:50:01 +00:00
from openlp.core.api.http.errors import NotFound, ServerError
2016-06-11 18:50:39 +00:00
class TestApiError(TestCase):
"""
A test suite to test out the Error in the API code
"""
def test_not_found(self):
"""
Test the Not Found error displays the correct information
"""
2016-06-11 21:13:48 +00:00
# GIVEN:
# WHEN: I raise an exception
2016-06-11 18:50:39 +00:00
with self.assertRaises(Exception) as context:
raise NotFound()
2016-06-11 21:13:48 +00:00
# THEN: we get an error and a status
2016-06-11 18:50:39 +00:00
self.assertEquals('Not Found', context.exception.message, 'A Not Found exception should be thrown')
self.assertEquals(404, context.exception.status, 'A 404 status should be thrown')
def test_server_error(self):
"""
Test the server error displays the correct information
"""
2016-06-11 21:13:48 +00:00
# GIVEN:
# WHEN: I raise an exception
2016-06-11 18:50:39 +00:00
with self.assertRaises(Exception) as context:
raise ServerError()
2016-06-11 21:13:48 +00:00
# THEN: we get an error and a status
2016-06-11 18:50:39 +00:00
self.assertEquals('Server Error', context.exception.message, 'A Not Found exception should be thrown')
2016-06-14 20:56:50 +00:00
self.assertEquals(500, context.exception.status, 'A 500 status should be thrown')