<s> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> import atom . http_core <EOL> import atom . auth <EOL> import atom . client <EOL> import atom . mock_http_core <EOL> class AtomPubClientEchoTest ( unittest . TestCase ) : <EOL> def test_simple_request_with_no_client_defaults ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> self . assert_ ( client . host is None ) <EOL> self . assert_ ( client . auth_token is None ) <EOL> responses = [ client . request ( '<STR_LIT:GET>' , '<STR_LIT>' ) , <EOL> client . request ( http_request = atom . http_core . HttpRequest ( <EOL> uri = atom . http_core . Uri ( '<STR_LIT:http>' , '<STR_LIT>' , path = '<STR_LIT:/>' ) , <EOL> method = '<STR_LIT:GET>' ) ) , <EOL> client . request ( '<STR_LIT:GET>' , <EOL> http_request = atom . http_core . HttpRequest ( <EOL> uri = atom . http_core . Uri ( '<STR_LIT:http>' , '<STR_LIT>' , <EOL> path = '<STR_LIT:/>' ) ) ) ] <EOL> for response in responses : <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:http>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:GET>' ) <EOL> self . assertTrue ( response . getheader ( '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) ) <EOL> def test_auth_request_with_no_client_defaults ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> token = atom . auth . BasicAuth ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = client . request ( '<STR_LIT:POST>' , '<STR_LIT>' , <EOL> auth_token = token ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:POST>' ) <EOL> def test_request_with_client_defaults ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) , <EOL> '<STR_LIT>' , atom . auth . BasicAuth ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assert_ ( client . host == '<STR_LIT>' ) <EOL> self . assert_ ( client . auth_token is not None ) <EOL> self . assert_ ( client . auth_token . basic_cookie == '<STR_LIT>' ) <EOL> response = client . request ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:http>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:GET>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> response = client . request ( '<STR_LIT:GET>' , '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:http>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> response = client . request ( '<STR_LIT:GET>' , '<STR_LIT:/>' , <EOL> http_request = atom . http_core . HttpRequest ( <EOL> uri = atom . http_core . Uri ( port = <NUM_LIT> ) ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> def test_get ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> response = client . get ( '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:GET>' ) <EOL> response = client . Get ( uri = '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:GET>' ) <EOL> def test_modify_request_using_args ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> class RequestModifier ( object ) : <EOL> def modify_request ( self , http_request ) : <EOL> http_request . headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = client . get ( '<STR_LIT>' , <EOL> extra = RequestModifier ( ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:GET>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> def test_post ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> class TestData ( object ) : <EOL> def modify_request ( self , http_request ) : <EOL> http_request . add_body_part ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = client . Post ( uri = '<STR_LIT>' , data = TestData ( ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:POST>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == str ( len ( '<STR_LIT>' ) ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT:Content-Type>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . read ( <NUM_LIT:2> ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . read ( ) == '<STR_LIT>' ) <EOL> response = client . post ( data = TestData ( ) , uri = '<STR_LIT>' ) <EOL> self . assert_ ( response . read ( ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT:Content-Type>' ) == '<STR_LIT>' ) <EOL> response = client . post ( x = TestData ( ) , uri = '<STR_LIT>' ) <EOL> self . assert_ ( response . read ( ) == '<STR_LIT>' ) <EOL> def test_put ( self ) : <EOL> body_text = '<STR_LIT>' <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) ) <EOL> class TestData ( object ) : <EOL> def modify_request ( self , http_request ) : <EOL> http_request . add_body_part ( body_text , '<STR_LIT>' ) <EOL> response = client . put ( '<STR_LIT>' , TestData ( ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT:/>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == str ( len ( body_text ) ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT:Content-Type>' ) == '<STR_LIT>' ) <EOL> response = client . put ( uri = '<STR_LIT>' , data = TestData ( ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT>' ) == str ( len ( body_text ) ) ) <EOL> self . assert_ ( response . getheader ( '<STR_LIT:Content-Type>' ) == '<STR_LIT>' ) <EOL> def test_delete ( self ) : <EOL> client = atom . client . AtomPubClient ( atom . mock_http_core . EchoHttpClient ( ) , <EOL> source = '<STR_LIT>' ) <EOL> response = client . Delete ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . getheader ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( response . getheader ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( response . getheader ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> response = client . delete ( uri = '<STR_LIT>' ) <EOL> self . assertEqual ( response . getheader ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( response . getheader ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertTrue ( <EOL> response . getheader ( '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) ) <EOL> def suite ( ) : <EOL> return unittest . TestSuite ( ( unittest . makeSuite ( AtomPubClientEchoTest , '<STR_LIT:test>' ) , <EOL> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
