<s> import mock <EOL> from six . moves import http_client <EOL> from ironicclient . common . apiclient import exceptions <EOL> from ironicclient import exc <EOL> from ironicclient . tests . unit import utils as test_utils <EOL> @ mock . patch . object ( exceptions , '<STR_LIT>' ) <EOL> class ExcTest ( test_utils . BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ExcTest , self ) . setUp ( ) <EOL> self . message = '<STR_LIT>' <EOL> self . traceback = '<STR_LIT>' <EOL> self . method = '<STR_LIT>' <EOL> self . url = '<STR_LIT>' <EOL> self . expected_json = { '<STR_LIT:error>' : { '<STR_LIT:message>' : self . message , <EOL> '<STR_LIT>' : self . traceback } } <EOL> def test_from_response ( self , mock_apiclient ) : <EOL> fake_response = mock . Mock ( status_code = http_client . BAD_REQUEST ) <EOL> exc . from_response ( fake_response , message = self . message , <EOL> traceback = self . traceback , method = self . method , <EOL> url = self . url ) <EOL> self . assertEqual ( http_client . BAD_REQUEST , fake_response . status_code ) <EOL> self . assertEqual ( self . expected_json , fake_response . json ( ) ) <EOL> mock_apiclient . assert_called_once_with ( <EOL> fake_response , method = self . method , url = self . url ) <EOL> def test_from_response_status ( self , mock_apiclient ) : <EOL> fake_response = mock . Mock ( status = http_client . BAD_REQUEST ) <EOL> fake_response . getheader . return_value = '<STR_LIT>' <EOL> delattr ( fake_response , '<STR_LIT>' ) <EOL> exc . from_response ( fake_response , message = self . message , <EOL> traceback = self . traceback , method = self . method , <EOL> url = self . url ) <EOL> expected_header = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> self . assertEqual ( expected_header , fake_response . headers ) <EOL> self . assertEqual ( http_client . BAD_REQUEST , fake_response . status_code ) <EOL> self . assertEqual ( self . expected_json , fake_response . json ( ) ) <EOL> mock_apiclient . assert_called_once_with ( <EOL> fake_response , method = self . method , url = self . url ) </s>
