<s> import json <EOL> import logging <EOL> import mock <EOL> import fixtures <EOL> import requests <EOL> from rackclient import client <EOL> from rackclient . tests import utils <EOL> class ClientTest ( utils . TestCase ) : <EOL> def test_log_req ( self ) : <EOL> self . logger = self . useFixture ( <EOL> fixtures . FakeLogger ( <EOL> name = client . __name__ , <EOL> format = "<STR_LIT>" , <EOL> level = logging . DEBUG , <EOL> nuke_handlers = True <EOL> ) <EOL> ) <EOL> cs = client . HTTPClient ( '<STR_LIT>' , True ) <EOL> cs . http_log_req ( '<STR_LIT:GET>' , '<STR_LIT>' , { '<STR_LIT>' : { } } ) <EOL> cs . http_log_req ( '<STR_LIT:GET>' , '<STR_LIT>' , { '<STR_LIT>' : { <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } } ) <EOL> data = { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> } } <EOL> cs . http_log_req ( '<STR_LIT:POST>' , '<STR_LIT>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' <EOL> } , <EOL> '<STR_LIT:data>' : json . dumps ( data ) <EOL> } ) <EOL> output = self . logger . output . split ( '<STR_LIT:\n>' ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> self . assertIn ( "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> output ) <EOL> self . assertIn ( "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> output ) <EOL> def test_log_resp ( self ) : <EOL> self . logger = self . useFixture ( <EOL> fixtures . FakeLogger ( <EOL> name = client . __name__ , <EOL> format = "<STR_LIT>" , <EOL> level = logging . DEBUG , <EOL> nuke_handlers = True <EOL> ) <EOL> ) <EOL> cs = client . HTTPClient ( '<STR_LIT>' , True ) <EOL> text = '<STR_LIT>' <EOL> resp = utils . TestResponse ( { '<STR_LIT>' : <NUM_LIT:200> , '<STR_LIT>' : { } , <EOL> '<STR_LIT:text>' : text } ) <EOL> cs . http_log_resp ( resp ) <EOL> output = self . logger . output . split ( '<STR_LIT:\n>' ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> self . assertIn ( '<STR_LIT>' <EOL> '<STR_LIT>' , output ) <EOL> def test_request ( self ) : <EOL> cs = client . HTTPClient ( '<STR_LIT>' , False ) <EOL> data = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> mock_request = mock . Mock ( ) <EOL> mock_request . return_value = requests . Response ( ) <EOL> mock_request . return_value . status_code = <NUM_LIT> <EOL> mock_request . return_value . _content = data <EOL> with mock . patch ( '<STR_LIT>' , mock_request ) : <EOL> resp , body = cs . post ( '<STR_LIT>' , body = data ) <EOL> kwargs = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' <EOL> } , <EOL> '<STR_LIT:data>' : json . dumps ( data ) <EOL> } <EOL> mock_request . assert_called_with ( '<STR_LIT:POST>' , <EOL> '<STR_LIT>' , <EOL> ** kwargs ) <EOL> def test_request_raise_exception ( self ) : <EOL> cs = client . HTTPClient ( '<STR_LIT>' , False ) <EOL> mock_request = mock . Mock ( ) <EOL> mock_request . return_value = requests . Response ( ) <EOL> mock_request . return_value . status_code = <NUM_LIT> <EOL> mock_exec = mock . Mock ( ) <EOL> mock_exec . return_value = Exception ( '<STR_LIT>' ) <EOL> with mock . patch ( '<STR_LIT>' , mock_request ) : <EOL> with mock . patch ( '<STR_LIT>' , <EOL> mock_exec ) : <EOL> self . assertRaises ( Exception , cs . get , '<STR_LIT>' ) </s>
