
    [(                         S 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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 r " S S\5      rg)z.Create iOS test matrices in Firebase Test Lab.    )absolute_import)division)unicode_literalsN)
exceptions)matrix_creator_common)
matrix_ops)util)logc                 x    [        XX#U5      nUR                  [        R                  " 5       R                  5      $ )a  Creates a new iOS matrix test in Firebase Test Lab from the user's params.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    gcloud command invocation (i.e. group and command arguments combined).
  context: {str:obj} dict containing the gcloud command context, which
    includes the Testing API client+messages libs generated by Apitools.
  history_id: {str} A history ID to publish Tool Results to.
  gcs_results_root: the root dir for a matrix within the GCS results bucket.
  release_track: the release track that the command is invoked from.

Returns:
  A TestMatrix object created from the supplied matrix configuration values.
)MatrixCreatorCreateTestMatrixuuiduuid4hex)argscontext
history_idgcs_results_rootrelease_trackcreators         >lib/googlecloudsdk/api_lib/firebase/test/ios/matrix_creator.pyCreateMatrixr   !   s2     $')'		!	!$**,"2"2	33    c                   ^    \ rS rSrSrS rSS jrS rS rS r	S r
S	 rS
 rS rS rS rSrg)r   5   zGCreates a single iOS test matrix based on user-supplied test arguments.c                     [         R                  " 5       U l        Xl        X0l        X@l        US   U l        US   U l        XPl        g)aC  Construct an MatrixCreator to be used to create a single test matrix.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    gcloud command invocation (i.e. group and command arguments combined).
  context: {str:obj} dict containing the gcloud command context, which
    includes the Testing API client+messages libs generated by Apitools.
  history_id: {str} A history ID to publish Tool Results to.
  gcs_results_root: the root dir for a matrix within the GCS results bucket.
  release_track: the release track that the command is invoked from.
testing_clienttesting_messagesN)	r	   
GetProject_project_args_history_id_gcs_results_root_client	_messages_release_track)selfr   r   r   r   r   s         r   __init__MatrixCreator.__init__8   sC     OO%DMJ!-+,DL/0DN'r   c                     U(       d  gU(       a  [         R                  R                  U5      n[         R                  R                  U R                  U5      nU R
                  R                  US9$ )z0Build a FileReference pointing to a file in GCS.NgcsPath)ospathbasenamejoinr#   r%   FileReference)r'   filenameuse_basenamer.   s       r   _BuildFileReference!MatrixCreator._BuildFileReferenceM   sQ    !!(+h77<<..9D>>'''55r   c           
         [        U R                  S/ 5      =(       d    /  Vs/ s H1  nU R                  [        R                  R                  U5      5      PM3     nn/ n[        U R                  S/ 5      =(       d    /  Hn  nSU;   a=  UR                  S5      u  pVUR                  U R                  R                  XVS95        MF  UR                  U R                  R                  US95        Mp     / n[        U R                  SS5      =(       d    0 nUR                  5        H|  n	U	R                  S5      n
U
S:w  a  U	SU
 OSnU
S:w  a  XS	-   S OU	nUR                  U R                  R                  U R                  [        R                  " U5      S
S9UUS95        M~     U R                  R                  [        U R                  SS5      UUUS9$ s  snf )z&Build an IosTestSetup for an iOS test.additional_ipasdirectories_to_pull:)bundleId
devicePath)r;   other_filesN   F)r3   )contentr:   r;   network_profile)networkProfileadditionalIpas	pushFilespullDirectories)getattrr!   r4   r-   r.   r/   splitappendr%   IosDeviceFilekeysfindr	   GetRelativeDevicePathIosTestSetup)r'   additional_ipar7   r8   	directorybundler.   device_filesr<   device_pathidx	bundle_ids               r   _BuildGenericTestSetup$MatrixCreator._BuildGenericTestSetupV   s    &djj2CRHNBNNN 	  !1!1.!ABN   TZZ)>CIrI				 s+""NN((&(J	L 	""NN((I(>	@ J L$**mT:@bK"'') S!c'*by+ds#di&)Ri[q"[d
..
&
&..,,T2 / H 	 '   * >>&&tzz+<dC&+	 ' - -7s   8Gc                    U R                   R                  U R                  R                  (       + U R	                  5       [
        R                  " U R                  R                  5      U R                   R                  U R                  U R                  R                  5      U R                  U R                  R                  5      U R                  R                  [        U R                  SS5      S9S9nU$ )+Build a TestSpecification for an IosXcTest.test_special_entitlementsF)testsZip	xctestrunxcodeVersiontestSpecialEntitlements)disableVideoRecordingiosTestSetuptestTimeout	iosXcTest)r%   TestSpecificationr!   record_videorT   r   ReformatDurationtimeout	IosXcTestr4   testxctestrun_filexcode_versionrE   r'   specs     r   _BuildIosXcTestSpec!MatrixCreator._BuildIosXcTestSpecy   s    >>++"&**"9"99002//

0B0BC..**--djjoo>..tzz/H/HI11$+DJJ,G,1%3	 + 4	 , 
5D Kr   c           
      z   U R                   R                  U R                  R                  (       + U R	                  5       [
        R                  " U R                  R                  5      U R                   R                  U R                  U R                  R                  5      U R                  R                  S9S9nU$ )rW   )appIpa	scenarios)r]   r^   r_   iosTestLoop)r%   ra   r!   rb   rT   r   rc   rd   IosTestLoopr4   appscenario_numbersri   s     r   _BuildIosTestLoopTestSpec'MatrixCreator._BuildIosTestLoopTestSpec   s    >>++"&**"9"99002//

0B0BCNN..++DJJNN;jj11 / 3	 , 4D Kr   c           
      *   U R                   R                  U R                  R                  (       + U R	                  5       [
        R                  " U R                  R                  5      U R                   R                  U R                  U R                  R                  5      S9S9n[        U R                  SS5      (       aQ  U R                  [        R                  R                  U R                  R                  5      5      UR                   l        U$ )z/Build a TestSpecification for an iOS Robo test.)rn   )r]   r^   r_   iosRoboTestrobo_scriptN)r%   ra   r!   rb   rT   r   rc   rd   IosRoboTestr4   rr   rE   r-   r.   r/   rx   rw   
roboScriptri   s     r   _BuildIosRoboTestSpec#MatrixCreator._BuildIosRoboTestSpec   s    >>++"&**"9"99002//

0B0BCNN..++DJJNN; / =	 , >D tzz=$//$($<$<
''

4::11
2%4d!Kr   c                     US:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  U R                  5       $ [        R                  " SSR                  U5      5      e)zBMap a test type into its corresponding TestSpecification message .xctestz	game-looprobotypezUnknown test type "{}".)rk   rt   r{   r   InvalidArgumentExceptionformat)r'   	test_types     r   _TestSpecFromTypeMatrixCreator._TestSpecFromType   sk    H%%''	k	!++--	f	''))//
+229=? ?r   c                    U R                   R                   Vs/ s H  o R                  U5      PM     nnU R                  R	                  U R                  R                  US9S9nU R                  R                  U R                  S9nU R                  R                  U R                  U R                  S9nU R                  R                  XVS9n[        R                  " U R                  [        U R                   S0 5      =(       d    0 U R                  5      nU R                  R!                  UUUUU R                   R"                  =(       d    SS9$ s  snf )	zBuild just the user-specified parts of an iOS TestMatrix message.

Args:
  spec: a TestSpecification message corresponding to the test type.

Returns:
  A TestMatrix message.
)
iosDevices)iosDeviceListr+   )	projectId	historyId)googleCloudStoragetoolResultsHistoryclient_detailsr   )testSpecificationenvironmentMatrix
clientInforesultStorageflakyTestAttempts)r!   device_BuildIosDevicer%   EnvironmentMatrixIosDeviceListGoogleCloudStorager#   ToolResultsHistoryr    r"   ResultStorager   BuildClientInforE   r&   
TestMatrixnum_flaky_test_attempts)	r'   rj   ddevicesenvironment_matrixgcshistresultsclient_infos	            r   _BuildTestMatrixMatrixCreator._BuildTestMatrix   s<    15

0A0AB0A1##A&0AGB99nn22g2F : H ..
+
+D4J4J
+
KC>>,,--4+;+; - =Dnn** + 9G (77

,b17R9L9LNK >>$$,**<<A % C C Cs   Ec                 R    U R                   R                  US   US   US   US   S9$ )Nmodelversionlocaleorientation)
iosModelIdiosVersionIdr   r   )r%   	IosDevice)r'   
device_maps     r   r   MatrixCreator._BuildIosDevice   s>    >>##g&	*(#}-	 $ / /r   c                     U R                  U R                  R                  5      nU R                  R	                  U R
                  U R                  U5      US9$ )zBuild a TestingProjectsTestMatricesCreateRequest for a test matrix.

