
    .                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmc m	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dZ ed       ed       G d de	j.                                      Zy)z+Integration tests for notification command.    )absolute_import)print_function)division)unicode_literalsN)PopulateProjectId)	SkipForS3)
SkipForXML)ObjectToURI)Retry)UTF8s   innardsz)gsutil doesn't support S3 Requester Pays.z0Requester Pays is not supported for the XML API.c                        e Zd ZdZddgZddgZ fdZd ZddZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestRequesterPayszIntegration tests for Requester Pays.

  Passing in a user project should succeed for operations on Requester Pays
  buckets, and with the GA release will also succeed for non-Requester Pays
  buckets.
  requesterpayssetgetc                 n   t         t        |           | j                         | _        | j                         | _        | j                  | j
                         | j                  | j                  t              | _	        | j                  | j
                  t              | _
        dt               g| _        y )N
bucket_uricontentsz-u)superr   setUpCreateBucketnon_requester_pays_bucket_urirequester_pays_bucket_uri_set_requester_paysCreateObjectOBJECT_CONTENTSnon_requester_pays_object_urirequester_pays_object_urir   user_project_flag)self	__class__s    2platform/gsutil/gslib/tests/test_requester_pays.pyr   zTestRequesterPays.setUp0   s    	
T(*)-):):)<D&%)%6%6%8D"T;;<)-):):55 *; *QD&%)%6%611O &7 &MD""$5$78D    c                 @    | j                  dddt        |      g       y )Nr   r   on)	RunGsUtilsuri)r!   r   s     r#   r   z%TestRequesterPays._set_requester_pays;   s    NNOUD$z2BCDr$   c                     | j                  | j                  |z   d      }|rHt        |t              r|j	                  t
              }| j                  ||t        j                         yy)a  Test a command with a user project.

    Run a command with a user project on a Requester Pays bucket. The command is
    expected to pass because the source bucket is Requester Pays. If a regex
    pattern is supplied, also assert that stdout of the command matches it.
    Treturn_stdout)flagsN)	r'   r    
