
    *              	           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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rSr " S S\R(                  " SSS/5      5      rS r\4S jrS rS rS rS rg)zGA utility library to support interaction with the Tool Results service.    )absolute_import)division)unicode_literalsN)
exceptions)apis)
properties)progress_tracker)parse   c                       \ rS rSrSrSrg)ToolResultsIds#   zA tuple to hold the history & execution IDs returned from Tool Results.

Fields:
  history_id: a string with the Tool Results history ID to publish to.
  execution_id: a string with the ID of the Tool Results execution.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       8lib/googlecloudsdk/api_lib/firebase/test/tool_results.pyr   r   #   s    r   r   
history_idexecution_idc                    [         R                  R                  R                  R	                  5       nU(       d  Sn[
        R                  " SU UR                  UR                  S.5      n[        R                  " X#5      $ )a  Create the URL for a test's Tool Results UI in the Firebase App Manager.

Args:
  project_id: string containing the user's GCE project ID.
  tool_results_ids: a ToolResultsIds object holding history & execution IDs.

Returns:
  A url to the Tool Results UI.
z#https://console.firebase.google.comzBproject/{project}/testlab/histories/{history}/matrices/{execution})projecthistory	execution)r   VALUEStestresults_base_urlGeturitemplateexpandr   r   r
   urljoin)
project_idtool_results_idsurl_baseurl_ends       r   CreateToolResultsUiUrlr)   -   sk     ##4488:(	4HJ%00'44M	' 
x	))r   c                    SnSnSn[         R                  " USS9    U R                  R                  (       aO  U R                  R                  R                  nU R                  R                  R
                  nU(       a  U(       a  OaU R                  UR                  ;   a  [        R                  " [        U 5      5      e[        R                  " U5        UR                  5       n M  SSS5        [        X4S9$ ! , (       d  f       N= f)a  Gets the Tool Results history ID and execution ID for a test matrix.

Sometimes the IDs are available immediately after a test matrix is created.
If not, we keep checking the matrix until the Testing and Tool Results
services have had enough time to create/assign the IDs, giving the user
continuous feedback using gcloud core's ProgressTracker class.

Args:
  matrix: a TestMatrix which was just created by the Testing service.
  matrix_monitor: a MatrixMonitor object.
  status_interval: float, number of seconds to sleep between status checks.

Returns:
  A ToolResultsIds tuple containing the history ID and execution ID, which
  are shared by all TestExecutions in the TestMatrix.

Raises:
  BadMatrixError: if the matrix finishes without both ToolResults IDs.
Nz#Creating individual test executionsT)autotick)r   r   )r	   ProgressTrackerresultStoragetoolResultsExecution	historyIdexecutionIdstatecompleted_matrix_statesr   BadMatrixError_ErrorFromMatrixInFailedStatetimesleepGetTestMatrixStatusr   )matrixmatrix_monitorstatus_intervalr   r   msgs         r   GetToolResultsIdsr<   D   s    , *,-#''d;
				2	2))>>HH
++@@LL,
	??	?''(Ef(MNN
jj!113f  < 
:	II <;s   CC::
Dc                     [         R                  " SS5      nU R                  UR                  R                  R
                  :X  a  [        U 5      $ [        U 5      $ )z?Produces a human-readable error message from an invalid matrix.testingv1)r   GetMessagesModuler1   
TestMatrixStateValueValuesEnumINVALID_ExtractInvalidMatrixDetails_GenericErrorMessage)r8   messagess     r   r4   r4   n   sH    ##It4(\\X((==EEE'//	f	%%r   c                    / nU R                    H.  nUR                  SUR                   SUR                   35        M0     U(       a7  SR	                  U R
                  [        R                  R                  U5      S9$ [        U 5      $ )NzReason: z
 Message: z,Matrix [{m}] failed during validation.
{msg})mr;   )
extendedInvalidMatrixDetailsappendreasonmessageformattestMatrixIdoslinesepjoin_GetLegacyInvalidMatrixDetails)r8   invalid_details_for_userinvalid_details      r   rD   rD   w   s    ;;n##
>(()N4J4J3KL < :AA


2::??3K#L B   *&11r   c                 |   [         R                  " SS5      nUR                  R                  n0 UR                  S_UR
                  S_UR                  S_UR                  S_UR                  S_UR                  S_UR                  S	_UR                  S
_UR                  S_UR                  S_UR                  S_UR                  S_UR                   S_UR"                  S_UR$                  S_UR&                  S_UR(                  S_0 UR*                  S_UR,                  S_UR.                  S_UR0                  S_UR2                  S_UR4                  S_UR6                  S_UR8                  S_UR:                  S_UR<                  S_UR>                  S_UR@                  S_URB                  S _URD                  S!_URF                  S"_URH                  S#_URJ                  S$_EURL                  S%URN                  S&0EnU RP                  nXC;   a  S'RS                  U RT                  X4   S(9$ [W        U 5      $ ))zConverts legacy invalid matrix enum to a descriptive message for the user.

Args:
  matrix: A TestMatrix in a failed state

Returns:
  A string containing the legacy error message when no message is available
  from the API.

r>   r?   z.The app APK is not a valid Android applicationz8The test APK is not a valid Android instrumentation testz(The app APK is missing the manifest filez1The APK manifest file is missing the package namez5The test APK has the same package name as the app APKz=The test APK declares no instrumentation tags in the manifestzAAt least one supplied APK file has a missing or invalid signaturezThe test runner class specified by the user or the test APK's manifest file is not compatible with Android Test Orchestrator. Please use AndroidJUnitRunner version 1.1 or higherzThe test APK does not contain the test runner class specified by the user or the manifest file. The test runner class name may be incorrect, or the class may be mislocated in the app APK.z5The app APK does not specify a main launcher activityz=The app declares one or more permissions that are not allowedzRobo directives are invalid: multiple robo-directives cannot have the same resource name and there cannot be more than one `click:` directive specified.z?Robo Directive includes at least one invalid action definition.zURobo Directive resource name contains invalid characters: ":"  (colon) or " " (space)zCThe app does not have a correctly formatted game-loop intent filterz6A scenario-label was not declared in the manifest filezCA scenario-label in the manifest includes invalid numbers or rangesz7A scenario-number was not declared in the manifest filez1Device administrator applications are not allowedzThe XCTest zip file was malformed. The zip did not contain a single .xctestrun file and the contents of the DerivedData/Build/Products directory.zUThe provided XCTest was built for the iOS simulator rather than for a physical devicez;The .xctestrun file did not specify any test targets to runzxOne or more of the test targets defined in the .xctestrun file specifies "UseDestinationArtifacts", which is not allowedzOne or more of the test targets defined in the .xctestrun file does not have a host binary to run on the physical iOS device, which may cause errors when running xcodebuildzA"hasCode" is false in the Manifest. Tested APKs must contain codezEither the provided input APK path was malformed, the APK file does not exist, or the user does not have permission to access the filezdYour app targets a preview version of the Android SDK that's incompatible with the selected devices.zBOne or more of the Info.plist files in the zip could not be parsedzxThe APK application ID (aka package name) is invalid. See also https://developer.android.com/studio/build/application-idz*The app IPA is not a valid iOS applicationzEThe iOS game loop application does not register the custom URL schemez,The iOS application bundle (.app) is invalidz3The matrix expanded to contain too many executions.z;Not enough test quota to run the executions in this matrix.z.A required cloud service api is not activated.z8There was an unknown permission issue running this test.z,
Matrix [{m}] failed during validation: {e}.)rH   e),r   r@   rA   #InvalidMatrixDetailsValueValuesEnumMALFORMED_APKMALFORMED_TEST_APKNO_MANIFESTNO_PACKAGE_NAMETEST_SAME_AS_APPNO_INSTRUMENTATIONNO_SIGNATURE)INSTRUMENTATION_ORCHESTRATOR_INCOMPATIBLENO_TEST_RUNNER_CLASSNO_LAUNCHER_ACTIVITYFORBIDDEN_PERMISSIONSINVALID_ROBO_DIRECTIVESINVALID_DIRECTIVE_ACTIONINVALID_RESOURCE_NAME!TEST_LOOP_INTENT_FILTER_NOT_FOUNDSCENARIO_LABEL_NOT_DECLAREDSCENARIO_LABEL_MALFORMEDSCENARIO_NOT_DECLAREDDEVICE_ADMIN_RECEIVERMALFORMED_XC_TEST_ZIPBUILT_FOR_IOS_SIMULATORNO_TESTS_IN_XC_TEST_ZIPUSE_DESTINATION_ARTIFACTSTEST_NOT_APP_HOSTEDNO_CODE_APKINVALID_INPUT_APKINVALID_APK_PREVIEW_SDKPLIST_CANNOT_BE_PARSEDINVALID_PACKAGE_NAMEMALFORMED_IPAMISSING_URL_SCHEMEMALFORMED_APP_BUNDLEMATRIX_TOO_LARGETEST_QUOTA_EXCEEDEDSERVICE_NOT_ACTIVATEDUNKNOWN_PERMISSION_ERRORinvalidMatrixDetailsrM   rN   rE   )r8   rF   enum_values
error_dictdetails_enums        r   rR   rR      s    ##It4(##GG+Z
:Z $$
D	Z
 
4Z !!
=Z ""
AZ $$
IZ 
MZ ;;A!Z& &&G)Z. &&
A1Z2 ''
I5Z6 ))"9Z> **
KAZB ''$EZH 33
OKZL --
BOZP **
OSZT ''
CWZX ''
=[Z\ ''_Zd ))gZj ))
GmZn ++FqZt %%;wZ| 
MZ@ ##OCZF ))4IZL ((
NOZP &&FSZV 
6YZZ $$]Z` &&
8cZd ""
?gZh %%
GkZl ''
:**
DsZ*v ,,,;BB


!9 C ; < 
f	%%r   c                 J    SR                  U R                  U R                  S9$ )Nz
Matrix [{m}] unexpectedly reached final status {s} without returning a URL to any test results in the Firebase console. Please re-check the validity of your test files and parameters and try again.)rH   s)rM   rN   r1   )r8   s    r   rE   rE      s.    BBH&6<< CI C12r   )r   
__future__r   r   r   collectionsrO   r5   $googlecloudsdk.api_lib.firebase.testr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   googlecloudsdk.core.consoler	   six.moves.urllibr
   r"   _STATUS_INTERVAL_SECS
namedtupler   r)   r<   r4   rD   rR   rE   r   r   r   <module>r      s|    N &  '  	  ; , * 8 "  +lN-KL*2 '<'JT&2m&`2r   