Args:
  request_id: {str} a unique ID for the CreateTestMatrixRequest.

Returns:
  A TestingProjectsTestMatricesCreateRequest message.
)r   
testMatrix	requestId)r   r!   r   r%   (TestingProjectsTestMatricesCreateRequestr    r   )r'   
request_idrj   s      r   _BuildTestMatrixRequest%MatrixCreator._BuildTestMatrixRequest   sQ     !!$**//2D>>BB--((. C  r   c                 
   U R                  U5      n[        R                  " SR                  U5      5         U R                  R
                  R                  U5      n[        R                  " SR                  U5      5        [        R                  R                  SR                  UR                  S95        U$ ! [        R                   a4  nS[        R                  " U5      -   n[        R                  " U5      eSnAff = f)a"  Invoke the Testing service to create a test matrix from the user's args.

Args:
  request_id: {str} a unique ID for the CreateTestMatrixRequest.

Returns:
  The TestMatrix response message from the TestMatrices.Create rpc.

Raises:
  HttpException if the test service reports an HttpError.
z!TestMatrices.Create request:
{0}
z"TestMatrices.Create response:
{0}
z'Http error while creating test matrix: Nz1Test [{id}] has been created in the Google Cloud.)id)r   r
   debugr   r$   projects_testMatricesCreateapitools_exceptions	HttpErrorr	   GetErrorr   HttpExceptionstatusPrinttestMatrixId)r'   r   requestresponseerrormsgs         r   r   MatrixCreator.CreateTestMatrix   s     **:6GII3::7CD*33::7Ch	ii6==hGH
 JJHOO   P " #O (( *5e8LLc$$S))*s   A
B: :D/C==D)r!   r$   r#   r"   r%   r    r&   N)T)__name__
__module____qualname____firstlineno____doc__r(   r4   rT   rk   rt   r{   r   r   r   r   r   __static_attributes__ r   r   r   r   5   s>    O(*6!-F	
?C</r   r   )r   
__future__r   r   r   r-   r   apitools.base.pyr   r   $googlecloudsdk.api_lib.firebase.testr   r   r	   googlecloudsdk.calliopegooglecloudsdk.corer
   r   objectr   r   r   r   <module>r      s>    5 &  ' 	  > F ; 5 . #4(BF Br   