isinstancebytesdecoder   assertRegexpMatchesWithFlagsre
IGNORECASE)r!   command_listregexstdouts       r#   _run_requester_pays_testz*TestRequesterPays._run_requester_pays_test>   s`     ^^D22\A*.  0F	E5	!T"
''R]]'K r$   c                 D    | j                  | j                  |z   d      }y)zTest a command with a user project on a non-Requester Pays bucket.

    Run a command with a user project on a non-Requester Pays bucket. The
    command will still succeed, because with GA user project is accepted for
    all requests.
    Tr*   N)r'   r    )r!   r3   r5   s      r#   _run_non_requester_pays_testz.TestRequesterPays._run_non_requester_pays_testL   s'     ^^D22\A*.  0Fr$   c                     | j                         }| j                  | j                  t        |      gz   d      }| j	                  |j                         dt        |      z         y NTr*   z%s: Disabled)r   r'   _get_rp_cmdr(   assertEqualstrip)r!   r   r5   s      r#   test_off_defaultz"TestRequesterPays.test_off_defaultV   s[    ""$J^^D,,Z0@/AA*.  0FV\\^^d:6F%FGr$   c                       j                          j                   j                  dt              gz           fd} |        y )Nr&   c                      j                  j                  t              gz   d      } j                  | j	                         dt              z         y NTr*   z%s: Enabledr'   r;   r(   r<   r=   r5   r   r!   s    r#   _Check1z2TestRequesterPays.test_turning_on.<locals>._Check1`   N    ~~d..$z2B1CC,0  2f
v||~}tJ7G'GHr$   r   r'   _set_rp_cmdr(   )r!   rD   r   s   ` @r#   test_turning_onz!TestRequesterPays.test_turning_on\   s?    ""$JNN4##tT*-=&>>?I
 Ir$   c                       j                          j                   j                  dt              gz           fd} |         j                   j                  dt              gz           fd} |        y )Nr&   c                      j                  j                  t              gz   d      } j                  | j	                         dt              z         y rA   rB   rC   s    r#   rD   z3TestRequesterPays.test_turning_off.<locals>._Check1k   rE   r$   offc                      j                  j                  t              gz   d      } j                  | j	                         dt              z         y r:   rB   rC   s    r#   _Check2z3TestRequesterPays.test_turning_off.<locals>._Check2t   sN    ~~d..$z2B1CC,0  2f
v||~~Z8H'HIr$   rF   )r!   rD   rM   r   s   `  @r#   test_turning_offz"TestRequesterPays.test_turning_offg   sm    ""$JNN4##tT*-=&>>?I
 INN4##ud:.>&??@J
 Ir$   c                    | j                  | j                  dd      }| j                  d|       | j                  | j                  dd      }| j                  d|       | j                  dgdd      }| j                  d|       y)z;Ensures requesterpays commands fail with too few arguments.T   )return_stderrexpected_statuszcommand requires at leastr   N)r'   rG   assertInr;   )r!   stderrs     r#   testTooFewArgumentsFailsz*TestRequesterPays.testTooFewArgumentsFails{   s     ^^D,,*.,-  /F 	MM-v6 ^^D,,*.,-  /F 	MM-v6 ^^_-*.,-  /F 	MM-v6r$   c                 R   | j                         }| j                  |       | j                  dddt        |      g       | j                  ddt        |      g       | j                         }| j	                  dddt        |      g       | j	                  ddt        |      g       y )Naclr   zpublic-readr   r   r   r6   r(   r8   )r!   r   r   s      r#   test_aclzTestRequesterPays.test_acl   s     $ 1 1 367!!	}	'	(	*+ 	!!	t5679 %)$5$5$7!%%	}	+	,	./ 	%%	t9:;=r$   c                     | j                  dt        | j                        g       | j                  dt        | j                        g       y )Nls)r6   r(   r   r8   r   r!   s    r#   test_lszTestRequesterPays.test_ls   sA    !!4d.L.L)M"NO%%	tD6678:r$   c                     | j                         }| j                  |       | j                  dt        |      g       | j                         }| j	                  dt        |      g       y )NrbrX   )r!   rp_bucket_urinon_rp_bucket_uris      r#   test_rbzTestRequesterPays.test_rb   s^    %%'M]+!!4m)<"=>))+%%tT2C-D&EFr$   c                     | j                         }| j                  dt        | j                        t        |      g       | j	                  dt        | j
                        t        |      g       y )Ncp)r   r6   r(   r   r8   r   )r!   dest_bucket_uris     r#   	test_copyzTestRequesterPays.test_copy   sj    '')O!!		d,,	-	o		 ! 	%%		d00	1	o		 !r$   c                     g d}| j                         }|D cg c]  }| j                  ||      j                  ! }}| j                  || j	                  d            }| j                  dg|z   |j                  gz          | j                         }| j                  |       |D cg c]  }| j                  ||      j                  ! }}t        |      dz   }| j                  dg|z   |gz          y c c}w c c}w )N)s   apples   oranges   bananar   objcomposez/composite.txt)	r   r   uriStorageUriCloneReplaceNameMakeTempNamer8   r   r(   r6   )	r!   	data_listr   data
