
    w)                        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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SKJr  SSKJr  SSKJr  SSK J!r!J"r"  \!" \"" SSS5      5        SSK#J$r$  \RJ                  RM                  \RJ                  RO                  \(5      5      r)\RJ                  RU                  \)SS5      r+ " S S\RX                  5      r- " S S\R\                  5      r/g)zTests for the update command.    )absolute_import)print_function)division)unicode_literalsN)_UUID_FILE_PATH)ObjectToURI)unittest)system_util)CERTIFICATE_VALIDATION_ENABLED)UTF8)DisallowUpdateIfDataInGsutilDir)GsutilPubTarball)add_moveMovedModulemockzunittest.mock)r   z..c                   J    \ rS rSrSr\R                  " \S5      S 5       rSr	g)
UpdateTest8   zUpdate command test suite.z3Test requires https certificate validation enabled.c           	         [         R                  " 5       (       a&  U R                  S/SSSS9nU R                  SU5        g[        R
                  (       a%  U R                  S/SSS9nU R                  S	U5        gU R                  5       nU R                  5       n[        R                  R                  US
5      n[        R                  R                  US
5      n[        R                  R                  S
S
5      n[        R                  " SSSS5      n[        R                  " [        XGS9  [        R                  " U5        [        R                  " [        5       H  nSU;  d  M  SU;  d  M  UR!                  S5      (       a  M+  UR!                  S5      (       a  MC  [        R                  R                  [        U5      n	[        R                  R                  XX5      n
[        R                  R#                  U	5      (       a  [        R                  " XUS9  M  [        R$                  " X5        M     Sn[        R                  R                  US5      nU R'                  [        R                  R)                  U5      5        [+        US5       nUR-                  U5        SSS5        [        R                  R                  US5      n[        R                  R.                  n S [        R                  l        [0        R*                  " US5      nUR3                  USS9  UR5                  5         U[        R                  l        [6        R8                  (       a  [6        R8                  /O/ n[:        R<                  " U/ SQ-   U[:        R>                  [:        R>                  S9nURA                  5       u  nnURB                  R5                  5         URD                  R5                  5         U RG                  URH                  S5        U R                  SU5        [:        R<                  " U/ SQ-   U[:        R>                  [:        R>                  S9nURA                  5       u  nnURB                  R5                  5         URD                  R5                  5         U RG                  URH                  S5        U R                  SU5        [:        R<                  " US
S[K        U5      /-   U[:        R>                  [:        R>                  S9nURA                  5       u  nnURB                  R5                  5         URD                  R5                  5         U RG                  URH                  S5        U R                  S U5        [+        [        R                  R                  US!5      S5       nUR-                  S"5        SSS5        [:        R<                  " US
SS#[K        U5      /-   U[:        R>                  [:        R>                  [:        R>                  S$9nURA                  5       u  nnURB                  R5                  5         URD                  R5                  5         [        RL                  " [        R                  R                  US!5      5        U RG                  URH                  S5        [        RN                  RQ                  [R        5      nUU;   a  URU                  US%5      nOS&U;   a  URU                  S&S%5      nU R                  S'U5        [        R                  R)                  [V        5      =(       d     [X        RZ                  R]                  S(S)5      (       + nU(       a  S*OS+n[:        R<                  " UUSS#[K        U5      /-   U[:        R>                  [:        R>                  [:        R>                  S$9nURA                  US,9u  nnURB                  R5                  5         URD                  R5                  5         U RG                  URH                  S-S.URH                  UR_                  [R        5      4-  S/9  [        R                  R                  US
S5      n[+        US05       nU RG                  URa                  5       U5        SSS5        U(       a  [        RL                  " [V        5        gg! , (       d  f       GN = f! U[        R                  l        f = f! , (       d  f       GN2= f! , (       d  f       No= f)1z@Tests that the update command works or raises proper exceptions.updatenT   )stdinreturn_stderrexpected_statusz(update command is disabled for Cloud SDKN)r   r   zInvalid commandgsutilz.git*z*.pycz*.pyo__pycache__)ignore.git.pycz.pyoz17.25VERSIONwzgsutil.test.tar.gzc                     U $ )N )fnames    *platform/gsutil/gslib/tests/test_update.py<lambda>(UpdateTest.test_update.<locals>.<lambda>   s    u    zw:gzz./gsutil)arcname)r   r   zgs://pub)cwdstdoutstderrs%   update command only works with tar.gz)r   r   zgs://pub/Jdjh38)(;.tar.gzs   NotFoundExceptions   command does not supportzuserdata.txtzimportant data
z-f)r+   r,   r-   r          
sD   The update command cannot run with user data in the gsutil directoryGSUtildisable_analytics_prompts   n
y
s   y
)inputr   z:Non-zero return code (%d) from gsutil update. stderr = 
%s)msgr)1r
   InvokedViaCloudSdk	RunGsUtilassertIngslibIS_PACKAGE_INSTALLCreateTempDirospathjoinshutilignore_patternscopytree
GSUTIL_DIRmakedirslistdirendswithisdircopyfile
assertTrueexistsopenwritenormpathtarfileaddclosesys
executable
subprocessPopenPIPEcommunicater,   r-   assertEqual
returncodesuriunlinklinesepencoder   replacer   botoconfig	get_valuedecoderead)selfr-   
tmpdir_src
tmpdir_dst
gsutil_src
gsutil_dstgsutil_relative_dstignore_callablecompcp_src_pathcp_dst_pathexpected_versionsrc_version_filefsrc_tarballrK   tarprefixp_fpos_lsanalytics_promptupdate_inputdst_version_files                            r&   test_updateUpdateTest.test_update;   s    %%''~~xj$',0./  1f mm>G~~xja~Pf
mm%v. ##%J##%J j(3Jj(3J'',,x:,,	O OOJ
C KK


:&


t
#}}V$$}}V$$ggll:t4ggll:477==%%
//+?
K
//+
3 ' ww||J	:OOBGGNN#345		$gg 
% '',,z+?@KwwH	" -bggLLf-c	ggj*g-	iik!bgg!$cnnRF 	"BB' * *	1A --/KQHHNNHHNNQ\\1%MM:FC 	JK' * *		1A
 --/KQHHNNHHNNQ\\1%MM&/ 	(Hd;&788		 A
 --/KQHHNNHHNNQ\\1%MM-v6 
bggll:~6	<hh!" 
=	8T4#45	6oo	A --/KQHHNNHHNN IIbggll:~67Q\\1%JJd#E~~eT*f	&~~eT*fMMO
 GGNN?; N KK11(2LNO %5=(L 	%x{#% 	%oo	A --l-3KQHHNNHHNN		JllFMM$/01  3 ww||J)D		$
qvvx!12 
%
 ii  c 
%	$  "bggP 
=	<h 
%	$s1   b?)Ac .c+3!c=?
cc(+
c:=
dr$   N)
__name__
__module____qualname____firstlineno____doc__r	   
skipUnlessr   rx   __static_attributes__r$   r)   r&   r   r   8   s,    "5LNi!Ni!r)   r   c                   n    \ rS rSrSr\R                  " \R                  (       + S5      S 5       r	S r
Srg)UpdateUnitTest   z.Tests the functionality of commands/update.py.zhTest is runnable only if gsutil dir is accessible, and update command is not valid for package installs.c                    U R                  5       n[        R                  R                  US5      n[        R                  " U5        / n[        R
                  " [        5       Hf  nUR                  S5      (       d:  UR                  S5      (       d$  US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US	:X  a  MU  UR                  U5        Mh     U H  n[        R                  R                  [        R                  R                  [        U5      5      (       a  [        R                  nO[        R                  nU" [        R                  R                  [        U5      [        R                  R                  X%5      5        M     [        US
9  g)z1Ensure that all files/folders match the manifest.r   r    r   r   z	.settingsz.projectz.pydevprojectz.style.yapfz.yapfignore)	directoryN)r:   r;   r<   r=   rB   rC   rA   rD   
startswithappendrE   r>   r@   rF   r   )ra   rb   rd   
copy_filesfilenamerh   funcs          r&   test_repo_matches_manifest)UpdateUnitTest.test_repo_matches_manifest   s    ##%Jj(3JKK
JJJz*


F
#
#x':':6'B'B
m
#x;'>
j
 H$?
m
#x='@! + 	rww||J5	6	6
277<<
D)277<<
+IJ  $j9r)   c                    [         R                  R                  [        S5       nSUl        U R                  S[        5       5        SUl        U R                  S[        5       5        SSS5        g! , (       d  f       g= f)zDEnsure that the correct URI is returned based on the Python version.version_info   zgsutil.tar.gz   zgsutil4.tar.gzN)r   patchobjectrO   majorr7   r   )ra   r   s     r&   test_pub_tarballUpdateUnitTest.test_pub_tarball  sY    			3	/<l
mmO%5%78l
mm$&6&89	 
0	/	/s   AA11
A?r$   N)rz   r{   r|   r}   r~   r	   r   r8   r9   r   r   r   r$   r)   r&   r   r      s8    6

"
""34:	4:.:r)   r   )0r~   
__future__r   r   r   r   os.pathr;   r>   rQ   rO   rL   r\   r8   gslib.metricsr   gslib.tests.testcaseteststestcasegslib.tests.utilr   rW   r	   gslib.utilsr
   gslib.utils.boto_utilr   gslib.utils.constantsr   gslib.utils.update_utilr   r   sixr   r   	six.movesr   r<   abspathdirname__file__	TESTS_DIRr=   rA   GsUtilIntegrationTestCaser   GsUtilUnitTestCaser   r$   r)   r&   <module>r      s   , $ & %  '    
    ) ' ' 0 % # @ & C 4 % VV_	5 6 GGOOBGGOOH56	WW\\)T40
n!33 n!b$:X00 $:r)   