
    "'                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	r	SSK
Jr  SSKJs  Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  \" S5       " S S\R.                  5      5       rg)'Integration tests for gsutil -D option.    )absolute_import)print_function)division)unicode_literalsN)ApiSelector)	SkipForS3)ObjectToURI)SetBotoConfigForTest)ONE_KIBz%-D output is implementation-specific.c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestDOption#   r   c                     SU-  nU(       a  USU-  -  nXC;   a  gSU-  nU(       a  USU-  -  nXS;  a  U R                  SU< SU< SU< 35        gg)	a3  Asserts that httplib2's debug logger printed out a specified header.

This method is fairly primitive and uses assertIn statements, and thus is
case-sensitive. Values should be normalized (e.g. to lowercase) if
capitalization of the expected characters may vary.

Args:
  name: (str) The header name, e.g. "Content-Length".
  value: (Union[str, None]) The header value, e.g. "4096". If no value is
      expected for the header or the value is unknown, this argument should
      be `None`.
  output: (str) The string in which to search for the specified header.
zheader: %s:z %sNz('%s'z, '%s')zANeither of these two header formats were found in the output:
1) z
2) z
Output string: )fail)selfnamevalueoutputexpectedalt_expecteds         +platform/gsutil/gslib/tests/test_Doption.pyassert_header_in_output#TestDOption.assert_header_in_output'   sh     t#H%%-h T>Li%''l!
ii<1 2 "    c                 :   S GH  nU R                  US9nU R                  5       n[        SS[        [        5      4/5         U R                  SSU[        U5      /SS9n[        S	S
R                  SSU[        U5      /5      -   5        U R                  [        R                  :X  a  U R                  SU5        U R                  SU5        U R                  SU5        U R                  S[        U5      -  U5        SSS5        GM     g! , (       d  f       GM  = f)z:Tests that debug option does not output upload media body.)   a1b2c3d4s	   a1b2c3d4
contentsGSUtilresumable_threshold-DcpTreturn_stderrzcommand line: z
media bodya1b2c3d4)Comparing local vs cloud md5-checksum forztotal_bytes_transferred: %dN)CreateTempFileCreateBucketr   strr   	RunGsUtilsuriprintjointest_apir   JSONassertInassertNotInlen)r   file_contentsfpath
bucket_uristderrs        r   test_minus_D_multipart_upload)TestDOption.test_minus_D_multipart_uploadM   s    6!!=!9e$$&j(,A3w<!P !" #4Z 01   Go$eT*=M)N OOP==K,,,
--f
-V,A6J3c-6HH	# # 6# #s   B:D


D	c           	         SnU R                  USS9nU R                  5       nU R                  SSSU[        U5      /SS9nU R	                  S	U5        U R                  SSS[        X15      U/SS9nU R	                  S	U5        g
)8Test upload and download with a sample perf trace token.bar   foo	file_namer   r"   z--perf-trace-token=123r#   Tr$   z'cookie': '123'N)r)   r*   r,   r-   r2   )r   r@   r6   r7   r8   stderr2s         r   test_minus_D_perf_trace_cp&TestDOption.test_minus_D_perf_trace_cp_   s    I)fEE""$J^^	'u	j		  F 	MM'0nn&Z#U ,0	  1G
 	MM'1r   c           
         SnU R                  USS9nU R                  5       nU R                  SSSSU[        U5      /SS	9nU R	                  US
5        U R                  SSSS[        X15      U/SS	9nU R	                  US
5        U R                  SS[        X15      /SS9nU R                  SU5        U R                  SU5        g)r<   r=   r>   r?   r"   z-hzcustom-header:asdfr#   Tr$   z2Headers: \{[\s\S]*'custom-header': 'asdf'[\s\S]*\}lsz-L)return_stdoutcustomasdfN)r)   r*   r,   r-   assertRegexr3   )r   r@   r6   r7   r8   rA   stdouts          r    test_minus_D_arbitrary_header_cp,TestDOption.test_minus_D_arbitrary_header_cpp   s    I)fEE""$J^^	t)4	j		  F 	VJLnnd($Z#U ,0	  1G
 	WJL ^^	tT*01  GFXv&VV$r   c           	      4   U R                  SS9nU R                  5       n[        S/5         U R                  SSU[	        U5      /SS9nU R                  SU5        U R                  S	U5        U R                  S
U5        S S S 5        g ! , (       d  f       g = f)Nr   r   )r    r!   4r"   r#   Tr$   r'   r(   ztotal_bytes_transferred: 8)r)   r*   r   r,   r-   r3   r2   )r   r6   r7   r8   s       r   test_minus_D_resumable_upload)TestDOption.test_minus_D_resumable_upload   s    5E""$J	EF	G~~ud:.
/t  Ef
z6*
mm?H
mm0&9 
H	G	Gs   AB		
Bc                    U R                  SS9n[        S/5         U R                  SS[        U5      /SSS9u  nnSSS5        U R	                  S	W5        U R	                  S
U5        [
        R                  (       a  U R	                  SU5        OU R	                  SU5        U R	                  SU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  [        R                  :X  Ga2  U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        U R                  SSU5        SUR                  < SUR                  < S 3n[        R                  " U5      nUR                  U5      nU(       d  U R!                  S!U< S"U< 35        UR#                  S#5      nU R	                  S$U5        U R%                  US%[&        R(                  -  5        OU R                  [        R*                  :X  a  [
        R                  (       a  U R	                  S&U5        OU R	                  S'U5        U R                  SS(U5        U R%                  US)UR                  < S*UR                  < 35        U R%                  US+[,        R.                  " 5       < S,[&        R(                  < S-35        [&        R0                  (       a  U R	                  S.W5        OU R%                  WS/5        U R	                  S0[&        R(                  -  U5        U R	                  S1U5        U R	                  S2U5        U R	                  S3U5        U R	                  S4U5        U R	                  S5U5        U R	                  S6U5        U R	                  S7U5        U R	                  S8U5        U R	                  S9U5        U R	                  S:U5        U R	                  S;U5        g! , (       d  f       GN= f)<z$Tests cat command with debug option.s
   0123456789r   )Boto
proxy_passsecretr"   catT)rF   r%   Nz1You are running gsutil with debug output enabled.zconfig:z('proxy_pass', u'REDACTED')z('proxy_pass', 'REDACTED')zreply: 'HTTP/1.1 200 OKExpiresDatezContent-Typezapplication/octet-streamzContent-Length10zCache-ControlETagz""781e5e245d69b566979b86e28d23f2c7"zLast-Modifiedzx-goog-generationzx-goog-metageneration1zx-goog-hashzcrc32c=KAwGng==zmd5=eB5eJF1ptWaXm4bijSPyxw==zsend:\s+([b|u]')?HEAD //z HTTP/[^\\]*\\r\\n(.*)z*Did not find this regex in stderr:
Regex: z	
Stderr:    zContent-Length: 0zPUser-Agent: .*gsutil/%s.*interactive/False invocation-id/[a-z0-9-].+ command/catz$md5Hash: u'eB5eJF1ptWaXm4bijSPyxw=='z#md5Hash: 'eB5eJF1ptWaXm4bijSPyxw=='z.no-cache, no-store, max-age=0, must-revalidatez	.*GET.*b/z/o/zPython/z.gsutil/z9.*interactive/False invocation-id/[a-z0-9-].+ command/cat.PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMSz.*checksum: [0-9a-f]{32}.*zgsutil version: %szboto version: zpython version: zOS: zmultiprocessing available: zusing cloud sdk: z&pass cloud sdk credentials to gsutil: zconfig path(s): zgsutil path: zcompiled crcmod: zinstalled via package manager: zeditable install: )CreateObjectr   r,   r-   r2   sixPY2r   r0   r   XMLbucket_nameobject_namerecompilesearchr   grouprI   gslibVERSIONr1   platformpython_versionIS_PACKAGE_INSTALL)r   key_urirJ   r8   	regex_strregexmatchrequest_fields_strs           r   test_minus_D_catTestDOption.test_minus_D_cat   s   7G	?@	Aud7m <.2.2   4v 
B 	MMEvNMM)V$
ww
mm16:
mm0&9MM+V4  D&9  v6  1K!')  !14@}}'
""?D&A
""6+O#)+
""?D&A
""#6fE
""#:CH
""=2CVL
""=#A6K 

w224ijj#ell6"e		f& 	' ;;q>
mm');<


\MM 
+**	*	<fE;VD
""
K
 
 ' 3 3W5H5H
IK 
$$&78
 
mmDfM
v<=MM&6?MM"F+MM$f-MM&&!MM/8MM%v.MM:FCMM$f-MM/6*MM%v.MM3V<MM&/W 
B	As   !Q
Q N)__name__
__module____qualname____firstlineno____doc__r   r9   rB   rK   rO   rr   __static_attributes__rt   r   r   r   r   #   s%    /$2L$2"%2:N0r   r   )ry   
__future__r   r   r   r   rj   rd   r_   rh   gslib.cs_api_mapr   gslib.tests.testcaseteststestcase)gslib.tests.testcase.integration_testcaser	   gslib.tests.utilr
   r-   r   gslib.utils.unit_utilr   GsUtilIntegrationTestCaser   rt   r   r   <module>r      sa    . & %  '  	 
  ( ' ' ? 0 1 ) 23}0(44 }0 4}0r   