components	compositer`   rp_componentsrp_composites	            r#   test_composezTestRequesterPays.test_compose   s#   0I""$J D 	Z$?CC   //
040A0A%0HJI%%ykJ&>'0}}o'6 7 %%'M]+ D 	]TBFF   &)99L!!9+"="NO!s   $C6($C;c                     | j                  dt        | j                        gt               | j	                  dt        | j
                        g       y )Ncatr4   )r6   r(   r   r   r8   r   r\   s    r#   test_catzTestRequesterPays.test_cat   sL    !!	T3345_ " N%%	T7789;r$   c                 H     t        t        dd       fd       } |        y )N   rP   )triestimeout_secsc                       j                  dt         j                        g        j                  dt         j                        g       y )Ndur6   r(   r   r8   r   r\   s   r#   _checkz-TestRequesterPays.test_du_obj.<locals>._check   sG     ##d445
68
''d889
:<r$   )r   AssertionError)r!   r   s   ` r#   test_du_objzTestRequesterPays.test_du_obj   s%    
>3< 4< Hr$   c                     | j                  ddt        | j                        gd       | j                  ddt        | j                        g       y )Nhashz-czHash \(crc32c\)rv   r~   r\   s    r#   	test_hashzTestRequesterPays.test_hash   sS    !!	tD::;<  " " 	%%	tD>>?@Br$   c                     | j                  ddt        | j                        g       | j                  ddt        | j                        g       y )Niamr   )r6   strr   r8   r   r\   s    r#   test_iamzTestRequesterPays.test_iam   sI    !!	s499:;=%%	s4==>?Ar$   c                 j   | j                         }| j                  |d      }| j                  |d      }| j                  |d       | j                  |       | j                         }||fD ](  }| j	                  dt        |      t        |      g       * | j                  |d       | j                         }| j                  |d      }| j                  |d      }| j                  |d       ||fD ](  }| j                  dt        |      t        |      g       * | j                  |d       y )	Ns   foor   s   oOOo   mvr      bar   baz)r   r   AssertNObjectsInBucketr   r6   r(   r8   )r!   r   object1_uriobject2_urire   rh   r   s          r#   test_mvzTestRequesterPays.test_mv   s?    $ 1 1 3##/H-3 $ 5K##/H-4 $ 6K 91=67'')O [)
##T49d?6K$LM * 91=""$J##zF#KK##zF#KK
A.[)
''cD1
24 * 	
A.r$   c                 (   | j                  d      }| j                  rdnd}| j                  dd|t        |      g       | j	                         }| j                  |       | j                  |d      }| j                  dd|t        |      g       y )	Nr   )r   nearlinedrarewritez-sr   r   )r   _use_gcloud_storager8   r(   r   r   r6   )r!   
object_uristorage_classreq_pays_bucket_urireq_pays_obj_uris        r#   test_rewritezTestRequesterPays.test_rewrite  s    ""F"3J"&":":JM%%	D-	j		 ++-01((4G28 ) :!!	D-			!"r$   c                 f   | j                  d      }| j                  |       | j                  d      }| j                  ddt        |      t        | j                        g       | j                  d      }| j                  d      }| j                  ddt        |      t        |      g       y )Nr   )test_objectsrP   rsyncz-d)r   r   r6   r(   r   r8   )r!   r   r   bucket_uri1bucket_uri2s        r#   
test_rsynczTestRequesterPays.test_rsync  s    +++;01"""2J!! !T++,#  ###3K###3K%%	$[)	k		r$   c                     | j                  | j                  d      }| j                  dddt        |      g       | j                  | j                  d      }| j                  dddt        |      g       y )Ns   <html><body>text</body></html>r   setmetaz-hzcontent-type:text/html)r   r   r6   r(   r   r8   )r!   r   obj_uris      r#   test_setmetazTestRequesterPays.test_setmeta$  s    ((112 ) 4 	!!	D2			!" 4+M+M)J   LG%%	D2	g	r$   c                     | j                  dt        | j                        g       | j                  dt        | j                        g       y )Nstatr~   r\   s    r#   	test_statzTestRequesterPays.test_stat2  sD    !!	d44568%%	d889:<r$   )N)__name__
__module____qualname____doc__rG   r;   r   r   r6   r8   r>   rH   rN   rU   rY   r]   rb   rf   rs   rw   r   r   r   r   r   r   r   r   __classcell__)r"   s   @r#   r   r   #   s     !%(+ %(+	9EL0H	(7(= :
G
!P,;
BA/0" <r$   r   )r   
__future__r   r   r   r   r1   gslib.tests.testcaseteststestcasegslib.project_idr   )gslib.tests.testcase.integration_testcaser   r	   gslib.tests.utilr
   r(   gslib.utils.retry_utilr   gslib.utils.constantsr   r   GsUtilIntegrationTestCaser    r$   r#   <module>r      so    2 & %  ' 	 ' ' . ? @ 0 ( & 78>?Q<:: Q< @ 9Q<r$   