
                         r    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J	r	  SSK
Jr  SSKJr   " S S	\5      rg
)z?A library to find a Tool Results History to publish results to.    )absolute_import)division)unicode_literals)
exceptions)util)logc                   0    \ rS rSrSrS rS rS rS rSr	g)	ToolResultsHistoryPicker   z5Finds a History to publish mobile test results to.
  c                 (    Xl         X l        X0l        g)zConstruct a ToolResultsHistoryPicker.

Args:
  project: string containing the GCE project id.
  client: ToolResults API client lib generated by apitools.
  messages: ToolResults API message classes generated by apitools.
N)_project_client	_messages)selfprojectclientmessagess       :lib/googlecloudsdk/api_lib/firebase/test/history_picker.py__init__!ToolResultsHistoryPicker.__init__!   s     MLN    c                    U R                   R                  U R                  XS9n U R                  R                  R                  U5      n[        R                  " SR                  U5      5        U$ ! [        R                   a@  nSR                  [        R                  " U5      5      n[        R                  " U5      eSnAff = f)a&  Lists histories by name using the Tool Results API.

Args:
   history_name: string containing the history name.
   page_size: maximum number of histories to return.

Returns:
  A list of histories matching the name.

Raises:
  HttpException if the Tool Results service reports a backend error.
)	projectIdfilterByNamepageSizez)
ToolResultsHistories.List response:
{0}
z<Http error while getting list of Tool Results Histories:
{0}N)r   'ToolresultsProjectsHistoriesListRequestr   r   projects_historiesListr   debugformatapitools_exceptions	HttpErrorr   GetErrorr   HttpException)r   history_name	page_sizerequestresponseerrormsgs          r   _ListHistoriesByName-ToolResultsHistoryPicker._ListHistoriesByName-   s     nnDD--l E PG*0055g>h	ii>EEhOPo(( *LfT]]5)* 
$$S))*s   AA2 2C;CCc                    U R                   R                  UUS9nU R                   R                  U R                  US9n U R                  R
                  R                  U5      n[        R                  " SR                  U5      5        U$ ! [        R                   a@  nSR                  [        R                  " U5      5      n[        R                  " U5      eSnAff = f)zCreates a History using the Tool Results API.

Args:
   history_name: string containing the name of the history to create.

Returns:
  The history id of the created history.

Raises:
  HttpException if the Tool Results service reports a backend error.
)namedisplayName)r   historyz+
ToolResultsHistories.Create response:
{0}
z5Http error while creating a Tool Results History:
{0}N)r   History)ToolresultsProjectsHistoriesCreateRequestr   r   r   Creater   r   r    r!   r"   r   r#   r   r$   )r   r%   r0   r'   r(   r)   r*   s          r   _CreateHistory'ToolResultsHistoryPicker._CreateHistoryE   s     nn$$,1= % ?GnnFF-- G 2G*0077@h	ii@!#o(( *EfT]]5)* 
$$S))*s    AB C  ;CC c                     U(       d  gU R                  US5      R                  nU(       a  US   R                  $ U R                  U5      nUR                  $ )a  Gets the history id associated with a given history name.

All the test executions for the same app should be in the same history. This
method will try to find an existing history for the application or create
one if this is the first time a particular history_name has been seen.

Args:
   history_name: string containing the history's name (if the user supplied
     one), else None.

Returns:
  The id of the history to publish results to.
N   r   )r+   	histories	historyIdr4   )r   r%   r8   new_historys       r   GetToolResultsHistoryId0ToolResultsHistoryPicker.GetToolResultsHistoryId_   sS      )),:DDIq\###''5k"""r   )r   r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r+   r4   r;   __static_attributes__ r   r   r
   r
      s    
*0*4#r   r
   N)rA   
__future__r   r   r   apitools.base.pyr   r!   $googlecloudsdk.api_lib.firebase.testr   googlecloudsdk.calliopegooglecloudsdk.corer   objectr
   rC   r   r   <module>rJ      s.     F &  ' > 5 . #Z#v Z#r   