
    k/iA                     \    d dl  d dl d dlmZ d dlmZ  G d deej                        Zy)    )*)cmf_testcase_run)EvaTestCodeMixinc                        e Zd Zej                  j
                  g dz   Zd Zd Zd Z fdZ	d Z
 fdZd Zedd	ef fd
       Z fdZ xZS )CmfTestcaseRun)rungroup_changesgroup_changes_statusesc           
      \   | j                  g d       | xj                  dz  c_        t        j                  j	                  ddidd| g       t        j                  | | j
                  | j                  | j                  | j                  | j                  d| j                  	      | _
        y )
N)testcaseresponsibleprioritytext   curFparent==)valuesfilterT)r   cache_testcaser   r   r   cache_estimate_timer   	iteration)load_fieldsr   modelsCmfTestcaseRunHistorybulk_updater   r   r   r   r   cur_history)selfargskwargss      ,./modules/evatest/models/cmf_testcase_run.pyr   zCmfTestcaseRun.run   s    ;	
 	!$$00PXZ^`dOe0f!77==((]] $ 8 8nn 8 	
    c                 ^   | j                   j                  sy | j                   j                  r3| j                  xj                  | j                   j                  z  c_        | j                  xj                  | j                   j
                  z  c_        | j                  j                          y N)r   
is_changedoldr   estimate_timenewsaver   s    r!   _calc_estimate_timez"CmfTestcaseRun._calc_estimate_time   su    ''22##''KK%%)A)A)E)EE%!!T%=%=%A%AA!r"   c                    | j                   j                  s| j                  r| j                  sy | j                  j                  }| j                   j
                  r7| j                   j                  r!|| j                   j
                  xx   dz  cc<   | j                   j                  |vrd|| j                   j                  <   n!|| j                   j                  xx   dz  cc<   || j                  _        | j                  j                  dk(  rD| j                   dk7  r5| j                  j                  j                  d      | j                  _         | j                  j                  dk7  r| j                   dvrvt        j                  j                  dd	| j                  gg d
dd| j                  gg      }|s5| j                  j                  j                  d      | j                  _         | j                  j                          y )Nr   OPENopenIN_PROGRESS)status_typeCLOSEDr.   in_progressr   r   )statusINr2   idz!=)r   )r4   r%   is_newr   testcase_run_cacher&   r(   cache_status_typeworkflowget_default_statusr   r   countr6   r)   )r   	run_cachecnts      r!   _cache_statuszCmfTestcaseRun._cache_status&   s|   &&$++dkk KK22	;;??t{{55dkkoo&!+&;;??)+)*Idkkoo&dkkoo&!+&)2&;;((F2t{{f7L!%!5!5!H!HUb!H!cDKK;;((H4Lc9c''--xt{{6S6_7;T4776K6M- NC %)[[%9%9%L%LYa%L%b"r"   c                 *    t         |          g dz   S )N)
ztestcase.estimate_timezparent.statusr4   zparent.testcase_run_cachezparent.workflowzparent.cache_status_typecur_history.responsibler   r   zparent.estimate_time)supersave_preload_fields)r   	__class__s    r!   rC   z"CmfTestcaseRun.save_preload_fields?   s     w*, 0` ` 	`r"   c                     | j                   j                  r#| j                   | j                  j                   k(  ry | j                   | j                  _         | j                  j                          y r$   )r   r%   r   r)   r*   s    r!   _calc_responsiblez CmfTestcaseRun._calc_responsibleC   sS    **d.>.>$BRBRB^B^.^'+'7'7$r"   c                    | j                   j                  | _        | j                          | j                          | j                  r| j                          | j                  r| j                          t        | $  |i |S r$   )
r   namer+   r?   r   rF   r7   r   rB   r)   )r   r   r    rD   s      r!   r)   zCmfTestcaseRun.saveI   sg    MM&&	  """$;; HHJw|T,V,,r"   c                    | j                  g d       | j                  sy| j                  j                  | _        | j                  j                  | _        | j                  j                  | _        | j                  j
                  | _        | j                  j                  | _        | j                  j                  | _        | j                          y)uC   Обновляем поля из текущего рана
        )	zcur_history.priorityzcur_history.statusrA   zcur_history.cmf_ownerzcur_history.test_configurationr   r   	cmf_ownertest_configurationN)	r   r   r   r   rK   rJ   r4   rH   r)   r*   s    r!   recalc_fieldszCmfTestcaseRun.recalc_fieldsY   s     	 = 	> ((11++77"&"2"2"E"E))33&&--$$))			r"   returnc                 4    |sg d}t         |   ||||      S )N)r6   coderH   r   zparent.nameztestcase.cmf_author.nameztestcase.cmf_author.loginztestcase.cmf_owner.nameztestcase.cmf_owner.loginztestcycle_testcase_folder.nameztest_configuration.namezenvironment.namer   zstatus.namezresponsible.namezresponsible.loginr   r   
spent_timezrelease.name)rB   export2file)clsfield_namesbqlformat_fileinclude_archivedrD   s        r!   rQ   zCmfTestcaseRun.export2filej   s&    &K w";[BRSSr"   c                     t         j                  j                  |       D ]  } |j                  |i |  t	        |   |i |S )N)r   )r   r   listdeleterB   )r   r   r    rhrD   s       r!   rY   zCmfTestcaseRun.deletez   sO    ..3343@ 	'BBIIt&v&	' w~t.v..r"   )NNcsvF)__name__
__module____qualname__r   r   api_methodsr   r+   r?   rC   rF   r)   rL   classmethodstrrQ   rY   __classcell__)rD   s   @r!   r   r      sl    ''33
<	= 

"2` - " Tcf T T/ /r"   r   N)cmf.include
cmf.fieldsmodules.evatest.fieldsr   -modules.evatest.models.cmf_evatest_code_mixinr   r    r"   r!   <module>rh      s)      3 Jw/%'7'F'F w/r"   