<s> import unittest <EOL> from werkzeug . exceptions import Forbidden <EOL> from flask_potion . exceptions import DuplicateKey <EOL> from flask_potion . routes import Route <EOL> from flask_potion import Api , Resource <EOL> from tests import BaseTestCase <EOL> class ErrorMessagesTestCase ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ErrorMessagesTestCase , self ) . setUp ( ) <EOL> self . api = Api ( self . app , prefix = '<STR_LIT>' ) <EOL> class ErrorResource ( Resource ) : <EOL> @ Route . GET <EOL> def forbidden ( self ) : <EOL> raise Forbidden ( ) <EOL> @ Route . GET <EOL> def python_exception ( self ) : <EOL> raise ValueError ( ) <EOL> @ Route . GET <EOL> def duplicate_key ( self ) : <EOL> raise DuplicateKey ( ) <EOL> class Meta : <EOL> name = '<STR_LIT:error>' <EOL> self . api . add_resource ( ErrorResource ) <EOL> def test_werkzeug_exception ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assert403 ( response ) <EOL> self . assertEqual ( { <EOL> "<STR_LIT:message>" : "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:status>" : <NUM_LIT> <EOL> } , response . json ) <EOL> def test_potion_exception ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertStatus ( response , <NUM_LIT> ) <EOL> self . assertEqual ( { <EOL> "<STR_LIT:message>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : <NUM_LIT> <EOL> } , response . json ) <EOL> def test_not_found_exception ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assert404 ( response ) <EOL> self . assertEqual ( { <EOL> "<STR_LIT:message>" : "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:status>" : <NUM_LIT> <EOL> } , response . json ) <EOL> def test_exception_outside_api ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assert404 ( response ) <EOL> @ unittest . SkipTest <EOL> def test_python_exception ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assert500 ( response ) <EOL> self . assertEqual ( { } , response . json ) </s>
